Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I create a shapefile using Python in ArcGIS 10?

I have lat & long.

From this I need Python code which will create a shapefile in ArcGIS Desktop 10.

share|improve this question
Are you trying to create a point shapefiles, or do you need to turn your lat/long points into lines or polygons? – RyanDalton Oct 24 '11 at 14:41
Hi I have lat and long and need an array to add all the lat and long in the same shape file – Mehul Oct 24 '11 at 17:12
up vote 14 down vote accepted

For creating points:

ptList =[[20.000,43.000],[25.500, 45.085],[26.574, 46.025]]
pt = arcpy.Point()
ptGeoms = []
for p in ptList:
    pt.x = p[0]
    pt.Y = p[1]

arcpy.CopyFeatures_management(ptGeoms, r"C:\Temp\test.shp")

It will return a message like this:

<Result 'C:\\Temp\\test.shp'>
share|improve this answer
Also how can i add the same shape file through python in ArcGIS 10 – Mehul Oct 24 '11 at 17:15
u will run python interpreter from Geoprocessing > Python then first of all write import arcpy and finally add code line by line... i hope you have asked this... :) – Aragon Oct 25 '11 at 9:14
I believe it should be pt.X (uppercase X)! That took me half an hour to find! – user1650538 Sep 23 '14 at 4:51

Another option would be to just use the existing arcpy geoprocessing tools, see code below.

   # Import arcpy module
import arcpy

# Local variables:
table_dbf = "C:\\temp\\table.dbf"
table_Layer2 = "table_Layer2"
point3_shp = "C:\\temp\\point3.shp"

# Process: Make XY Event Layer
arcpy.MakeXYEventLayer_management(table_dbf, "x_coord", "y_coord", table_Layer2, "", "")

# Process: Copy Features
arcpy.CopyFeatures_management(table_Layer2, point3_shp, "", "0", "0", "0")

mxd = arcpy.mapping.MapDocument(r"C:\temp\Untitled.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
addLayer = arcpy.mapping.Layer(point3_shp)
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
share|improve this answer
Also how can i add the same shape file through python in ArcGIS 10 – Mehul Oct 24 '11 at 17:15
@Mehul, See my updated code. – artwork21 Oct 24 '11 at 19:01
Can you please explain me from where will i get .dbf file and also some how i am unable to implement this code. – Mehul Oct 25 '11 at 9:08
what is the meaning of x_coord and y_coord in arcpy.MakeXYEventLayer_management(table_dbf, "x_coord", "y_coord", table_Layer2, "", "") and what is it mean? – Mehul Oct 27 '11 at 7:24
@Mehul, DBF is just the tabular file that makes up a shapefile (e.g. .shp, .shx, & .dbf). The x_coord and y_coord are just the two fields in the .dbf file that contain the long/lat coordinates. These fields are most likely different for you database. – artwork21 Nov 17 '11 at 19:28

You can create a shapefile in Python using the Create Feature Class tool. There is an example at the bottom of the page.

To populate the shapefile with your lat & long data, you'll need to use an Insert Cursor.

Perhaps you can load your lat & long data as a list into Python, then iterate through the array populating the rows of your new shapefile with the insert cursor.

EDIT, response to comment

A python list of coordinates can be constructed like this:

latLonList = [[40.000,-75.000],[39.998,-75.432],[39.981,-75.343]]

Then to iterate through coordinates in the list (and print them, for example), do this:

for coord in latLonList:
    print "lat: " + str(coord[0])
    print "lon: " + str(coord[1])

If I'm interpreting your second question correctly, to add a layer to an mxd file, see this post on GIS.SE.

share|improve this answer
Hi Can you please give me a sample code which has list and array in it ? – Mehul Oct 24 '11 at 17:13
Also how can i add the same shape file through python in ArcGIS 10 – Mehul Oct 24 '11 at 17:14
I did look at the post but i am not able to implement it. Can you suggest me any other method or may be a sample code with explanation – Mehul Oct 25 '11 at 9:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.