Esri / Esri/arcgis-python-api

SEDF creation using from_df fails if geometry column contains Shapely geometries (instead of strings)

Open
#1,180 2 comments 1 reaction 1 assignee Claimed by @nanaeaubry View on GitHub
enhancement on-hold
Dominant language
Python
Stars
2.2k
Forks
1.2k
Avg merge
2h 40m
Merged PRs (30d)
2

Description

**Describe the bug**
A common workflow I use is to create spatially enabled dataframes (SEDFs) from Shapely geometries in a Pandas DataFrame. However, if the geometry column is left as Shapely geometries when trying to convert to an SEDF, then `from_df` will fail with an error similar to: `TypeError: argument of type 'Point' is not iterable`.

**To Reproduce**
Steps to reproduce the behavior:
```python
from shapely.geometry import Point, LineString
from arcgis.features import GeoAccessor

points = [Point(40, 40), Point(30,30)]
# points = [str(x) for x in points] ## works if this line is included

df = pd.DataFrame({
'id' : ['point1', 'point2'],
'points' : points
})

sedf = pd.DataFrame().spatial.from_df(df, geometry_column = 'points')
```
error:
```python
TypeError: argument of type 'Point' is not iterable
```
**Screenshots**
If applicable, add screenshots to help explain your problem.

**Expected behavior**
Ideally we can just check whether the DataFrame column contains Shapely geometries, and if so, then convert those Shapely geometries to strings before trying to make the SEDF from a geometry column.

**Platform (please complete the following information):**
- OS: Windows
- Browser Chrome
- Python API Version 1.9.1

**Additional context**
Add any other context about the problem here, attachments etc.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.