jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
898 stars 120 forks source link

GeoJSON data format #141

Closed arrato closed 2 years ago

arrato commented 4 years ago

I am using https://wanderdrone.appspot.com/ API for live data driven leaflet map. To generate similar geojson, I used

my_point = Point((-3.68, 40.41)) Feature(geometry=my_point)

that generates {"geometry": {"coordinates": [-3.68, 40.41], "type": "Point"}, "properties": {}, "type": "Feature"}

On original page, that works correctly with leaflet, geojson looks like this : {"geometry": {"type": "Point", "coordinates": [93.9898619431257, 10.737359341831866]}, "type": "Feature", "properties": {}}

Although it should not affect the map functionality, in reality it does.

What do I wrong ? GeoJSON appears on API page correctly.

JRHutson commented 4 years ago

Why are you needing to convert the API response to a point?

Are you using the Leaflet-Realtime plugin?

If so, does the format specified in the documentation not work?

https://github.com/perliedman/leaflet-realtime

var map = L.map('map'),
    realtime = L.realtime({
        url: 'https://wanderdrone.appspot.com/',
        crossOrigin: true,
        type: 'json'
    }, {
        interval: 3 * 1000
    }).addTo(map);

realtime.on('update', function() {
    map.fitBounds(realtime.getBounds(), {maxZoom: 3});
});
rayrrr commented 4 years ago

Not sure what's going on here. Could be an issue with the other system, but if it is any use to @arrato or anyone else reading this, the correct way to produce a valid output GeoJSON string is to use the dumps() method. Something like:

geojson.dumps(Feature(geometry=Point((-3.68, 40.41))))

as documented at https://github.com/jazzband/geojson#geojson-encoding-decoding

Hope that helps.