rgugik icon indicating copy to clipboard operation
rgugik copied to clipboard

Splitting large geometries in query

Open j-miszczyszyn opened this issue 1 year ago • 2 comments

Hello, i find a problem with requesting date for big areas.

remotes::install_github("kadyb/rgugik")
library(rgugik)
library(sf)
library(tidyverse)

#Preparing data
counties = county_names
counties = counties[substr(counties$TERYT, 1, 2) == "16", "TERYT"]
counties_geom = borders_get(TERYT = counties)

#Subset for smaller area
counties_geom= counties_geom[1,]

req_df = DEM_request(counties_geom)

ERROR: DEM_request(counties_geom)': maximum number of records, reduce the area

May I suggest a solution using loops ?

aoi=st_as_sf(counties_geom)
grid=st_make_grid(aoi, n=10)  
aoi=st_intersection(aoi, grid)

result_dem=data_frame()

for (i in 1:nrow(aoi)) {
  req_df = DEM_request(aoi[i, ])
  result_dem = bind_rows(result_dem, req_df)
}

j-miszczyszyn avatar Feb 08 '24 13:02 j-miszczyszyn

req_df = DEM_request(counties_geom)
#> Warning message:
#> In DEM_request(counties_geom) : maximum number of records, reduce the area

Hi! This is not an error, but a warning and is expected. The server can return maximum 1000 records in a single query (unless anything has changed). This function expects the geometries will be small enough not to exceed the query limit, otherwise the geometries must be split into smaller parts as you showed.

kadyb avatar Feb 08 '24 20:02 kadyb

Thanks! Is it possible to add new function based on spliting ?

j-miszczyszyn avatar Feb 08 '24 23:02 j-miszczyszyn