Working with Polygons
Using polygons with offline event data
from shapely.geometry import shape
event = {"id": "268aCtdaPgDJNurMeP",
"title": "Flood Warning",
"geo": {
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-94.15, 39.1599999],
[-94.17, 39.220000000000006],
[-93.86, 39.25000000000001],
[-93.84, 39.18000000000001],
[-94.05, 39.11000000000001],
[-94.15, 39.1599999]
]
]
}
}
# other fields omitted...
}
# retrieving event's geojson field
event_geojson = event['geo']['geometry']
# parsing the geojson object using shape from shapely
parsed_polygon = shape(event_geojson)
# print the shapely polygon object
print(parsed_polygon)
>> POLYGON ((-94.15000000000001 39.1599999, -94.17 39.22000000000001, -93.86 39.25000000000001, -93.84 39.18000000000001, -94.05 39.11000000000001, -94.15000000000001 39.1599999))
Last updated
Was this helpful?