YT Li
YT Li

Reputation: 73

How to change projection and convert shapefile to rasterstack in R?

I have a map shapefile from my colleagues and I've also got some observation data with their coordinates recorded in WGS84. I read the shapefile in R:

# read shapefile
> shpmap <- readOGR(dsn = "soil_type", layer = "soil_type_data")
OGR data source with driver: ESRI Shapefile 
Source: "soil_type", layer: "soil_type_data"
with 18542 features
It has 8 fields

# show shapefile attributes
> shpmap
class       : SpatialPolygonsDataFrame 
features    : 18542 
extent      : 44795.53, 1572888, 3187943, 4661428  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=aea +lat_1=25 +lat_2=47 +lat_0=0 +lon_0=105 +x_0=0 +y_0=0 +ellps=krass +units=m +no_defs

After I read the shapefile, I found it's using krassovsky ellps. Now I want to do two things. First, change the projection of the shapefile to match my observation's, WGS84. Second, the shapefile contains several soil attributes and I want to convert them into a rasterstack object.

I am new to deal with GIS files in R and I am really confused. I would appreciate any suggestions! Thanks in advance!

Upvotes: 1

Views: 2345

Answers (1)

Robert Hijmans
Robert Hijmans

Reputation: 47536

Use spTransform to change the crs.

library(rgdal)
g <- spTransform(shpmap, CRS("+proj=longlat +datum=WGS84"))

You can use rasterize (raster package) to create a RasterBrick (Stack)

Upvotes: 1

Related Questions