8

Suppose I have a string that contains raw unparsed GeoJSON data. For example:

geojson_str = '''{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "id": 1, "test": "a" }, "geometry": { "type": "Point", "coordinates": [ 3.0, 7.0 ] } },
{ "type": "Feature", "properties": { "id": 2, "test": "b" }, "geometry": { "type": "Point", "coordinates": [ 5.0, 5.0 ] } },
{ "type": "Feature", "properties": { "id": 3, "test": "c" }, "geometry": { "type": "Point", "coordinates": [ 7.0, 3.0 ] } }
]
}
'''

How can I read the data above into a GeoDataFrame?

1
  • 1
    I know this seems like a small silly post, but I didn't find this info being stated anywhere else, so I just wanted to document it here.
    – Felipe D.
    Jan 4, 2022 at 16:35

1 Answer 1

12

You can load that string into a GeoDataFrame using the read_file method:

import geopandas as gpd
gdf = gpd.read_file(geojson_str, driver='GeoJSON')

In the code above, gdf is a CRS-aware GeoDataFrame that you can manipulate however you want.

Credit

Special credit to @tynowell for highlighting that this is possible in an unrelated thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.