python – EPSG Conversion and Image Rotation in Folium

coordinate systemepsgfoliumoverlaypython

I'm using Python's folium library (which uses Leaflet) to display images over a map.

However, my original data uses EPSG:3035 and folium uses EPSG:4326 (WGS84). There is a rotation when converting from one to another.

With pyproj, I'm able to reproject the bounds into 4326 but folium's ImageOverlay function demands a bounds argument as follows : [[lat_min, lon_min], [lat_max, lon_max]] so I can only specify a "straight" rectangle.

The image below shows the result that I get and the rectangle which the image should fit into.

Current and expected results

Is it possible to rotate the bounds? How can I display my data at the right place?

Best Answer

Unless leaflet/folium can do this on-the-fly, you need to reproject your image to EPSG:4326. This involves a change of the grid system for your data, and is usually a lossy operation. Its unlikely this is a simple rotation, since you are transforming from a conical projection of the GRS80 ellipsoid to a lat-long coordinate system on the WGS84 ellipsoid.

I'd probably do this by using the gdalwarp command line tool, or its interface from QGIS, or similar tools in R. You'll end up with your rotated image within a larger rectangle filled with missing values, which should be rendered as transparent.

The Python rasterio package has functionality for raster warping: https://rasterio.readthedocs.io/en/latest/