2

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)
ArnJac
  • 375
  • 1
  • 3
  • 18
  • 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: http://pro.arcgis.com/en/pro-app/tool-reference/data-management/make-feature-layer.htm – 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
  • I'm putting it into the simplify function. But it makes sense that I mix up those. I'll look into this! Is there a one sentence difference or is this off topic? – ArnJac Oct 16 '17 at 12:34
  • Some geoprocessing tool want feature layer as inputs (like Select By Location) and some want feature classes (like a shapefile, or a feature class in a file geodatabase). So it depends on what you are going to do next in your code. See: http://support.esri.com/en/other-resources/gis-dictionary/browse – BERA Oct 16 '17 at 13:01
  • perfect, thank you very much! If you post the answer I will mark it as correct – ArnJac Oct 16 '17 at 15:59
  • 1
    See: https://gis.stackexchange.com/questions/26336/difference-between-map-layer-and-spatial-dataset-e-g-feature-class-shapefile – BERA Oct 18 '17 at 06:25

2 Answers2

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.

Midavalo
  • 29,696
  • 10
  • 48
  • 104
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')
artwork21
  • 35,114
  • 8
  • 66
  • 134