尽管投影相似,但栅格和形状未对准

时间:2019-01-29 16:00:54

标签: r raster rgdal

我裁剪了从切尔萨(Chelsa)获得的气候数据,以使用国家形状文件获得了荷兰的栅格。同时绘制都表明它们未对齐。投影是相同的。

https://ibb.co/f2f49PJ

我跟踪了neonscience.org上关于栅格的介绍,并在最近两天阅读了几篇文章和包装文档,因为事实证明,要获取GPS数据的气候数据非常困难。 (或者我只是比我所希望的更加无能)

setwd(pathtodata)

library(rgdal)
library(raster)

# data for raster http://chelsa-climate.org/downloads/ (adjust file name)
climate <- raster('CHELSAcruts_prec_8_2015_V.1.0.tif')

# data for NUTS shape files https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts#nuts16
bounds  <- readOGR(dsn=getwd(),'NUTS_RG_01M_2016_4326_LEVL_0')
bounds  <- bounds[bounds$NUTS_ID=='NL',]  

climate_nl <- crop(x=climate,y=bounds)
climate_nl@data@values[which(climate_nl@data@values==-32768)] <- NA

plot(climate_nl)
plot(bounds,add=T)

结果将裁剪原始.tif文件以仅显示荷兰。然后,我想继续提取GPS位置的值。目前,我获得了应该在范围内的位置的NA。

1 个答案:

答案 0 :(得分:0)

像您一样,我得到了很多NA,但是如果我缓冲bounds范围,我将获得除一个之外的所有NA:

# remotes::install_github("adamhsparks/GSODRdata", build_vignettes = TRUE)
library(GSODRdata)
library(GSODR)
library(dplyr)
library(sf)
library(raster)

climate <- raster("CHELSAcruts_prec_8_2015_V.1.0.tif") 
# https://stackoverflow.com/a/49159943/3362993
climate <- reclassify(climate, cbind(-Inf, 0, NA), right=FALSE)

NL <- get_GSOD(years = 2010, country = "Netherlands", max_missing = 5)
bounds <- GSODRdata::CHELSA[,c("STNID", "CHELSA_prec_8_1979-2013")] %>% 
  left_join(NL, by = "STNID") %>%
  dplyr::filter(!is.na(LON)) %>%
  distinct(STNID, `CHELSA_prec_8_1979-2013`, .keep_all = TRUE) %>%
  dplyr::filter(LON > -33) %>% # fix misclassified county codes
  st_as_sf(coords = c("LON", "LAT"), crs = 4326)

climate_nl <- raster::crop(climate, as_Spatial(st_buffer(bounds, 0.1)))
res        <- extract(climate_nl, as_Spatial(bounds))

plot(climate_nl)
plot(bounds, add = TRUE, color = "black")
plot(bounds[which(is.na(res)),]$geometry, add = TRUE, color = "red", pch = 19)
legend("topleft", legend = c("NA vals"), pch = 19)

enter image description here