Loading JSON into a GeoDataFrame

后端 未结 4 1800
旧时难觅i
旧时难觅i 2021-02-07 17:48

I\'m having difficulty loading the following JSON containing GIS data (https://data.cityofnewyork.us/resource/5rqd-h5ci.json) into a GeoDataFrame.

The following code fai

4条回答
  •  长发绾君心
    2021-02-07 18:31

    A more idiomatic way that uses regular dataframe functions inherited from pandas, and the native GeoDataFrame.from_features:

    gdf = gpd.GeoDataFrame(data.json())
    
    # features column does not need to be stored, this is just for illustration
    gdf['features'] = gdf['the_geom'].apply(lambda x: {'geometry': x, 'properties': {}})
    gdf2 = gpd.GeoDataFrame.from_features(gdf['features'])
    
    gdf = gdf.set_geometry(gdf2.geometry)
    gdf.head()
    

提交回复
热议问题