Reputation: 1
I have a raster in Lambert Conformal Conical projection that I would like to change to unprojected.
I tried to use the project function in terra package.The result raster has an extent that is very off from the region where it should be.
Here is the CRS of the original raster in proj4 as recognized by QGIS: "+proj=lcc +lat_0=90 +lon_0=100 +lat_1=0 +lat_2=57.29577951 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs"
Here are the codes that I tried so far, along w/ the metadata of the raster object (Thanks @L Tyrone for the suggestion : ) )
#The raster in Lambert projection.
flood<-rast("flood_2014_Glenda.tif")
#dimensions : 14983, 11835, 1 (nrow, ncol, nlyr)
#resolution : 19.99915, 19.99915 (x, y)
#extent : 2482274, 2718964, 1287189, 1586836 (xmin, xmax,
#ymin, ymax)
#coord. ref. : Lambert_Conformal_Conic_2SP
#min value : 0
#max value : 1
#An unpojected vector object. It is the same region as the raster
#object.
bicol<-vect("phl_adm2_bicol.shp")
#geometry : polygons
#dimensions : 6, 14 (geometries, attributes)
#extent : 122.2986, 124.4249, 11.72048, 14.50116 (xmin, xmax,
#ymin, ymax)
#coord. ref. : lon/lat WGS 84 (EPSG:4326)
flood_unprojected<-project(flood,crs(bicol))
flood_unprojected
#dimensions : 1966, 19090, 1 (nrow, ncol, nlyr)
#resolution : 0.0007564935, 0.0007564935 (x, y)
#extent : -30.45265, -16.01119, 82.91273, 84.4 (xmin, xmax,
#ymin, ymax)
#coord. ref. : lon/lat WGS 84 (EPSG:4326)
#name : flood_2014_Glenda
#min value : NaN
#max value : NaN
#Note that the extent of flood_unprojected is very different from
#that of the vector.
@margusl, I tried your suggestion, and my workflow also did not work for the input raster created from the terra system file. Here are the codes :
r_lcc <- terra::rast(system.file("ex/elev.tif",
package="terra"))
|> terra::project("+proj=lcc +lat_0=90 +lon_0=100 +lat_1=0
+lat_2=57.29577951 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
+type=crs")
bicol<-vect("phl_adm2_bicol.shp")
r_lcc_unproj<-project(r_lcc,crs(bicol))
r_lcc_unproj
#extent: 5.741667, 6.533333, 49.44167, 50.19167 (xmin, xmax,
#ymin,
#ymax)
r_lcc_o<-rast("C:/Users/xiaoj/AppData/Local/R/win-
library/4.3/terra/ex/elev.tif")
r_lcc_o
#extent: 5.164309, 7.115402, 49.17813, 50.44312 (xmin, xmax, ymin,
#ymax)
Upvotes: 0
Views: 41