openstreetmap – Correct Projections for Leaflet and OSM

coordinate systemleafletopenstreetmap

I downloaded data from OSM and extract lat/lng coordinates from a user who is clicking on a leaflet map. So my program returns the coordinates where a user clicked!

I am wondering what crs I need to assign them?

As stated here and here there are two possible choices.

OSM

What I see on the screen is Web Mercator (EPSG 3857). The data I download from OSM is in WGS84 (EPSG 4326)?

Leaflet

Everything in Web Mercator (EPSG 3857)

What I am wondering is what CRS I need to assign to the downloaded OSM data and the data I get returned in my program from leaflet.

Best Answer

You should not have to do any particular conversion on your OSM data or Leaflet returned coordinates.

There is a high confusion on this subject, but I think it comes down to a simple explanation:

  • OSM data is in WGS84 datum (EPSG 4326). This is how you plot the Earth onto an ellipsoid.
  • Web Mercator (EPSG 3857) is how you project this ellipsoid onto a plane.
  • Most online mapping services (including Leaflet-based OSM and Google Maps) display maps in Web Mercator (EPSG 3857), but internally use WGS84 datum. The conversion is automatically done internally. So the returned coordinates are already in WGS84.
  • If your program uses Leaflet default CRS, it is Web Mercator, and the returned coordinates are in WGS84.