I'm undertaking a fairly simple workflow all within a python script with the goal of passing urlencoded GeoJSON in a URL to the Mapbox static API:
- create a point from DD string in
EPSG:4326
: - convert to UTM for easier units and buffer the point generating a polygon
- transform back to WGS84 for the API
- generate valid, URL encoded GeoJSON string.
My hangup is the last part. I've used Shapely and pyproj to conduct 1-3 but using:
json.dumps(mapping(<shapely.geometry.polygon.Polygon at 0x106a22690>))
(and several permutations of this) and encoding it using urlencode
or url_quote
generates an encoded URL with JSON that returns 'Invalid Geojson' from Mapbox.
I am optimistic that the geojson
library may solve this, but I can't seem to find a simple way to convert a shapely Polygon object to a GeoJSON polygon object.
Best Answer
Decided to use the
mapbox-sdk-py
library instead. Works well but the pipeline from shapely to a map-able feature using the SDK is a little cumbersome (per this issue)Need to add some features to the shapley (
geom
, below) object and encapsulate it in a list:feature = [{'type': 'Feature', 'properties': {}, 'geometry': mapping(geom)}]
for the
Static
method to work.Thanks @perrygeo and @sgillies for the hints.