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("https://arcgis.com",username, password)
base_url = 'https://services1.arcgis.com/Hp6G80Pky0om7QvQ/arcgis/rest/services/DoD_Sites_Boundaries_Public/FeatureServer/0/query'
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?