question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GeoAccessor.from_geodataframe() mangles geometries

See original GitHub issue

Describe 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: image After converting to a Spatially Enabled dataframe: image A closeup: image Result: image

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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
davidgrubmanchoicehotelscommented, Nov 9, 2021

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.

image

It does look kinda cool I must say.

2reactions
achapkowskicommented, Sep 21, 2021

@manuela-butuc thank you for the code and sample, we’ll take a look at this and get back to you.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found