Select to view content in your preferred language

Issue saving a geo Pandas DataFrame to Feature Class

603
4
Jump to solution
03-04-2024 10:53 AM
RobertKleisley
Emerging Contributor

I am currently pulling data from an api that is in a json format. 
I convert this into a geodataframe using the lat lon columns provided in the dataset.

df_points = gpd.GeoDataFrame.from_dict(all_results)

df_points['lon'] = df_points['lon'].astype(float)
df_points['lat'] = df_points['lat'].astype(float)

df_points['geometry'] = [shapely.geometry.Point(xy) for xy in zip(df_points.lon, df_points.lat)]

gdf = df_points
sedf = arcgis.GeoAccessor.from_geodataframe(gdf)

This part works fine even if it may not be elegant. 
From here I can save it off as a shapefile no problem
I would like to send it directly to my GeoDatabase as a Feature Class

however when I attempt to I get an error.

sedf.spatial.to_featureclass(r'...\MyProject.gbd\sample')

--------------------------
AttributeError      Traceback(most recent call last)
In[23]:
Line 1: sedf.spatial.to_featureclass(r'...\MyProject.gbd\sample')

File ...\site-packages\arcgis\feature\geo\_accesspr.py, in to_featureclass:
Line 2668: result = to_featureclass(

File ...\site-packages\arcgis\features\geo\_io\fileops.py, in to_featureclass"
Line 1262: raise e

File ...\site-packages\arcgis\features\geo\_io\fileops.py, in to_featureclass:
Line 1075: "point": pd.io.json.dumps(

AttributeError: module 'pandas.io.json' has no attribute 'dumps'
-----------------------

Any thoughts why I am seeing this. 

I do thought it might be conflicting with the json library but I removed it and it is still popping this error.

0 Kudos
1 Solution

Accepted Solutions
RobertKleisley
Emerging Contributor

Unfortunately cannot remove posts so replying again with the solution

As of Panda's 2.2.x
pandas calls json.dumps as json.udumps

In order to get .to_featureclass, arcgis is now reliant on pandas version 2.1.x or older

!pip install pandas == 2.1

df_points = gpd.GeoDataFrame.from_dict(all_results)

df_points['lon'] = df_points['lon'].astype(float)
df_points['lat'] = df_points['lat'].astype(float)

df_points['geometry'] = [shapely.geometry.Point(xy) for xy in zip(df_points.lon, df_points.lat)]

gdf = df_points
sedf = arcgis.GeoAccessor.from_geodataframe(gdf)

sedf.spatial.to_featureclass(r'...\MyProject.gbd\sample')

View solution in original post

0 Kudos
4 Replies
CodyPatterson
Frequent Contributor

Hey @RobertKleisley 

Do you happen to have anything named json.py or json.x (x being any extension)? I've had this exact issue before due to it picking up something named json.

I'd attempt to move this to a different location and give it another shot to see!

Hope that helps!

Cody

0 Kudos
RobertKleisley
Emerging Contributor

I'm unsure what you mean. 
something named json saved anywhere in the GDB?

anything named json in my Python3 directory where my packages are installed?

0 Kudos
RobertKleisley
Emerging Contributor

Digging into this  a bit.

I have figured out that I am using pandas 2.2.x
as of this version pandas imports json.udumps not json.dumps

0 Kudos
RobertKleisley
Emerging Contributor

Unfortunately cannot remove posts so replying again with the solution

As of Panda's 2.2.x
pandas calls json.dumps as json.udumps

In order to get .to_featureclass, arcgis is now reliant on pandas version 2.1.x or older

!pip install pandas == 2.1

df_points = gpd.GeoDataFrame.from_dict(all_results)

df_points['lon'] = df_points['lon'].astype(float)
df_points['lat'] = df_points['lat'].astype(float)

df_points['geometry'] = [shapely.geometry.Point(xy) for xy in zip(df_points.lon, df_points.lat)]

gdf = df_points
sedf = arcgis.GeoAccessor.from_geodataframe(gdf)

sedf.spatial.to_featureclass(r'...\MyProject.gbd\sample')
0 Kudos