3

I am using leaflet and the R library sp. The CRS from my leaflet map is EPSG3857 - WGS84 Web Mercator. I am retrieving the coordinates of my current map view with getBounds(). For further calculations I want to create a polygon from these coordinates. That works fine until I want to assign the CRS.

When I use this

+proj=longlat +datum=WGS84 +nodefs +ellps=WGS84 +towgs84=0.0.0 +init=epsg:3857

my Polygon is a square, which fits my current map view. I check that visually through plotting the Polygon. The plot is a square. That fits since my map view is a square too. When I use the proj4 I obtain from http://spatialreference.org/ref/sr-org/7483/ my polygon is shaped rectangular.

 +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs

How comes the two are different? Shouldnt when I use the epsg:3857 it all be the same?! Am I missing something crucial here?

The values of the corners of my Polygon (which come back from the getBounds() function) are

 > coordinates  
             [Lng(x)] [Lat(y)]
 [corner 1]  2.570801 46.89023
 [corner 2] 17.424316 55.15377
 [corner 3] 17.424316 46.89023
 [corner 4]  2.570801 55.15377
3

The official definition for EPSG:3857 is

+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs

As you see, it is calculated on a sphere (a=b). Your formula is a bit contradictory:

You define a lat-long coordinate system on the WGS84 ellispoid, then you add +init=epsg:3857 which should invoke the World Mercator definition. This will lead to uncertain results. And BTW the towgs84 paramater should be 0,0,0.

If I load your coordinates as WGS84 EPSG:4326 into QGIS on an EPSG:3857 background, I see a square around Germany. If you see a rectangle (probably offshore from Nigeria), you might have missed to tell your software that the coordinates have to be reprojected to EPSG:3857.

  • Thanks for your answere. I think I have difficulties understanding it. I thought I tell the software to reproject them to EPSG:3857 by adding this +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs?! – Stophface Aug 25 '15 at 15:58
  • 1
    No, you tell the software that it should treat the data as Web Mercator meter coordinates, but you don't change the coordinate values. You can use ogr2ogr or cs2cs or some built-in leaflet function to reproject the coordinates. – AndreJ Aug 25 '15 at 17:56
  • Okay. I set my leaflet map to EPSG3857 which is Web Mercator. I am using a leaflet function to obtain my coordinates (therefore it should know that it is Web Mercator). But (!), the coordinates I am obtaining are not in Web Mercator Units?! – Stophface Aug 26 '15 at 9:58
  • If you look up the definition at leafletjs.com/reference.html#map-get-methods it notes Returns the LatLngBounds of the current map view and that is in degrees and not meters. – AndreJ Aug 26 '15 at 11:24
  • Ok. That makes sense... I did not have that in mind. The CRS stuff get me confused always. So, to sum up: I recieve the data, and assign WGS84 EPSG:4326 as the datum to my data. Then I reproject it into EPSG4320 (Web Mercator) and finally tell my software with +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs that its treating with Web Mercator shapes?! – Stophface Aug 26 '15 at 11:44

Your Answer

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

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