在 R 和 QGIS 中重新投影时栅格大小增加
我正在使用北美的土地覆盖栅格,该栅格可在此处公开:https://open.canada.ca/data/en/dataset/4e615eae-b90c-420b-adee-2ca35896caf6
我将其剪辑在 R
中以覆盖魁北克/拉布拉多:
veg <- raster("CanadaLandcover2015/CAN_LC_2015_CAL.tif")
e <- extent(c(1000000, 2700000, 500000, 2700000))#all qc
veg_qc <- crop(veg, e)
该栅格最初位于投影 ESPG:3978 NAD83/Canada Atlas Lambert
中。我希望它是经纬度的,以便能够将值提取到数据点。
veg_qc2 <- projectRaster(veg_qc,crs="+proj=longlat +ellps=WGS84 +no_defs")
该单行运行大约需要 12 小时,并占用了超过 200 GB 的临时数据。最糟糕的是,有一个警告(抱歉没有复制它)并且只显示了一半的光栅。
所以我决定尝试使用QGIS
中的Wrap
功能。虽然它工作得很好,但输出光栅是 16 GB!原始裁剪栅格只有 693 MB。
更糟糕的是,我需要将值层包含在 R 中,因此我使用了:
veg_qc <- getValues(veg_qc)
并且出现以下错误:
错误:无法分配大小为 31.0 Gb 的向量
- 为什么重新投影时栅格会变大?
- 是否有一种方法可以压缩栅格或重新投影而不需要大量增加数据?
- 如何将值添加到大栅格图层?
最终,我可以使用数据的 mcp 进一步裁剪栅格。我还可以在 EPSG:3978
中重新投影我的数据和其他栅格(尽管我想知道我的其他栅格最终是否也会大于 10GB)。
I'm using a Land cover raster of North America which is publicly available here: https://open.canada.ca/data/en/dataset/4e615eae-b90c-420b-adee-2ca35896caf6
I clipped it in R
to cover Québec/Labrador:
veg <- raster("CanadaLandcover2015/CAN_LC_2015_CAL.tif")
e <- extent(c(1000000, 2700000, 500000, 2700000))#all qc
veg_qc <- crop(veg, e)
The raster is originally in projection ESPG:3978 NAD83/Canada Atlas Lambert
. I wanted it to be in lat and long to be able to extract the values to datapoints.
veg_qc2 <- projectRaster(veg_qc,crs="+proj=longlat +ellps=WGS84 +no_defs")
That single line took ~12 hours to run and took over 200 GB of Temp data. Worst, there was a warning (sorry did not copy it) and only half the raster showed.
So I decided to try with the function Wrap
in QGIS
. Although it worked perfectly, the output raster was 16 Gb! The original clipped raster was only 693 MB.
To make things worse, I need the value layer to be included in R
, so I used:
veg_qc <- getValues(veg_qc)
And I get the following error:
Error: cannot allocate vector of size 31.0 Gb
- Why does the raster get bigger when reprojected?
- Would there be a way to compress the raster or reproject without that giant increase of data?
- How can I add the values to a big raster layer?
Ultimately, I could clip the raster further with the mcp of my data. I could also reproject my data and my other rasters in EPSG:3978
(although I am wondering if my other rasters my end up as > 10GB too).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这周我刚刚遇到了同样的问题。重新投影后,从 40Mb 变为 350Mb。我在此链接中找到了答案平均两个栅格后的巨大文件大小。
我在 QGIS(此时不是 R)中所做的是,我在 Manu 栏中打开了以下功能: raster >转换>翻译,并在高级参数>其他命令行参数,我添加了
-co COMPRESS=LZW
。这将使用 LZW 方法进行压缩。另外,根据此 链接并考虑您的数据集,您可以使用 PACKBITS。我希望这对你有帮助。I just had the same issue this week. After a reprojection, from 40Mb to 350Mb. I found the answer in this link Huge file size after averaging two rasters.
What I did in QGIS (not R by this time) is that I opened the following function in the Manu bar: raster > conversion > translate, and in Advanced parameters > Additional command-line parameters, I added
-co COMPRESS=LZW
. This will compress using the LZW method. Also, according to this link and considering your dataset, you can use PACKBITS. I hope this helps you.