1

I'm trying to use polygons in arcpy. The polygons are stored in a shapefile. When running the following:

import arcpy 
gdb = 'path//to//gbd' 
inshape = os.path.join(folder,'Ameland_1968.shp') 
poly = os.path.join(gdb,'test')

arcpy.MakeFeatureLayer_management (inshape, poly)

I get this error:

ExecuteError: ERROR 000229: Cannot open inshape **(red: this path is typed out)
Failed to execute (MakeFeatureLayer).

What is the problem? Arcpy should be able to run this line with shapefiles right? I'm actually trying to run a part of a script that's using arcpy but the data is in shapefiles. How to convert these?

edit: this is my original code

poly_shape = 'D:\\ARNO\\Analysis\\ArcGIS\\ArcPyScripts\\Data\\straight_bars_2\\Ameland\\Ameland_1965.shp'
poly = 'D:\\ARNO\\Analysis\\ArcGIS\\ArcPyScripts\\Data\\test.gdb\\Ameland65'
arcpy.MakeFeatureLayer_management (poly_shape, poly)
  • What happens if you replace MakeFeatureLayer with if arcpy.Exists(inshape): print("OK") (with line break before print)? You haven't defined folder in your snippet above, which may or may not be the problem... a complete example is going to be important to help with debugging. – Erica Oct 16 '17 at 12:13
  • 1
    Show how you declare 'folder'. Also you cant place a feature layer in a geodatabase, it is created in memory. If you want to make it permanent use Copy Features afterwards. Syntax for Make Feature Layer: pro.arcgis.com/en/pro-app/tool-reference/data-management/… – BERA Oct 16 '17 at 12:14
  • It prints 'OK', the file exists. I thought I'd make it easier for the ones trying to replicate it. I'll paste exactly what I have. – ArnJac Oct 16 '17 at 12:16
  • 1
    You are confusing feature classes with feature layers. What is your next step after you have created a feature layer? – BERA Oct 16 '17 at 12:28
  • 1
    See: gis.stackexchange.com/questions/26336/… – BERA Oct 18 '17 at 6:25
4

With arcpy.MakeFeatureLayer_management() you just need to specify a name for your feature layer, not a path. The feature layer still points back to your original shapefile as the source, it does not copy it to a new geodatabase feature class.

So instead of giving a path in the second parameter, just give it a string value like "mypoly"

poly_shape = 'D:\\ARNO\\Analysis\\ArcGIS\\ArcPyScripts\\Data\\straight_bars_2\\Ameland\\Ameland_1965.shp'
arcpy.MakeFeatureLayer_management (poly_shape, "mypoly")

You can then reference "mypoly" elsewhere as an input for other tools such as the Simplify you mention above.

2

You do not have to make a feature layer from a gdb feature class. You may point the Make Feature Layer method directly to the shapefile:

inshape = os.path.join('C:/myFolder/','Ameland_1968.shp') 
arcpy.MakeFeatureLayer_management(inshape, 'myFeatureLayerName')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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