TransWikia.com

Shapefile in leaflet shifted North 0.25°

Geographic Information Systems Asked by Stefan Gofferje on September 2, 2021

I have the following problem:

I render a bunch of weather maps as PNG overlays with grads and then reproject them from EPSG:4326 to EPSG:3857 to display them in leaflet as follows:

gdal_translate -of "GTIFF" -a_srs EPSG:4326 -gcp 0 0 -40.0 80.0 -gcp 4800 0 80.0 80.0 -gcp 2400 1000 20.0 55.0 -gcp 0 2000 -40.0 30.0 -gcp 4800 2000 80.0 30.0 ${INFILE} /tmp/SK_L_referenced.tif
gdalwarp -overwrite -setci -t_srs EPSG:3857 /tmp/SK_L_referenced.tif /tmp/SK_L_warped.tif
gdal_translate -of PNG /tmp/SK_L_warped.tif /tmp/SK_L_warped.png

Those reprojected PNG in leaflet match the maps that grads produces itself, i.e. they should be correct.
Additionally, I reproject some shapefiles which I also produce with grads as follows:

ogr2ogr -f "ESRI Shapefile" output.shp input.shp -s_srs EPSG:4326 -t_srs EPSG:3857 -overwrite'

Those files appear in leaftlet shifted ~0.25° to the North. I have no clue whatsoever what could be the problem here. It’s a total mystery to me.

Screenshot of shifted shapefile vs. OK PNG overlay

One Answer

Apparently, leaflet uses EPSG:4326 for input and output, so reprojecting the shapefiles isn't necessary in the first place. When not reprojecting the shapefiles from 4326 to 3857, they are displayed correctly. The shift appears to be a bug in a library.

See also https://github.com/calvinmetcalf/leaflet.shapefile/issues/60

Answered by Stefan Gofferje on September 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP