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());


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());


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"
  • do you mean the axis order with in the coordinates or the actual order of the coordinates? we need to know more about your data source and the code consuming it - what CRS are you using at each end? – Ian Turton Jul 1 at 12:41
  • 1
    Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works. – Ian Turton Jul 1 at 12:41
  • Thanks for the info. I edited title and question to be more precise. – vladobl Jul 1 at 19:25
  • It looks like it has something to do with the CRS of the original data in PostGIS. When I transformed the data to 4326 at the backend, everything works smoothly. Maybe (just guessing) the culprit is in the geospatial libraries or PostGIS on the production server (they are all older versions). – vladobl Jul 2 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.