How to check geometry prior to running a geoprocess using a loop?

303
3
Jump to solution
05-22-2019 12:14 PM
ConnorMcivor
New Contributor III

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.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

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"

View solution in original post

3 Replies
DanPatterson_Retired
MVP Esteemed Contributor

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"

ConnorMcivor
New Contributor III

I have now tried this approach however im getting the following errors:

  • AttributeError: 'module' object has no attribute 'Describe'

        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")

  • TypeError: 'geoprocessing describe data object' object has no attribute '__getitem__'

         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. 

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor
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 

0 Kudos