2

I have one raster and a shapefile of points. I want to check them if they are in the same coordinate system by plotting them together on a map (like in a classical GIS), here the R script :

# raster first
library(raster)
setwd("P:/folder/")
my.raster <- raster("raster_1991.img")

# shapefile second
library(rgdal)
library(sp)
library(maptools)

setwd("P:/folder")
meteo.shp <- readShapePoints("meteo.shp")

# set up same coordinate system
coord.sys <- CRS("+init=epsg:2065")
proj4string(meteo.shp) <- coord.sys
proj4string(my.raster) <- coord.sys

# plot them in one map (window)
plot(meteo.shp)
plot(my.raster, bg = "transparent", add = TRUE)

I am able to read the data and plot them, but only separately. How can I make sure myself that the points - meteo stations - are exactly where they should be if I cannot check them on a map?

  • What CRS information did the two inputs have before you assigned EPSG:2065? Did proj4string() throw any warnings when you used it? – obrl_soil Mar 19 at 22:39
  • @obrl_soil I don't know exactly, when I do summary(meteo.shp) before assigning EPSG I get Object of class SpatialPointsDataFrame Coordinates: min max coords.x1 20.06176 20.28333 coords.x2 49.11886 49.26306 Is projected: NA proj4string : [NA] – user3624251 Mar 20 at 7:10
  • Run proj4string(meteo.shp) and proj4string(my.raster) before setting them to coord.sys - do they both return NA? – obrl_soil Mar 20 at 12:53
  • @obrl_soil No, only the meteo.shp is NA. – user3624251 Mar 20 at 13:30
  • Are you sure that it should be EPSG:2065? What made you pick that system? – obrl_soil Mar 20 at 23:45
2

Look at the tmap package, which can draw spatial objects on a web map with a choice of map layer backgrounds, such as OpenStreetMap.

There are other ways of doing that, including the mapview package and the leaflet package. There are also packages that will download OpenStreetMap tiles for context in R graphics plots but tmap and the web map will allow you convenient zoom and pan functionality.

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.