Converting geodataframe to spatially enabled dataframe messes the polygon geometry

a month ago
New Contributor II

I use a script to get data into our ArcGIS online organization, but it seems like the GeoAccessor function messes with the vertices and outputs wrong geometry. 

Source Data:


Polygon after adding to ArcGIS online using the script below:


Not sure how visible it is on the screenshots here, but it seems like the 2 inner holes of this big polygon get all mesed up when converting the geodataframe to a sedf.

This is my script:



import geopandas as gpd
from arcgis import GIS
import requests
from arcgis.features import GeoAccessor

gis=GIS("",username, password)

base_url = ''

payload = {
'f': 'geojson',
'where': "SITE_NAME='Eglin Air Force Base'",
'outSR': 4326,
'outFields': '*'
response = requests.get(base_url, params=payload)

gdf=gpd.GeoDataFrame.from_features(response.json()['features'], crs="epsg:4326")

sedf=GeoAccessor.from_geodataframe(gdf, column_name="geometry")

lyr = sedf.spatial.to_featurelayer('test_poly')



I have fiddled with this for hours. I tried the .buffer(0) method - didn't work. I tried the make_valid() function from shapely.validation too. Filling holes before converting to a spatially enabled dataframe worked, but it is not an acceptable solution. 
Any ideas? I have thought the vertices ordering might be to blame, since ESRI uses different clockwise/counterclockwise direction for exterior/interior rings, but I don't know how I would go about to change those.
Or maybe there is a way to bypass GeoAccessor altogether when trying to publish / append to a feature layer?

0 Kudos
4 Replies
MVP Esteemed Contributor

related? spatial.from_geodataframe() mangles geometries · Issue #931 · Esri/arcgis-python-api (

you might want to start an "Issue" there to narrow down the possibilities.

... sort of retired...
New Contributor II

Looking more at this, I am pretty sure it's a bug.. Thanks for sending that link! I don't even know if I should be glad or cry, these probably take a while to get solved. 
Do you know of any other way to publish a geodataframe as a feature layer?

0 Kudos
New Contributor II

Have you tried repairing the geometry first?  Admittedly I mix the API with ArcPy, but to dissolve groups of polygons I had to run (used OGC validation) first.
So I had sqlite - gdf - sedf - fc - repair geoms - dissolve.  Maybe not 100% related, but sometimes shifting formats/APIs can bypass the problem.

0 Kudos
New Contributor II

I tried to repair geometries using shapely functions, thing is, by the time I would be able to use arcpy repair - the geometries are already mangled. But yes, that is my thought too.. I need to get there using different formats/APIs, I am trying to add the data to a regular dataframe  instead of geodataframe at the moment, but that gives me some other errors. 

0 Kudos