简体   繁体   English

如何使用单层 shapefile 屏蔽 multi-layer.netCDF 或栅格?

[英]How do I mask a multi-layer netCDF or raster with a single-layer shapefile?

I am currently working with daily precipitation data in.netCDF format.我目前正在处理 .netCDF 格式的每日降水数据。 The data's at a 4km resolution that covers the United States.数据分辨率为 4 公里,覆盖美国。 However, I want to mask/clip the data with a much higher-resolution shapefile for a particular geographical region (about the size of a county).但是,我想为特定地理区域(大约一个县的大小)使用更高分辨率的 shapefile 来屏蔽/剪辑数据。 Ultimately, I want the output to be daily precipitation data, either at that high resolution or the original 4km resolution, for the much smaller area.最终,我希望 output 成为更小区域的每日降水数据,无论是高分辨率还是原始 4km 分辨率。

I've tried a couple different methods, with the most success using the following code:我尝试了几种不同的方法,使用以下代码最成功:

prcp_2000 <- raster::brick('pr_2000.nc')
shapefile <- shapefile("polygon_combined.shp")
shapefile <- spTransform(shapefile, crs(prcp_2000))
prcp_2000 <- mask(prcp_2000, shapefile)
prcp_2000 <- crop(prcp_2000, shapefile)
outfile <- paste("prcp_","2000_","CS",".nc",sep="")
writeRaster(prcp_2000, outfile, overwrite=TRUE, format="CDF", varname="prcp", varunit="mm/day", longname="mm of precipitation per day", xname="lon", yname="lat", zname="day", zunit="days since 1900-01-01")

However, I keep getting nothing but infinities/negative infinities for prcp output, even though I'm still getting appropriate variable lengths otherwise (day=366, lat=24, lon=23).但是,对于 prcp output,我只得到无穷大/负无穷大,即使我仍然得到适当的可变长度(日 = 366,纬度 = 24,经度 = 23)。 Am I missing something?我错过了什么吗?

The problem is the starting shapefile, shapefile <- shapefile("polygon_combined.shp") .问题是起始 shapefile, shapefile <- shapefile("polygon_combined.shp") I imported "polygon_combined.shp" into QGIS to plot a base layer under it easily.我将“polygon_combined.shp”导入 QGIS 到 plot 很容易成为它下面的基础层。 The image I've attached shows that it starts off in the Gulf of Mexico.我附上的图片显示它墨西哥湾开始。 With a bad location to begin with, transforming it isn't going to save it later.开始的位置不好,改造它不会在以后保存它。

墨西哥湾带有 AOI 的 QGIS 场景图像

I don't know the origin of the data, so I have no idea how it was produced this way to start.我不知道数据的来源,所以我不知道它是如何以这种方式产生的。 One way to possibly fix this is get the data from a different source.可能解决此问题的一种方法是从不同的来源获取数据。 The EPA makes an ecoregions product that has several levels of regions. EPA 制作了一个具有多个区域级别的生态区域产品。 I think you want the level IV data to get your region.我想你想要 IV 级数据来获取你的区域。 You may still need to transform it, but it'll be located in the right place to begin with.您可能仍需要对其进行转换,但它将位于正确的开始位置。 https://www.epa.gov/eco-research/ecoregion-download-files-state-region-5#pane-47 https://www.epa.gov/eco-research/ecoregion-download-files-state-region-5#pane-47

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 terra 包将 R 中的多层栅格(457 个波段)与一层栅格(值 0 和 1 )相乘? - How to multiply a multi-layer raster (457 bands) with a one-layer raster (values of 0 and 1 ) in R with terra package? 如何为 R 中的每一列创建一个单独的数据框,然后将所有栅格层栅格化并将其绑定到多层栅格中? - How to create an individual dataframe for each column in R to then rasterize and bind all raster layers into multi-layer raster? 可以使用不同模式创建多层对象吗? - can raster create multi-layer objects with different modes? 如何将多层ggplot导出到googleVis? - How to export a multi-layer ggplot to googleVis? 在R中的栅格图层上绘制shapefile - Plotting a shapefile on a raster layer in R 有没有办法将多层栅格(Terra)转换为 R 中的 rasterStack object(栅格)? - Is there a way to convert a multi-layer raster (Terra) to a rasterStack object (Raster) in R? 为什么在使用R-package Raster绘制带有“ image(x,y,z)”和“ plot(raster)”的NetCDF层时得到不同的结果? - Why do I get different results in plotting a NetCDF layer with “image(x,y,z)” and “plot (raster)” using R-package Raster? 将线形文件转换为栅格图层并保留值 - Convert a line shapefile to a raster layer and preserve values 使用 terra 使用其他图层的栅格堆栈的蒙版图层 - Mask layer of a raster stack using other layer using terra 为栅格堆栈中的每一层汇总跨多边形的值-如何将值与shapefile合并? - Summarizing values across polygons, for each layer in Raster Stack - How to merge values with shapefile?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM