Open jhotujec opened 7 years ago
The widget save the geometries as GeoJSON ones. GeoJSON uses the coordinates as x/y ones.
@Gagaro thanks for the explanation. Is there a quick way to change this without having to rewrite huge chunks of the widget?
What issue do you have exactly? The default SRID should be 4326. How do you use the data afterwards ?
My issue is that, as I understand, according to SRID4326 geographical data is supposed to be saved in order of lat/long and with the widget coordinates are reversed. That leads to having to reverse Point
coordinates everytime I wanna do some GeoDjango lookups (for example checking if Polygon
contains Point
)
This is how I initiate widget (forms.py
)
widgets = {
'garage': LeafletWidget(),
'airports': LeafletWidget(),
}
This is how they are defined (models.py
)
garage = models.PointField(default=(40, 40))
airports = models.MultiPolygonField(null=True)
So when data is saved the coordinates are (x,y) instead of (lat, long) in the database. I'm using default settings for django-leaflet
- not overriding anything.
Thanks!
They should be stored correctly in the DB. How do you do the GeoDjango lookup?
Hm.. well for example, saving London
in the database looks like this: SRID=4326;POINT(-0.118092 51.509865)
but lat/long of London
is 51.509865/-0.118092
. But what's interesting is that the widget represent location correctly.
Database (field structure)
(value in db)
Rendered widget in HTML
For GeoDjango lookup im doing <Polygon>.contains(<Point>)
but because the coordinates are reversed it returns False
Because they are stored as x y coordinates as well. Where do you get your polygon? Are you sure it's not the one having reversed coordinates?
So my understanding is that leaflet.js expects coordinates in order of lat/long but the widget is saving and displaying them in x,y.
I'm using SRID 4326 in my database and when i save the geometry with django-leaflet widget the coordinates are reversed.
Is there any way to change this?
EDIT Even when specifically setting SRID in widget it doesn't seem to work.
SO: link
Thanks