Simple test to check if returned value is a geometry object

130
1
Jump to solution
05-28-2022 09:38 PM
Labels (3)
Glasnoct
New Contributor III

I gave it a whirl but I can't seem to figure out the particular expression to test if the given variable is a geometry object (as if you had run a searchcursor for "Shape@"). I'm mostly just concerned with detecting that's it's a geometry object and not of what type (line, polyline, etc). I've tried things to the effect of:

if type(value) == 'arcpy.arcobjects.geometries.Polyline' (or 'Polyline' or 'arcpy.arcobjects.arcobjects.Geometry')

What's the magic word I'm looking for, for the right side of that expression?

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

The value you compare it to should be a type, not a string.

 

if type(value) in (arcpy.Polygon, arcpy.Point, arcpy.Polyline, arcpy.Multipoint):
    arcpy.DoSomething(...)

It'd be nice if type(value) is arcpy.Geometry returned True, but sadly it doesn't.

 

View solution in original post

1 Reply
Luke_Pinner
MVP Regular Contributor

The value you compare it to should be a type, not a string.

 

if type(value) in (arcpy.Polygon, arcpy.Point, arcpy.Polyline, arcpy.Multipoint):
    arcpy.DoSomething(...)

It'd be nice if type(value) is arcpy.Geometry returned True, but sadly it doesn't.