My objective is to convert a google earth engine featureCollection into a geopandas geodataframe.
Earth engine can handle geoJSON whereas geopandas prefers shapely.
The geometry (geoJSON) of the first feature in my featureCollection is:
as you can see, there is a geodesic (boolean) parameter in the geoJSON.
I use shapely.geometry.shape() to convert the geoJSON to a shapely geometry that geopandas can handle. However I am not sure if the geodesic parameter is captured correctly. The shapely documentation doesn't mention this. [EDIT: the main page does] How can I make sure the geodesic parameter is handled correctly?
Here is my full function:
def fcToGdf(fc):
"""converts a featurecollection to a (geo)Pandas GeoDataFrame or a pandas DataFrame. WARNING: Geometries are non-geodesic. Geodesic not yet supported. work in progress
Args:
fc (ee.FeatureCollection) : the earth engine feature collection to convert. Size is limited to memory (geopandas limitation)
crs (dictionary, optional) : the coordinate reference system in geopandas format. Defaults to {'init' :'epsg:4326'}
Returns:
gdf (geoPandas.GeoDataFrame or pandas.DataFrame) : the corresponding (geo)dataframe.
"""
crs = {'init' :'epsg:4326'}
features = fc.getInfo()['features']
dictarr = []
for f in features:
attr = f['properties']
attr['geometry'] = f['geometry']
dictarr.append(attr)
gdf = gpd.GeoDataFrame(dictarr)
gdf['geometry2'] = map(lambda s: shapely.geometry.shape(s), gdf.geometry)
gdf.crs = crs
return gdf