我正在处理一个使用废弃的crs格式的数据集,并希望在将数据集转换为SpatRaster后避免重新投影。似乎gdal会自动将EPSG:2163替换为EPSG:9311(请参见此处)。Gdal显然会显示警告,但是terra没有显示警告。
我可以通过使用完整的crs字符串来强制SpatRaster进入正确的crs。随后的操作(例如,掩蔽)似乎会使用已废弃的crs,这正是所需的。
我可以通过使用完整的crs字符串来强制SpatRaster进入正确的crs。随后的操作(例如,掩蔽)似乎会使用已废弃的crs,这正是所需的。
r <- rast(ncol = 1, nrow = 1, vals = 1,
xmin = -1694992.5, xmax = -1694137.5,
ymin = -430492.5, ymax = -429367.5,
crs = 'EPSG:2163') # creates raster in EPSG:9311
crs(r) <- 'EPSG:2163' # doesn't work
# however, this successfully forces crs to EPSG:2163:
crs(r) <-"PROJCRS[\"US National Atlas Equal Area\",\n BASEGEOGCRS[\"Unspecified datum based upon the Clarke 1866 Authalic Sphere\",\n DATUM[\"Not specified (based on Clarke 1866 Authalic Sphere)\",\n ELLIPSOID[\"Clarke 1866 Authalic Sphere\",6370997,0,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n ID[\"EPSG\",4052]],\n CONVERSION[\"US National Atlas Equal Area\",\n METHOD[\"Lambert Azimuthal Equal Area (Spherical)\",\n ID[\"EPSG\",1027]],\n PARAMETER[\"Latitude of natural origin\",45,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8801]],\n PARAMETER[\"Longitude of natural origin\",-100,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8802]],\n PARAMETER[\"False easting\",0,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8806]],\n PARAMETER[\"False northing\",0,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8807]]],\n CS[Cartesian,2],\n AXIS[\"easting (X)\",east,\n ORDER[1],\n LENGTHUNIT[\"metre\",1]],\n AXIS[\"northing (Y)\",north,\n ORDER[2],\n LENGTHUNIT[\"metre\",1]],\n USAGE[\n SCOPE[\"Statistical analysis.\"],\n AREA[\"United States (USA) - onshore and offshore.\"],\n BBOX[15.56,167.65,74.71,-65.69]],\n ID[\"EPSG\",2163]]"
然而,当我将光栅图写入GeoTIFF格式时,我还没有找到如何覆盖gdal替换crs的方法。
tf <- tempfile(fileext = '.tif')
writeRaster(r, tf) # this doesn't work
writeRaster(r, tf, gdal = 'OSR_USE_NON_DEPRECATED=NO') # neither does this
笨拙的解决方法是在将GeoTiff加载到R中后,仅使用完整的CRS字符串重新定义CRS。是否有更好的方法来覆盖CRS替换,以便在读写文件时使用?