Working on a portion of a script that needs to check each feature class in the geodatabase for geometry type. If the geometry is a point, it SHOULD NOT move into the loop of geoprocesses. If it is not a point i WANT it to iterate through the loop. The loop generates a feature class of points from polygons and polylines that intersect a user defined "Input_Centerline" (polyline).
Input_Centerline = arcpy.GetParameterAsText(0)
Folder = "C:\\......."
WS = arcpy.CreateFolder_management(Folder, Date)
TEMP = arcpy.CreateFileGDB_management(WS, "TEMP", "CURRENT")
arcpy.env.workspace = str(TEMP)
fcList2 = arcpy.ListFeatureClasses()
for fc in fcList2:
fc_desc = arcpy.Describe(fc)
fc_gm = fc_desc.shapeType
if fc_gm is not "Point":
fc_xing = arcpy.Intersect_analysis([Input_Centerline, fc], str(TEMP) + "\\" + str(fc) + "_XING", "", "", "POINT")
Bolded is the line where i believe my issue is. So it runs through the loop just fine but it does EVERY feature class and ignores the if statement. I have tried using '<>' in place of 'is not' and yields the same results.
Solved! Go to Solution.
Connor, use the new data access cursors
Describing data—ArcPy Get Started | ArcGIS Desktop
For example
desc = arcpy.da.Describe(inFC)
if desc['shapeType'] == "Point"
Connor, use the new data access cursors
Describing data—ArcPy Get Started | ArcGIS Desktop
For example
desc = arcpy.da.Describe(inFC)
if desc['shapeType'] == "Point"
I have now tried this approach however im getting the following errors:
When i use :
fcList2 = arcpy.ListFeatureClasses()
for fc in fcList2:
fc_desc = arcpy.da.Describe(fc) <<< ERROR HERE
if fc_desc['shapeType'] <> "Point":
fc_xing = arcpy.Intersect_analysis([Input_Centerline, fc], str(TEMP) + "\\" + str(fc) + "_XING", "", "", "POINT")
When i use:
fcList2 = arcpy.ListFeatureClasses()
for fc in fcList2:
fc_desc = arcpy.Describe(fc)
if fc_desc['shapeType'] <> "Point": <<< ERROR Here
fc_xing = arcpy.Intersect_analysis([Input_Centerline, fc], str(TEMP) + "\\" + str(fc) + "_XING", "", "", "POINT")
The first error was using ".da" prior to the "Describe" module
The second error i have no idea whats going on. Im still trying variations of this approach.
a = "Point"
a == "Point" # ---- is equal
True
a <> "Point" # ---- not, not equalo
File "<ipython-input-3-d6a10bb86c6a>", line 1
a <> "Point"
^
SyntaxError: invalid syntax
a != "Point" # --- not equal
False
If you are using recent versions of ArcMap and/or Pro the new cursors are available