Geographic Information Systems Asked by vladobl on June 15, 2021
I have a polygon layer fed from GeoDjango + PostGIS as GeoJSON.
Its original CRS is 3908. It’s being drawn as a GeoJSON layer in Leaflet in CRS 4326 (I figure it is transformed on the fly by Django GeoJSON serializer) with the standard OSM tile basemap.
On my development server the working code is (in Django template):
var basemap = L.tileLayer('//{s}.tile.osm.org/{z}/{x}/{y}.png');
var geojson_lyr = L.geoJson({{geojson_data|safe}});
var m = L.map('map').fitBounds(geojson_lyr.getBounds());
basemap.addTo(m);
geojson_lyr.addTo(m);
However, on a production server, this code results in a mirrored polygon being drawn far away from where it should (south Arabian Peninsula instead of Bosnia and Herzegovina), which is in fact the exact position of the original polygon with lon-lat values reversed, so I have to fix it with coordsToLatLng
option like:
var basemap = L.tileLayer('//{s}.tile.osm.org/{z}/{x}/{y}.png');
var geojson_lyr = L.geoJson({{geojson_data|safe}}, {
coordsToLatLng: function (coords) {
return new L.LatLng(coords[0], coords[1], coords[2])
});
var m = L.map('map').fitBounds(geojson_lyr.getBounds());
basemap.addTo(m);
geojson_lyr.addTo(m);
Does anyone know what could be the reason for this different behaviour between local and production server, as I would like to have the same Leaflet code in development and production environments?
Environments on local and remote machines are the same as far as Django packages go.
The only differences are PostGIS and geospatial libraries versions.
On remote:
POSTGIS="2.1.8 r13780" GEOS="3.8.1-CAPI-1.13.3" PROJ="Rel. 4.8.0, 6 March 2012"
GDAL="GDAL 1.11.4, released 2016/01/25" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
On local:
POSTGIS="2.5.1 r17027" [EXTENSION] PGSQL="94" GEOS="3.7.0-CAPI-1.11.0 3.7.1" PROJ="Rel. 4.9.3, 15 August 2016"
GDAL="GDAL 2.2.4, released 2018/03/19" LIBXML="2.7.8" LIBJSON="0.12" LIBPROTOBUF="1.2.1" RASTER"
The reason for all problems was in GDAL. When I installed GDAL version 2.2.4 to the remote machine everything went smoothly (only it took me a while to figure out how to install PostGIS with geolibraries without a root access, which is why I tried to find another solution).
Answered by vladobl on June 15, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP