Using Geopandas with ArcGIS

682
1
Jump to solution
08-13-2024 10:42 AM
Labels (1)
Jades1
by
Occasional Contributor

Hi all,

I've worked in Python and Pandas and Geopandas and given that I know the functions within those, I find it easier to use them. I would have to make a clone of the Arc env with Conda in order to install the geopandas package (Pandas comes in the Arc environment), which I can do (waiting for admin privileges) but I'm wondering if others have gone down this path and found it workable. It's easy enough to get a feature layer into an SEDF, but I don't think geopandas can deal with a SEDF since it recognizes coordinates as Geometry (awhile back I was using AGOL and remember that being the case). What are your thoughts on this? Do I just need to learn the functions within Arc and deal with the fact that it doesn't seem nearly as intuitive, or can what I'm suggesting be a viable alternative?

I am dealing with health info, so I can't upload data to the internet and need to use Pro.

Thanks,


James

0 Kudos
1 Solution

Accepted Solutions
MattHowe
Frequent Contributor

Hi James, I've used arcpy, arcgis API for Python, and Geopandas together and works ok once you get the hang of it. As you say, clone the arc Python environment then pip install Geopandas works fine. Here's an example of rotating something with geopandas, shapely and the API for Python.

import arcpy
from arcgis.gis import GIS
import os
import pandas as pd
import geopandas as gpd
from shapely import affinity

sdf = pd.DataFrame.spatial.from_featureclass(rotate_features_sj)
gdf = gpd.GeoDataFrame(sdf, geometry='SHAPE', crs=f"EPSG:{self.epsg_code}")
for index, row in gdf.iterrows():
   rotate_pf = affinity.rotate(row['SHAPE'], row['Pivot_Rotation'], origin=(row['Pivot_Easting'], row['Pivot_Northing']))
gdf.loc[index, 'geometry'] = rotate_pf
gdf.loc[index, 'SHAPE'] = gdf.loc[index, 'geometry']
gdf = gdf.drop(columns=['geometry'])
gdf.to_file(os.path.dirname(self.final_features), layer=os.path.basename(self.final_features), driver="OpenFileGDB", crs=f"EPSG:{self.epsg_code}")

  

View solution in original post

1 Reply
MattHowe
Frequent Contributor

Hi James, I've used arcpy, arcgis API for Python, and Geopandas together and works ok once you get the hang of it. As you say, clone the arc Python environment then pip install Geopandas works fine. Here's an example of rotating something with geopandas, shapely and the API for Python.

import arcpy
from arcgis.gis import GIS
import os
import pandas as pd
import geopandas as gpd
from shapely import affinity

sdf = pd.DataFrame.spatial.from_featureclass(rotate_features_sj)
gdf = gpd.GeoDataFrame(sdf, geometry='SHAPE', crs=f"EPSG:{self.epsg_code}")
for index, row in gdf.iterrows():
   rotate_pf = affinity.rotate(row['SHAPE'], row['Pivot_Rotation'], origin=(row['Pivot_Easting'], row['Pivot_Northing']))
gdf.loc[index, 'geometry'] = rotate_pf
gdf.loc[index, 'SHAPE'] = gdf.loc[index, 'geometry']
gdf = gdf.drop(columns=['geometry'])
gdf.to_file(os.path.dirname(self.final_features), layer=os.path.basename(self.final_features), driver="OpenFileGDB", crs=f"EPSG:{self.epsg_code}")