Converting a spatial data frame to a geopandas data frame that contains curvedPath geometries

611
1
10-13-2023 08:15 AM
MattHowe
Occasional Contributor

I'm trying to convert a spatial dataframe to a geopandas dataframe but get errors when the geometry contains 'curvedPaths'. If the geometry says 'paths' it works fine.

sdf = pd.DataFrame.spatial.from_featureclass("tp_master_lyr")
gdf = gpd.GeoDataFrame(sdf, geometry='SHAPE', crs=f"EPSG:{self.epsg_code}")

 Create the sdf from a layer, then convert the gdf using the geometry field. When I read the sdf that works I see this:
0 1 B30 ... -43.801102 {"paths": [[[96887.0628000004, 4566105.1918],...
1 2 B30 ... -41.706207 {"paths": [[[963429.4271999998, 4566111.741800...

Testing another dataset, the one that doesn't work and gives KeyError: 'paths':

0 1 ... {"curvePaths": [[[777739.0449999999, 4321271.9...
1 2 ... {"curvePaths": [[[123521.7758999998, 4329860.0...

If the sdf has 'curvePaths' as the geometry type I get errors when trying to convert to a geodataframe. Any ideas how to get round this?

0 Kudos
1 Reply
EarlMedina
Esri Regular Contributor

Perhaps the conversion is missing a piece to perform the required steps for curves. I do believe, however, shapely supports curves and geopandas uses shapely geometry. 

If shape accuracy is not a concern, I would guess a quick way to get around this would be to generalize your shape data first before loading into a GeoDataFrame like so:

 

sdf["SHAPE"] = sdf.SHAPE.apply(lambda x: x.generalize(max_offset=10))

 

 

Where the max_offset is a value of your choosing.

0 Kudos