From 85a9de867fba2e3be129081027c8e245d05456c7 Mon Sep 17 00:00:00 2001 From: edarin Date: Fri, 17 Jun 2022 12:31:38 +0100 Subject: [PATCH 1/3] use st_make_valid to process bf with geom errors --- DESCRIPTION | 4 +++- R/calculate_pixel_footstats.R | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a3a255a..fb72e8b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,9 @@ Imports: units, filelock, geosphere, - geos + geos, + iterators, + mmap LazyData: true Description: Support for morphometric calculations of building footprints implemented in R. It provides flexible tools for processing 2D vector polygon representations of structures. The functionality includes basic geometry and morphology measures, distance and clustering metrics. These calculations are supported with helper functions for spatial intersections to define zonal indices and tiled reading/writing of data files. Encoding: UTF-8 diff --git a/R/calculate_pixel_footstats.R b/R/calculate_pixel_footstats.R index 6d15160..19e6f81 100644 --- a/R/calculate_pixel_footstats.R +++ b/R/calculate_pixel_footstats.R @@ -530,6 +530,11 @@ process_tile <- function(mgTile, mgBuffTile, suppressWarnings(Xsub <- sf::st_cast(Xsub, "POLYGON")) } + #make valid + if(any(sf::st_is_valid(Xsub) == F)){ + suppressWarnings(Xsub <- sf::st_make_valid(Xsub)) + } + # processing if(nrow(Xsub) > 0){ # read proxy to grid and convert to polygon object From 4cb9c7ff3e2dd9d47afb55bf0026970fd3a188e4 Mon Sep 17 00:00:00 2001 From: edarin Date: Fri, 17 Jun 2022 12:35:15 +0100 Subject: [PATCH 2/3] add message on number of tiles created --- R/calculate_pixel_footstats.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/calculate_pixel_footstats.R b/R/calculate_pixel_footstats.R index 19e6f81..e6fc811 100644 --- a/R/calculate_pixel_footstats.R +++ b/R/calculate_pixel_footstats.R @@ -354,6 +354,7 @@ calc_fs_px_internal <- function(X, what, how, tiles <- gridTiles(template, px=tileSize) if(verbose){ + cat("Number of tiles created:", nrow(tiles), "\n") file.create(tile_log <- file.path(outputPath, "tile.log")) } From f559f74142efd65b0d39ea6efedad391c5d51c77 Mon Sep 17 00:00:00 2001 From: edarin Date: Fri, 17 Jun 2022 13:30:05 +0100 Subject: [PATCH 3/3] print message for validity --- R/calculate_pixel_footstats.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/calculate_pixel_footstats.R b/R/calculate_pixel_footstats.R index e6fc811..5b56674 100644 --- a/R/calculate_pixel_footstats.R +++ b/R/calculate_pixel_footstats.R @@ -533,6 +533,7 @@ process_tile <- function(mgTile, mgBuffTile, #make valid if(any(sf::st_is_valid(Xsub) == F)){ + if(verbose){cat('Invalid geometries found in polygons and corrected')} suppressWarnings(Xsub <- sf::st_make_valid(Xsub)) }