Estoy tratando de combinar ".h5" archivos de datos de luz nocturna de Hawai con zipcode-shapefile de Hawai, pero estoy recibiendo el siguiente error:
#Error: [crop] extents do not overlap
Los códigos R están a continuación, y los datos se pueden descargar desde google drive con el enlace de abajo. https://drive.google.com/drive/u/2/folders/1IpkbgITblqxU9sArUFtD_-Oo3WtF6wQg
Nota: Si prefiere utilizar el enlace oficial para los datos (enlace más abajo), deberá registrarse.
library(terra) # the latest version of raster
library(sf)
# get hc files for jan 1 2022 of hawaii from the link below (need to register for getting data):
# https://ladsweb.modaps.eosdis.nasa.gov/search/order/4/VNP46A2--5000/2022-01-01..2022-01-01/N/-159.9,22.4,-154.4,18.8
# files are VNP46A2.A2022001.h02v07.001.2022009102111.h5 and
# VNP46A2.A2022001.h02v06.001.2022009101742.h5
# read two hc tile files for day 1 of 2022
temp_files<-list.files(pattern="VNP46A2.A2022001")
# read each hc files with rast
temp_files_rast <- sprc(lapply(temp_files, rast))
# merge raster files
data_raster <- mosaic(temp_files_rast)
# we need `DNB_BRDF-Corrected_NTL` layer only
data_raster_req <- data_raster$`DNB_BRDF-Corrected_NTL`
# assign crf since no crf is provided
crs(data_raster_req) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
# we need to get the nightlight data for zipcode level, so get the shape file to overlay on raster file
# https://files.hawaii.gov/dbedt/op/gis/data/zcta20.shp.zip
haw_sf<-read_sf("zcta20.shp")
# convert shape file to spatial class object
haw_sp<-as(haw_sf,"Spatial") # gives spatial class object
# to make sure shape file overlays with raster
haw_sp<-sp::spTransform(haw_sp,crs(data_raster_req))
# convert sp to sf
haw_sf<-as(haw_sp,"sf")
# next crop raster file for area of my interest
data_raster_crop <- crop(data_raster_req, haw_sp)