Create New Shapefile in Arcmap Using Python

I am trying to add a shape file in arc map without having the longitude and latitude but did not work . so how can i add new empty shape file in arcmap by using a simple python script ?

1

2 Answers

If you just want a new shapefile, you can use arcpy.CreateFeatureClass_management. For example, if you want a new point data shapefile, you'd use something like

arcpy.CreateFeatureclass_management(r'C:\output', "points.shp", "POINT")
1

Assuming if you are reading a text file with point coordinates. First step to creat feature class:arcpy.CreateFeatureclass_management(outputpath,fc,"Polygon").And create a insert cursor:cursor = arcpy.da.InsertCursor(fc,["shape@"]). Then obtain the points from text file and add them to an array to creat a polygon:

line_array = acrpy.Array()    
point = arcpy.Point()
for line in fileinput.input(infile):
    point.ID, point.X, point.Y = line.split()
    line_array.add(point)
polygon = arcpy.Polygon(line_array)
cursor.insertRow([polygon])
fileinput.close()
del cursor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest