library(sf) library(sp) library(raster) shp <- read_sf("E:/waterconstraint/LoessPlateauRegion/LoessPlateauRegion.shp") r<-raster("E:/waterconstraint/GIMMS_NDVI/MonthMax/1982-01-01.tif") crs(shp) crs(r) shp_proj <- st_transform(shp,crs = (r) #r_crop <- crop(r,shp_proj) plot(r) plot(r_crop,main = "crop")
时间: 2023-06-11 13:05:35 浏览: 177
这段代码的作用是引入R语言中的sf、sp和raster三个包,然后读取一个shp文件和一个.tif文件(分别位于E:/waterconstraint/LoessPlateauRegion/ 和 E:/waterconstraint/GIMMS_NDVI/MonthMax/ 这两个文件夹下),并获取它们对应的坐标系信息。最后,将读取的shp文件转换为与.tif文件相同的投影坐标系(即广义选择不仅仅是地理坐标系)。
相关问题
library(sf) > library(sp) > library(raster) > shp <- read_sf("E:/waterconstraint/LoessPlateauRegion/LoessPlateauRegion.shp") > r<-raster("E:/waterconstraint/GIMMS_NDVI/MonthMax/1982-01-01.tif") > crs(shp) [1] "PROJCRS[\"WGS_1984_Albers\",\n BASEGEOGCRS[\"WGS 84\",\n DATUM[\"World Geodetic System 1984\",\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ID[\"EPSG\",6326]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"Degree\",0.0174532925199433]]],\n CONVERSION[\"unnamed\",\n METHOD[\"Albers Equal Area\",\n ID[\"EPSG\",9822]],\n PARAMETER[\"Latitude of false origin\",0,\n ANGLEUNIT[\"Degree\",0.0174532925199433],\n ID[\"EPSG\",8821]],\n PARAMETER[\"Longitude of false origin\",105,\n ANGLEUNIT[\"Degree\",0.0174532925199433],\n ID[\"EPSG\",8822]],\n PARAMETER[\"Latitude of 1st standard parallel\",25,\n ANGLEUNIT[\"Degree\",0.0174532925199433],\n ID[\"EPSG\",8823]],\n PARAMETER[\"Latitude of 2nd standard parallel\",47,\n ANGLEUNIT[\"Degree\",0.0174532925199433],\n ID[\"EPSG\",8824]],\n PARAMETER[\"Easting at false origin\",4000000,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8826]],\n PARAMETER[\"Northing at false origin\",0,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8827]]],\n CS[Cartesian,2],\n AXIS[\"(E)\",east,\n ORDER[1],\n LENGTHUNIT[\"metre\",1,\n ID[\"EPSG\",9001]]],\n AXIS[\"(N)\",north,\n ORDER[2],\n LENGTHUNIT[\"metre\",1,\n ID[\"EPSG\",9001]]]]" > crs(r) Coordinate Reference System: Deprecated Proj.4 representation: +proj=longlat +datum=WGS84 +no_defs WKT2 2019 representation: GEOGCRS["unknown", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]], ID["EPSG",6326]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8901]], CS[ellipsoidal,2], AXIS["longitude",east, ORDER[1], ANGLEUNIT["degree",0.0174532925199433, ID["EPSG",9122]]], AXIS["latitude",north, ORDER[2], ANGLEUNIT["degree",0.0174532925199433, ID["EPSG",9122]]]] > shp_proj <- st_transform(shp,crs = (r) + r_crop <- crop(r,shp_proj) Error: unexpected symbol in: "shp_proj <- st_transform(shp,crs = (r) r_crop"
根据您所展示的代码,出现了一个错误:在 crop(r,shp_proj) 中有一个意外的符号。我建议您将此行代码改为:r_crop <- crop(r,shp_proj)。此外,这对话似乎涉及到一些 GIS 操作和空间参考系统的知识,您是否需要更详细的解释或其他帮助?
阅读全文