尽管投影相似,但光栅和形状未对齐
Misalignment in raster and shape despite similar projection
我裁剪了从 Chelsa 获得的气候数据,以使用国家/地区形状文件获得荷兰的栅格。绘制两者表明它们未对齐。投影是一样的。
我关注了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。
像你一样,我有很多 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")
#
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)
我裁剪了从 Chelsa 获得的气候数据,以使用国家/地区形状文件获得荷兰的栅格。绘制两者表明它们未对齐。投影是一样的。
我关注了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。
像你一样,我有很多 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")
#
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)