Issue with creating multipoints and running the symmetrical difference analysis?

468
2
Jump to solution
05-17-2023 08:42 AM
RPGIS
by
Occasional Contributor III

Hi,

I have a script that is designed to quickly analyze thousands of points to determine if there are any intersecting points. If there are any intersecting points, run the geometry analysis to get all of the intersecting points. Use the symmetrical difference analysis to get all points that do not intersect.

 

InFeatureMPoint, RefFeatureMPoint = arcpy.Multipoint(arcpy.Array([arcpy.Point(*x) for x in ListACoords])), arcpy.Multipoint(arcpy.Array([arcpy.Point(*x) for x in ListBCoords]))

UnMatched = InFeatureMPoint^RefFeatureMPoint

 

When I run the symmetrical difference analysis; I keep getting and error stating:

 

return convertArcObjectToPythonObject(self._arc_object.symmetricdifference(other._arc_object))
ValueError: <geoprocessing describe geometry object object at 0x000002D08952E1E0>

 

I don't know what the issue could be. I assume it might have something to do with the number of records but it is hard to say. Any help on this would be greatly appreciated.

 

0 Kudos
1 Solution

Accepted Solutions
RPGIS
by
Occasional Contributor III

I still could not get it to work despite my efforts. Oddly enough I did find an abstract workaround that behaves similarly. What I had to do was intersect the two multipoint features then subtract the intersected feature from both multipoint features to get something similar. This definitely seems like a bug that I'll have to let someone at Esri know about. But so far that seems to work for some reason. 

Also, it works with both operators and functions in that regards.

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

I assume it might have something to do with the number of records

I got the same error for Multipoints with only 1 point, so I don't think that's it.

My first idea was that it had something to do with the SpatialReference, because you don't set that when creating the Multipoints, but that didn't work either.

My tests suggest that something is buggy with constructed Multipoints.

def layer_to_multipoint(layer, wkid=None):
    """Reads the geometries of a point layer and returns a Multipoint geometry.
    If wkid is set, the Multipoint will be projected into that system.
    """
    in_sr = arcpy.Describe(layer).spatialReference
    coordinates = [row[0] for row in arcpy.da.SearchCursor(layer, ["SHAPE@XY"])]
    points = [arcpy.Point(*c) for c in coordinates]
    multipoint = arcpy.Multipoint(arcpy.Array(points), spatial_reference=in_sr)
    if wkid:
        out_sr = arcpy.SpatialReference(wkid)
        multipoint = multipoint.projectAs(out_sr)
    return multipoint


# construct a MP geometry from a point layer
constructed_mp = layer_to_multipoint("TestPoints")

# try to run some geometry functions on it
constructed_mp.symmetricDifference(constructed_mp)  # ERROR
constructed_mp.union(constructed_mp)                # ERROR
constructed_mp.difference(constructed_mp)           # works
constructed_mp.intersect(constructed_mp, 1)         # works



# write the constructed mp into a fc and read it again from there
with arcpy.da.InsertCursor("TestMultipoints", ["SHAPE@"]) as cursor:
    cursor.insertRow([constructed_mp])
read_mp = [r for r in arcpy.da.SearchCursor("TestMultipoints", ["SHAPE@"])][0][0]

# try to run the geometry functions on the read mp
read_mp.symmetricDifference(read_mp)   # works
read_mp .union(read_mp)                # works
read_mp .difference(read_mp)           # works
read_mp .intersect(read_mp , 1)        # works


# let's compare the mp's
print(constructed_mp.JSON)
#{"points":[[81359.018400000408,5906093.2276000008],[81356.343299999833,5906139.3099000007],[81519.05449999962,5905955.2974999994]],"spatialReference":{"wkid":25833,"latestWkid":25833}}
print(read_mp.JSON)
#{"points":[[81359.018400000408,5906093.2276000008],[81356.343299999833,5906139.3099000007],[81519.05449999962,5905955.2974999994]],"spatialReference":{"wkid":25833,"latestWkid":25833}}

 

It seems like these are the same Multipoints, but somehow union and symmetricDifference fail for the mp I constructed myself. It also didn't matter whether I used the functions, the operators, or the Geometry._arc_object functions.

 

 

I think I remember you posting a huge script containing this snippet. Did it work back then? I think this is a matter for tech support.

In the meantime, there's Symmetrical Difference...


Have a great day!
Johannes
0 Kudos
RPGIS
by
Occasional Contributor III

I still could not get it to work despite my efforts. Oddly enough I did find an abstract workaround that behaves similarly. What I had to do was intersect the two multipoint features then subtract the intersected feature from both multipoint features to get something similar. This definitely seems like a bug that I'll have to let someone at Esri know about. But so far that seems to work for some reason. 

Also, it works with both operators and functions in that regards.

0 Kudos