kadyb / rgugik

Download datasets from Polish Head Office of Geodesy and Cartography
https://kadyb.github.io/rgugik/
Other
33 stars 3 forks source link

Splitting large geometries in query #99

Open j-miszczyszyn opened 9 months ago

j-miszczyszyn commented 9 months ago

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)
}
kadyb commented 9 months ago
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.

j-miszczyszyn commented 9 months ago

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