spatialpandas icon indicating copy to clipboard operation
spatialpandas copied to clipboard

Being able to instanciate empty GeoDataFrame

Open rderollepot opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

I have a workflow in which I process a geopandas GeoDataFrame in order to draw a map on a dashboard. At some point, I wish to make use of datashader reduction capabilities and thus, I convert my df into a spatialpandas GeoDataFrame. My dashboard allows to set filters which can lead my GeoDataFrame to be empty, and in that case, the conversion into a spatialpandas GeoDataFrame fails:

ValueError: A spatialpandas GeoDataFrame must contain at least one spatialpandas GeometryArray column

This led me to realize that spatialpandas does not allow the instanciation of an empty DataFrame, or at least not in the way pandas and geopandas allow it:

import pandas as pd
import geopandas as gpd
import spatialpandas as spd

pd.DataFrame() # works
gpd.GeoDataFrame() # works
spd.GeoDataFrame() # fails

Describe the solution you'd like

I would like to be able to generate empty spatialpandas GeoDataFrame.

Describe alternatives you've considered

An alternative I have is to first convert into a spatialpandas GeoDataFrame, and then filter this new DataFrame. When I do it in this order, query() is able to return an empty spatialpandas GeoDataFrame if there are indeed no matching results.

rderollepot avatar Jun 19 '23 12:06 rderollepot

This should be fairly easy to implement, the question is whether it will break anything because of the previously valid assumption that a GeoDataFrame always contains data. I'll take a look.

ianthomas23 avatar Jun 20 '23 13:06 ianthomas23