0

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

enter image description here

asked Oct 8, 2019 at 21:18
1
  • 1
    I 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? Commented Oct 8, 2019 at 21:38

1 Answer 1

3

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.

answered Oct 8, 2019 at 21:40
3
  • 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? Commented Oct 8, 2019 at 22:03
  • 1
    @D_C It looks like touches means boundaries touch and nothing else. Commented 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. Commented Oct 9, 2019 at 15:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.