3

I'm trying to get familiar with Folium library in Python. I wanted to make a web-map of Turkey. Framework uses EPSG:3857 Web Mercator CRS as default. I tried to use approximate coordinates at the centroid of Turkey in EPSG:4326 CRS which is lat:39.0 and lon:35.0 by specifying EPSG:4326 as CRS while giving the parameters but output map pointed out somewhere out of projection area near Pacific Ocean. I looked at epsg.io to confirm that I'm not confusing CRS but could not figure what is the problem myself. Below are my two examples:

1- crs; EPSG:3857 coordinates;(lat:39, lon:35)

Centers at Syria, unsurprising to have misalignment since CRS is Web-Mercator and coordinates at Geographic WGS84

webMap = folium.Map(location=(39,35),
                    zoom_start=5,
                    crs='EPSG3857') #which is default

# visualize
webMap

Correctish output

2- crs; EPSG:4326 coordinates;(lat:39, lon:35)

Centers at out of projection area

webMap = folium.Map(location=(39,35),
                    zoom_start=10,
                    crs='EPSG4326') 

 visualize

webMap

totally wrong

Can anyone point out what I am missing?

1 Answer 1

7

There are several things you have to take into account when dealing with coordinates and coordinate systems in Leaflet.

First, regardless of the coordinate system of the actual map displayed, all coordinates passed to Leaflet functions/methods are always EPSG:4326.

Second, order of coordinates passed to Leaflet is [latitude, longitude]. Since in your first attempt you used reversed coordinate order, you ended in Syria instead of Turkey.

And third, when defining/creating map with folium.Map call, actual crs of map has to be specified. Since your map is in EPSG:3857, your second attempt was completely off.

1
  • Was going in circles - transforming an image overlay from one crs to another (neither of which were lat & lon) and could not figure why no combination of coordinates in any order seemed to worked. Thank you!
    – jwolf
    Mar 7, 2021 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.