I have geojson file like this:
location = {'type': 'Polygon', 'coordinates': [[[[-90.06, 29.34], [-89.8, 29.15], [-89.55, 29.26], [-89.61, 29.27], [-89.6, 29.35], [-89.67, 29.31], [-89.77, 29.33], [-89.75, 29.41], [-89.81, 29.43], [-89.83, 29.49], [-89.93, 29.51], [-89.94, 29.48], [-90.07, 29.55], [-90.17, 29.51], [-90.06, 29.43], [-90.06, 29.34]]]]}
I would like to extract the polygon information and save as polygon geometry in a geopandas data frame. I’m having trouble converting extracting this information from the geojson I would appreciate if anyone can help
Advertisement
Answer
- you can construct valid geojson from you dict snippet
- your coordinates are too deep hence taking zeroth element of first dimension
location = { "type": "Polygon", "coordinates": [ [ [ [-90.06, 29.34], [-89.8, 29.15], [-89.55, 29.26], [-89.61, 29.27], [-89.6, 29.35], [-89.67, 29.31], [-89.77, 29.33], [-89.75, 29.41], [-89.81, 29.43], [-89.83, 29.49], [-89.93, 29.51], [-89.94, 29.48], [-90.07, 29.55], [-90.17, 29.51], [-90.06, 29.43], [-90.06, 29.34], ] ] ], } gpd.GeoDataFrame.from_features( [ { "type": "Feature", "properties": {}, "geometry": { **location, **{"coordinates": location["coordinates"][0]}, }, } ] )
geometry | |
---|---|
0 | POLYGON ((-90.06 29.34, -89.8 29.15, -89.55 29.26, -89.61 29.27, -89.59999999999999 29.35, -89.67 29.31, -89.77 29.33, -89.75 29.41, -89.81 29.43, -89.83 29.49, -89.93000000000001 29.51, -89.94 29.48, -90.06999999999999 29.55, -90.17 29.51, -90.06 29.43, -90.06 29.34)) |