GeoAccessor.from_geodataframe() mangles geometries
See original GitHub issueDescribe the bug Using GeoAccessor.from_geodataframe() results in mangled geometries. It seems to happen on more complex polygons with many holes.
To Reproduce Steps to reproduce the behavior:
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')
Screenshots Source data: After converting to a Spatially Enabled dataframe: A closeup: Result:
Expected behavior I expect the geometries to stay the same.
Platform:
- OS: Windows 10
- Browser: Chrome
- Python API Version: 1.8.5
Additional context I tried the .buffer(0) method before converting to SEDF - didn’t work. I tried the make_valid() function from shapely.validation too, same result. Filling holes before converting to a spatially enabled dataframe worked, but it is not an acceptable solution.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Solved: Converting geodataframe to spatially enabled dataf...
Solved: I use a script to get data into our ArcGIS online organization, but it seems like the GeoAccessor function messes with the...
Read more >Introduction to the Spatially Enabled DataFrame
This document outlines some fundamentals of using the Spatially Enabled DataFrame object for working with GIS data. import pandas as pd from arcgis.features ......
Read more >shapely - Converting dataframe with WKT column to spatial ...
The GeoAccessor.from_df() function has a geometry_column parameter but this only seems to be expecting the geometry in the ESRI format ...
Read more >Getting to Know Pandas and the Spatial Enabled DataFrame
This presentation will cover modern Pandas best practices by using examples as well as how to use the new Spatially Enabled DataFrame ......
Read more >Automatically Convert to Esri Spatially Enabled Dataframe
from arcgis.features import GeoAccessor, FeatureLayer. from arcgis.geometry import Geometry. from arcgis.gis import GIS. import pandas as pd.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just for context, I have pretty much the same exact code as @manuela-butuc. Here is a screenshot of trying to upload the Census Subdivisions through a geodataframe and the sedf=GeoAccessor.from_geodataframe(gdf, column_name=“geometry”) command.
It does look kinda cool I must say.
@manuela-butuc thank you for the code and sample, we’ll take a look at this and get back to you.