I have geojson file like this:
JavaScript
x
18
18
1
location = {'type': 'Polygon',
2
'coordinates': [[[[-90.06, 29.34],
3
[-89.8, 29.15],
4
[-89.55, 29.26],
5
[-89.61, 29.27],
6
[-89.6, 29.35],
7
[-89.67, 29.31],
8
[-89.77, 29.33],
9
[-89.75, 29.41],
10
[-89.81, 29.43],
11
[-89.83, 29.49],
12
[-89.93, 29.51],
13
[-89.94, 29.48],
14
[-90.07, 29.55],
15
[-90.17, 29.51],
16
[-90.06, 29.43],
17
[-90.06, 29.34]]]]}
18
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
JavaScript
1
39
39
1
location = {
2
"type": "Polygon",
3
"coordinates": [
4
[
5
[
6
[-90.06, 29.34],
7
[-89.8, 29.15],
8
[-89.55, 29.26],
9
[-89.61, 29.27],
10
[-89.6, 29.35],
11
[-89.67, 29.31],
12
[-89.77, 29.33],
13
[-89.75, 29.41],
14
[-89.81, 29.43],
15
[-89.83, 29.49],
16
[-89.93, 29.51],
17
[-89.94, 29.48],
18
[-90.07, 29.55],
19
[-90.17, 29.51],
20
[-90.06, 29.43],
21
[-90.06, 29.34],
22
]
23
]
24
],
25
}
26
27
gpd.GeoDataFrame.from_features(
28
[
29
{
30
"type": "Feature",
31
"properties": {},
32
"geometry": {
33
**location,
34
**{"coordinates": location["coordinates"][0]},
35
},
36
}
37
]
38
)
39
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)) |