Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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

I am trying to automate various tasks in ArcGIS Desktop (using ArcMap generally) with Python, and I keep needing a way to add a shapefile to the current map. (And then do stuff to it, but that's another story).

The best I can do so far is to add a layer file to the current map, using the following ("addLayer" is a layer file object):

def AddLayerFromLayerFile(addLayer): 
  import arcpy 
  mxd = arcpy.mapping.MapDocument("CURRENT") 
  df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] 
  arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE") 
  del mxd, df, addLayer 

However, my raw data is always going be shapefiles, so I need to be able to open them. (Equivantly: convert a shapefile to a layer file without opening it, but I'd prefer not to do that).

share|improve this question

migrated from May 5 '11 at 18:48

This question came from our site for computer enthusiasts and power users.

Assuming there is no addshapefile function, one solution would be:

Make Feature Layer (Data Management) - Syntax:
MakeFeatureLayer_management (in_features, out_layer, {where_clause}, {workspace}, {field_info})

Then add the layer...

share|improve this answer

I don't have ArcPy to hand but can you not use the MakeFeatureLayer tool and then add the result to your map?

arcpy.mapping.AddLayer(df, "myData", "AUTO_ARRANGE")  
share|improve this answer

This library reads and writes ESRI Shapefiles in pure Python. You can read and write shp, shx, and dbf files with all types of geometry. Everything in the public ESRI shapefile specification is implemented.

share|improve this answer
I'm curious as to what's wrong with this solution? Thought it was an exact match for the question asked. – Jacques Tardie May 9 '11 at 14:15
This can be used to read/write shapefiles but the question is how to create a layer in ArcMap from a shapefile. – PolyGeo Dec 20 '14 at 7:51

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.