I have a set of geometries that I want to check whether they touch another geometry. I have created a tuple "tiffs" where I want position 0 when touches is true. tif[0] and tif1 are strings. The following code processes with no errors but no output in the print statements at the end. Confirming in the image below, there is overlap with many features and both features are in the same projection. Why am I getting no output?
list_tif = []
with arcpy.da.SearchCursor(boundary, ['SHAPE@']) as search:
for r in search:
for tif in tiffs:
with arcpy.da.SearchCursor(tif[1], ['SHAPE@']) as cursor:
for row in cursor:
if row[0].touches(r[0]) == True:
list_tif.append(tif[0])
for p in list_tif:
print p
-
1I think what you are generating is a list of geometry objects and those probably don't have a default string property to report when being called to print. Is that the list you want or do you want a list of ids so you can report the tiffs that intersect with the border? You might first check the length of the list to make sure it's getting populated. If it is, add the object id field token to the list of fields and append that to the list. All this said, would the Intersect tool suffice?EvanT– EvanT2019年10月08日 21:38:28 +00:00Commented Oct 8, 2019 at 21:38
1 Answer 1
One potential issue:
Your two geometries must be in the same spatial reference, so check this.
More importantly:
You want to use geometry.overlaps
instead of geometry.touches
.
list_tif = []
sr = arcpy.Describe (boundary).spatialReference
with arcpy.da.SearchCursor(boundary, ['SHAPE@']) as search:
for r in search:
for tif in tiffs:
with arcpy.da.SearchCursor(tif[1], ['SHAPE@'], "", sr) as cursor:
for row in cursor:
if row[0].overlaps(r[0]) == True:
list_tif.append(tif[0])
for p in list_tif:
print p
I'd look into intersect, spatial join, or select by location for options that should take less time.
-
Changing to overlaps worked. This confuses me, the docs say: "return Boolean value of True indicates the boundaries of the geometries intersect" for touches. Do they not intersect if they overlap? What is touches for?D_C– D_C2019年10月08日 22:03:14 +00:00Commented Oct 8, 2019 at 22:03
-
1@D_C It looks like
touches
means boundaries touch and nothing else.Emil Brundage– Emil Brundage2019年10月08日 22:27:48 +00:00Commented Oct 8, 2019 at 22:27 -
Working with overlaps turned out only returned the feature classes that touched the boundary of the "boundary" file. I found disjoint == False to work.D_C– D_C2019年10月09日 15:48:40 +00:00Commented Oct 9, 2019 at 15:48
Explore related questions
See similar questions with these tags.