Home > Software design >  dask_geopandas: GeoDataFrame with only geometry column
dask_geopandas: GeoDataFrame with only geometry column

Time:08-09

Using geopandas one can do:

from shapely.geometry import Point
import geopandas as gpd

points = [Point(0,0)]
gser = gpd.GeoSeries(points)
gdf = gpd.GeoDataFrame(geometry=gser.values)

If I had a dask_geopandas.GeoSeries what would be the equivalent lines in dask_geopandas? It seems that one can not use directly the dask_geopandas.GeoDataFrame constructor and has to rely on the staticmethods but can't see any suitable one.

EDIT:

To clarify: I have a dask_geopandas.GeoSeries (no geopandas.GeoSeries anywhere), how could I create a dask_geopandas.GeoDataFrame that only contains one column, a geometry column, whose values come from the dask_geopandas.GeoSeries?

Snippet that doesn't work:

dgser # is a dask_geopandas.GeoSeries
dgdf = dask_geopandas.GeoDataFrame(geometry=dgser.values)

CodePudding user response:

One option is to use from_geopandas:

from dask_geopandas import from_geopandas
from shapely.geometry import Point
from geopandas import GeoSeries, GeoDataFrame

points = [Point(0,0)]
gser = GeoSeries(points)
gdf = GeoDataFrame(geometry=gser.values)
dgdf = from_geopandas(gdf, npartitions=1)

CodePudding user response:

I figured it out (although I wish there was a built-in method for this):

dgser # is a dask_geopandas.GeoSeries
ddf = dgser.to_dask_dataframe()
ddf.columns = ["geometry"]
dgfg = dask_geopandas.from_dask_dataframe(ddf)
  • Related