Creating / updating feature layer in ArcGIS Online from geopandas GeoDataFrame?

02-13-2019 11:21 PM
New Contributor III


Is it at all possible to create a feature layer in ArcGIS Online from a GeoDataFrame? If you cannot create a feature layer directly from a GeoDataFrame, is it possible to populate an existing feature layer from a GeoDataFrame (provided the fields match of course). 

I tried all sorts of methods to create a feature layer directly using GeoJSON as the intermediary  - no luck. So then I tried to insert values (attributes and geometry) from a GeoDataFrame into an existing feature layer in AGOL, using GeoDataFrame.to_dict and then trying to add that dictionary to the feature layer using edit_features(adds=<my dictionary created from the GeoDataFrame>). No luck there either. 

Anyone knows how this can be done? 



0 Kudos
4 Replies
Occasional Contributor II
0 Kudos
New Contributor III

Here's a method I wrote for GeoDataFrame to return an arcgis spatially-enabled dataframe (SEDF):

import warnings
from arcgis.geometry import Geometry
from arcgis.features import GeoAccessor, GeoSeriesAccessor
from pandas import DataFrame
from geopandas import GeoDataFrame

def to_SpatialDataFrame(self, spatial_reference=None):
"""Returns an arcgis spatially-enabled data frame.

spatial_reference Either None or a spatial reference integer code.
If None, the spatial reference will be extracted
from the GeoDataFrame if it is defined using an
EPSG code.

if not spatial_reference:
crs =
epsg_code = crs.to_epsg()
if epsg_code:
spatial_reference = {'wkid': epsg_code}
spatial_reference = {'wkid': 4326}
warnings.warn('Unable to extract a spatial reference, assuming latitude/longitude (EPSG 4326).')
spatial_reference = {'wkid': spatial_reference}

sdf = DataFrame(data=self.drop(, axis=1))
sdf['SHAPE'] = [Geometry.from_shapely(g, spatial_reference) for g in self.geometry.tolist()]

return sdf

GeoDataFrame.to_SpatialDataFrame = to_SpatialDataFrame

The resulting SEDF can then be published or used to update an existing feature layer.

New Contributor III

That's very interesting, thanks!

0 Kudos
New Contributor II

There is a method using the arcgis api:

GeoAccessor.from_geodataframe(geo_df, inplace=False, column_name='SHAPE')
0 Kudos