I am new to GIS and R leaflet, and I am trying to plot the starting points of protected rivers in Spain. Example of coordinates from the original file:

Nombre.de.los.cauces.principales Coordenada.X.inicio.cauce..UTM..ETRS.89. Coordenada.Y.inicio.cauce..UTM..ETRS.89.
1 Río Burbia 679349 4742582
2 Río Porcarizas 677311 4737191
3 Río de Tejera 675899 4735382

The coordinates are in ETRS89, so I am using EPSG:25828 for the plot (the proj4def has been copied directly from the EPSG-page). I defined the CRS as follows:

epsg25828 <- leafletCRS(
     crsClass = "L.Proj.CRS", code = "EPSG:25828",
     proj4def = "+proj=utm +zone=28 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs",
     resolutions = 2^(13:-1), # 8192 down to 0.5

This is used in leaflet as follows:

leaflet(options = leafletOptions(csr = epsg25828)) %>%
addTiles() %>% 
addMarkers(lng = 675899, lat = 4735382)

The result is a world map with a marker at the top: R PLot

What am I doing wrong?


From the documentation here: https://rstudio.github.io/leaflet/projections.html

# Displaying shapes with custom projections

While tiles must be in the same projection as used in the leafletCRS function,
you must always use WGS 84 longitude/latitude data for markers, circles, 
polygons, and lines. Leaflet will automatically project the 
coordinates when displaying.

So in your map leaflet is trying to map lat-long of (lng = 675899, lat = 4735382) which is invalid since the numbers are greater than 180/90 degrees.

You should only use leafletCRS if your tiles are in a different coordinate system. The standard OSM ones -- and most others -- are in EPSG:3857 and so that's the default.

If you have point or polygon data in another coordinate system you have to convert them to true lat-long first, which you can do with st_transform from the sf package or various other ways.

But when I try and convert your points using the EPSG code you give I end up with points in Africa and not Spain. "ETRS89" is not a projected coordinate system, its an earth reference system that projections are based on...

| improve this answer | |
  • Thanks, @Spacedman. The file with the coordinates does not specify an EPSG coordinate code, but EPSG:3042 ETRS89 / UTM zone 30N (N-E) seems to make sense. – ElToro1966 Mar 14 '19 at 17:29

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.