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.
json.dumps(mapping(<shapely.geometry.polygon.Polygon at 0x106a22690>))is not a correct formulation – gene Oct 10 '16 at 18:05geojson.dumps(mapping(poly))wherepolyis a valid shapely polygon geometry generates valid geojson. my challenge at this point is to encode it in such a way that the mapbox api doesn't reject it. – PeterT Oct 10 '16 at 18:17mapbox-sdk-pyas well and get a422server response with valid python geojson object... this feels like it should be easy. I must be missing something... – PeterT Oct 10 '16 at 19:40