Select to view content in your preferred language

Having trouble creating a union polygon using arcgis.geometry.union

182
2
05-22-2024 06:10 AM
Labels (1)
erios
by
New Contributor

I am creating a series of geoprocessing tools for an AGE project and one of these tools includes a union function that is called when certain conditions are met. I am using the arcgis.geometry.module from the ArcGIS API for Python library. I am using a list comprehension of geometries that I created from a feature set that contains the polygons I would like to create a union from. I use this list comprehension as the geometries parameter in the union function to create a new polygon but what is returned is a single set of geometry, which appears to be the centroid of one of the polygons. Below is a summation of what my script looks like inside my union function.

getGeom = [polygon.geometry for polygon in checkStat]
 
This is what the list above looks like when it is returned.
[{'rings': [[[-79608.7971409224, 853510.7087014914], [-6525.311090338975, 856120.8334024921], [-2610.1243669204414, 780427.2229789868], [-78303.73479042202, 780427.2229789868], [-79608.7971409224, 853510.7087014914]]], 'spatialReference': {'wkid': 2881, 'latestWkid': 2881}}, {'rings': [[[-44372.1163020879, 880917.0160934925], [32626.556143827736, 886137.2648393214], [41761.991941161454, 837849.9618078247], [-44372.1163020879, 837849.9618078247], [-44372.1163020879, 880917.0160934925]]], 'spatialReference': {'wkid': 2881, 'latestWkid': 2881}}]
 
bndPoly = getGeom
bndUnion =union(bndPoly, spatial_ref=2881, gis=gis)
 
This is what is returned from the union.
[-83.0702025625555, 26.60882017966672]
 
I have also tried this, but get the same result.
    polyList=[]
    for poly in getGeom:
        polygon = (Polygon(poly))
        sr = polygon.spatialReference
        geom1_reprojected = project(geometries = [polygon], in_sr = sr, out_sr = 2881)[0]
        polyList.append(geom1_reprojected)
 

Any help or insight into what I am doing wrong is greatly appreciated, thank you!

 

0 Kudos
2 Replies
EarlMedina
Esri Regular Contributor

I tested your example and it works fine for me:

EarlMedina_0-1716408475547.png

 

I'm on version 2.3.0.1 of the API. My guess is maybe your version isn't correctly parsing that JSON into geometry objects?

 

 

Any difference if you explicitly parse into Polygon objects beforehand?

from arcgis.geometry import Polygon
parsed = [
    Polygon({'rings': [[
        [-79608.7971409224, 853510.7087014914], 
        [-6525.311090338975, 856120.8334024921], 
        [-2610.1243669204414, 780427.2229789868], 
        [-78303.73479042202, 780427.2229789868], 
        [-79608.7971409224, 853510.7087014914]]], 
        'spatialReference': {'wkid': 2881, 'latestWkid': 2881}}), 
    Polygon({'rings': [[
        [-44372.1163020879, 880917.0160934925], 
        [32626.556143827736, 886137.2648393214], 
        [41761.991941161454, 837849.9618078247], 
        [-44372.1163020879, 837849.9618078247], 
        [-44372.1163020879, 880917.0160934925]]], 
        'spatialReference': {'wkid': 2881, 'latestWkid': 2881}})]
0 Kudos
erios
by
New Contributor

Sorry for the late reply, but yes I have tried parsing into polygon objects as well. I have found a work around using dissolve but it is kind of clunky and would rather use union if possible. I am running 2.1.0.2

0 Kudos