Creating a GeoDataFrame from a GeoJSON Object

I have a collection of polygon functions and I must first write it in a temporary file and then load it with geopandas.GeoDataFrame.from_file(tmp_json_file), is there a way to not write a temporary file and just create GeoDataFramefrom GeoJSONan object?

+4
source share
1 answer

You can use the function for this GeoDataFrame.from_features(). A small example (suppose you have a geojson FeatureCollection function):

In [1]: from geojson import Feature, Point, FeatureCollection

In [2]: my_feature = Feature(geometry=Point((1.6432, -19.123)), properties={"country": "Spain"})

In [3]: my_other_feature = Feature(geometry=Point((-80.234, -22.532)), properties={'country': 'Brazil'})

In [4]: collection = FeatureCollection([my_feature, my_other_feature])

In [6]: import geopandas

In [7]: geopandas.GeoDataFrame.from_features(collection['features'])
Out[7]:
  country                 geometry
0   Spain   POINT (1.6432 -19.123)
1  Brazil  POINT (-80.234 -22.532)
+9
source

All Articles