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

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?
    – Evan Thoms
    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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.