Hands-On Geospatial Analysis with R and QGIS
上QQ阅读APP看书,第一时间看更新

Changing projection system

To change projection, we can use spTransform() from the rgdal package. We can do so using a CRS() argument inside spTransform():

map_bd = spTransform(map_bd, CRS("+proj=longlat +datum=WGS84"))

The preceding code sets the projection system to the longitude and latitude and the GCS to WGS84. If we want to change the projection to any other layer's (shapefile's) projection inside CRS(), we can write proj4string() to get the CRS of a new layer and then set it to that. For example, if we want to set the projection system of a layer a to the projection system of layer b, we can do so simply by writing the following: 

a = spTransform(a, CRS(proj4string(b)))