I created a circle using geopandas and it returned a shapely polygon:
POLYGON: ((...))
I want this same polygon as a geojson object. I ran across this:
shapely.geometry.mapping(shapelyObject)
which returns this:
{'type': 'Polygon', 'coordinates': (((570909.9247264927, 125477.71811034005)...}
But when I try to map this in mapbox it does not show anything. I think maybe it is not fully a geojson object.
Something like this should do the trick:
Now you can try to map
features
in mapbox. Hope this helps.Reference: https://gis.stackexchange.com/questions/213717/geometry-workflow-from-shapely-to-geojson
Use the driver provided by fiona:
If you don't want to create this dict manually, you can also rely on
geopandas
creating it:(Note that this gives a FeatureCollection and not a single feature.)
Or to a string (or file):
To write a standard geojson object using pandas you shall use the driver provided by
fiona
as recommended in the documentationSee
import fiona; fiona.supported_drivers
for a list of fully supported driversShapely returns a python dict where all the coordinates are in tuples. You need to convert to JSON in order for mapbox, etc... to properly accept it.