-
Notifications
You must be signed in to change notification settings - Fork 107
Description
This is connected to https://stackoverflow.com/questions/79872596 which was posted by my colleague, and it's probably linked to #1994 as you already commented at SO. Here's the issue you requested.
Problem: reading a large vector file (geopackage) containing both MULTIPOLYGON and MULTISURFACE geometries worked with terra 1.8-86, but it crashes using 1.8-93.
A possibly related problem encountered further below is that terra does not always report the number of geometries correctly.
Observations with the original, very large file
First, showing the original problem (the whole file however is not public). It has 683548 MULTIPOLYGON and 452 MULTISURFACE geometries, totalling 684000 geometries.
> packageVersion("terra")
[1] ‘1.8.93’
> terra::libVersion()
gdal proj geos
"3.11.4" "9.4.1" "3.12.2"
>
> sf::st_layers("habitatmap.gpkg")
Driver: GPKG
Available layers:
layer_name geometry_type features fields
1 bwk_202503__bwkhab202503 Multi Polygon 684000 32
crs_name
1 BD72 / Belgian Lambert 72
>
> sf::read_sf("habitatmap.gpkg") |> sf::st_geometry_type() |> dplyr::as_tibble() |> dplyr::count(value)
# A tibble: 2 × 2
value n
<fct> <int>
1 MULTIPOLYGON 683548
2 MULTISURFACE 452
>
> terra::vect("habitatmap.gpkg")
*** caught segfault ***
address 0x7f7be06b9888, cause 'invalid permissions'
Traceback:
1: .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: 0x5c82125bf5f0>, dll = list(name = "Rcpp", path = "/usr/lib/R/site-library/Rcpp/libs/Rcpp.so", dynamicLookup = TRUE, handle = <pointer: 0x5c8211383c40>, info = <pointer: 0x5c8212330130>, forceSymbols = FALSE), numParameters = -1L), <pointer: 0x5c82185ff5d0>, <pointer: 0x5c8210e8c4a0>, .pointer, ...)
2: p@pntr$read(x, layer, query, extent, filter, proxy, what, dialect, opts)
3: .local(x, ...)
4: terra::vect("habitatmap.gpkg")
5: terra::vect("habitatmap.gpkg")
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 2
On the same file, but using terra 1.8-86:
> packageVersion("terra")
[1] ‘1.8.86’
> terra::libVersion()
gdal proj geos
"3.11.4" "9.4.1" "3.12.2"
>
> terra::vect("~/ContinuLegen/habitatmap.gpkg")
class : SpatVector
geometry : polygons
dimensions : 684000, 32 (geometries, attributes)
extent : 21851.2, 258916.5, 153049.4, 244027.9 (xmin, xmax, ymin, ymax)
source : habitatmap.gpkg (bwk_202503__bwkhab202503)
coord. ref. : BD72 / Belgian Lambert 72 (EPSG:31370)
names : OBJECTID TAG eval eenh1 eenh2 eenh3 eenh4 eenh5 eenh6 eenh7 (and 22 more)
type : <num> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
values : 1 32_00001_22 m ad
2 41_00001_22 m ad
3 32_00002_22 m ad So it worked before. Importantly, the number of geometries matches the expected number from sf::st_layers() above. We will see different behaviour below.
Observations on a small subset of geometries
After breaking down this file (writing subsets using sf, each time trying to read with terra), it appeared that only the MULTISURFACE geometries caused the problem, and apparently only a few of them.
Below code uses a geopackage, attached and zipped as hm_geometry.gpkg.zip. The geopackage has two layers:
multisurface_only: 11 MULTISURFACE geometries holding at least 3 different geometries that cause a crash (I believe the first geometry is among them)hm_geometry: 1 MULTIPOLYGON + the same 11 MULTISURFACE geometries.
These layers were created by reading the original large file in R with sf, then filtering and writing it to a geopackage layer.
In summary, we can see several odd things happening with the file below:
- both terra versions do read the
hm_geometrylayer, reporting there's just a single polygon inside. However there are 1 MULTIPOLYGON + 11 MULTISURFACE geometries present.- for terra 1.8-93, this contradicts the finding with the original large dataset habitatmap.gpkg, which caused it crashing (above)
- when reading the
multisurface_onlylayer, terra 1.8-86 reports an error, while terra 1.8-93 crashes as expected.
For terra 1.8-86 both observations are different from the case where the original dataset habitatmap.gpkg was read, i.e. where the total number of geometries was reported correctly.
> packageVersion("terra")
[1] ‘1.8.93’
>
> sf::st_layers("hm_geometry.gpkg")
Driver: GPKG
Available layers:
layer_name geometry_type features fields crs_name
1 hm_geometry 12 0 BD72 / Belgian Lambert 72
2 multisurface_only Multi Surface 11 0 BD72 / Belgian Lambert 72
>
> sf::read_sf("hm_geometry.gpkg", "hm_geometry") |> sf::st_geometry_type()
[1] MULTIPOLYGON MULTISURFACE MULTISURFACE MULTISURFACE MULTISURFACE
[6] MULTISURFACE MULTISURFACE MULTISURFACE MULTISURFACE MULTISURFACE
[11] MULTISURFACE MULTISURFACE
18 Levels: GEOMETRY POINT LINESTRING POLYGON MULTIPOINT ... TRIANGLE
>
> terra::vect("hm_geometry.gpkg", "hm_geometry")
class : SpatVector
geometry : polygons
dimensions : 1, 0 (geometries, attributes)
extent : 174413.5, 174561.3, 170620.7, 170689.9 (xmin, xmax, ymin, ymax)
source : hm_geometry.gpkg
coord. ref. : BD72 / Belgian Lambert 72 (EPSG:31370)
>
> terra::vect("hm_geometry.gpkg", "multisurface_only")
*** caught segfault ***
address 0x7beebd4b9888, cause 'invalid permissions'
Traceback:
1: .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: 0x571c616c4df0>, dll = list(name = "Rcpp", path = "/usr/lib/R/site-library/Rcpp/libs/Rcpp.so", dynamicLookup = TRUE, handle = <pointer: 0x571c6011e7e0>, info = <pointer: 0x571c616de910>, forceSymbols = FALSE), numParameters = -1L), <pointer: 0x571c60d253f0>, <pointer: 0x571c601e0010>, .pointer, ...)
2: p@pntr$read(x, layer, query, extent, filter, proxy, what, dialect, opts)
3: .local(x, ...)
4: terra::vect("hm_geometry.gpkg", "multisurface_only")
5: terra::vect("hm_geometry.gpkg", "multisurface_only")
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 2On the same file, but using terra 1.8-86:
> packageVersion("terra")
[1] ‘1.8.86’
>
> terra::vect("hm_geometry.gpkg", "hm_geometry")
class : SpatVector
geometry : polygons
dimensions : 1, 0 (geometries, attributes)
extent : 174413.5, 174561.3, 170620.7, 170689.9 (xmin, xmax, ymin, ymax)
source : hm_geometry.gpkg
coord. ref. : BD72 / Belgian Lambert 72 (EPSG:31370)
>
> terra::vect("hm_geometry.gpkg", "multisurface_only")
Error: [vect] cannot read this geometry type: Multi SurfaceBehaviour depends on the MULTISURFACE geometries included: example without problems
For terra 1.8-93 it should be added that most MULTISURFACE geometries from the original file could be read correctly; showing them as polygons.
The file below is attached and zipped as multisurface_ok.gpkg.zip. It contains 4 MULTISURFACE geometries that work (most do work); this is from the search for MULTISURFACE geometries that cause the crash.
> packageVersion("terra")
[1] ‘1.8.93’
>
> sf::st_layers("multisurface_ok.gpkg")
Driver: GPKG
Available layers:
layer_name geometry_type features fields crs_name
1 multisurface_ok Multi Surface 4 0 BD72 / Belgian Lambert 72
>
> terra::vect("multisurface_ok.gpkg")
class : SpatVector
geometry : polygons
dimensions : 4, 0 (geometries, attributes)
extent : 0, 1.145114e+243, -9.651334e-287, 3.156916e+238 (xmin, xmax, ymin, ymax)
source : multisurface_ok.gpkg
coord. ref. : BD72 / Belgian Lambert 72 (EPSG:31370) With terra 1.8-86, we still have the error as with the (other) MULTISURFACE geometries that caused the crash in terra 1.8-93:
> packageVersion("terra")
[1] ‘1.8.86’
>
> terra::vect("multisurface_ok.gpkg")
Error: [vect] cannot read this geometry type: Multi SurfaceSo for the issue, my guess is that we may be looking at an effect of specific geometries, rather than an overall problem. And it seems that for very large files, terra 1.8-86 may just have missed the MULTISURFACE geometries inside (?).
Session info
> sessioninfo::session_info()
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.5.2 (2025-10-31)
os Linux Mint 22.3
system x86_64, linux-gnu
ui RStudio
language nl_BE:nl
collate nl_BE.UTF-8
ctype nl_BE.UTF-8
tz Europe/Brussels
date 2026-02-17
rstudio 2026.01.0+392 Apple Blossom (desktop)
pandoc 3.6.3 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/x86_64/ (via rmarkdown)
quarto 1.8.25 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/quarto
─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────
! package * version date (UTC) lib source
P assertthat 0.2.1 2019-03-21 [?] RSPM (R 4.4.0)
P bit 4.6.0 2025-03-06 [?] RSPM (R 4.4.0)
P bit64 4.6.0-1 2025-01-16 [?] RSPM (R 4.4.0)
P bookdown 0.46 2025-12-05 [?] CRAN (R 4.5.2)
P cellranger 1.1.0 2016-07-27 [?] RSPM (R 4.4.0)
P class 7.3-23 2025-01-01 [?] RSPM (R 4.4.0)
P classInt 0.4-11 2025-01-08 [?] RSPM (R 4.4.0)
P cli 3.6.5 2025-04-23 [?] RSPM (R 4.4.0)
P codetools 0.2-20 2024-03-31 [?] RSPM (R 4.4.0)
P crayon 1.5.3 2024-06-20 [?] RSPM (R 4.4.0)
P curl 7.0.0 2025-08-19 [?] RSPM (R 4.5.0)
P DBI 1.2.3 2024-06-02 [?] RSPM (R 4.4.0)
P digest 0.6.39 2025-11-19 [?] CRAN (R 4.5.2)
P dplyr * 1.1.4 2023-11-17 [?] RSPM (R 4.4.0)
P e1071 1.7-17 2025-12-18 [?] CRAN (R 4.5.2)
P evaluate 1.0.5 2025-08-27 [?] RSPM (R 4.5.0)
P farver 2.1.2 2024-05-13 [?] RSPM (R 4.4.2)
P fastmap 1.2.0 2024-05-15 [?] RSPM (R 4.4.2)
P forcats * 1.0.1 2025-09-25 [?] RSPM (R 4.5.2)
P fs 1.6.6 2025-04-12 [?] RSPM (R 4.4.0)
P gargle 1.6.1 2026-01-29 [?] CRAN (R 4.5.2)
P generics 0.1.4 2025-05-09 [?] RSPM (R 4.5.0)
P ggplot2 * 4.0.2 2026-02-03 [?] CRAN (R 4.5.2)
P git2r 0.36.2 2025-03-29 [?] RSPM (R 4.4.0)
P git2rdata * 0.5.1 2025-12-10 [?] CRAN (R 4.5.2)
P glue 1.8.0 2024-09-30 [?] RSPM (R 4.4.2)
P googledrive * 2.1.2 2025-09-10 [?] RSPM (R 4.5.0)
P googlesheets4 * 1.1.2 2025-09-03 [?] RSPM (R 4.5.0)
P gtable 0.3.6 2024-10-25 [?] RSPM (R 4.4.0)
P hms 1.1.4 2025-10-17 [?] RSPM (R 4.5.0)
P htmltools 0.5.9 2025-12-04 [?] CRAN (R 4.5.2)
P kableExtra * 1.4.0 2024-01-24 [?] RSPM (R 4.4.0)
P KernSmooth 2.23-26 2025-01-01 [?] RSPM (R 4.4.0)
P knitr * 1.51 2025-12-20 [?] CRAN (R 4.5.2)
P lifecycle 1.0.4 2023-11-07 [?] RSPM (R 4.4.0)
P lubridate * 1.9.5 2026-02-04 [?] CRAN (R 4.5.2)
P magrittr 2.0.4 2025-09-12 [?] RSPM (R 4.5.0)
P n2khab * 0.13.0 2025-12-19 [?] https://inbo.r-universe.dev (R 4.5.2)
P n2khabmon * 0.3.1 2025-03-10 [?] https://inbo.r-universe.dev (R 4.4.3)
P otel 0.2.0 2025-08-29 [?] RSPM (R 4.5.0)
P pillar 1.11.1 2025-09-17 [?] RSPM (R 4.5.0)
P pkgconfig 2.0.3 2019-09-22 [?] RSPM (R 4.4.0)
P plyr 1.8.9 2023-10-02 [?] RSPM (R 4.4.0)
P proxy 0.4-29 2025-12-29 [?] CRAN (R 4.5.2)
P purrr * 1.2.1 2026-01-09 [?] CRAN (R 4.5.2)
P R6 2.6.1 2025-02-15 [?] RSPM (R 4.4.0)
P RColorBrewer 1.1-3 2022-04-03 [?] RSPM (R 4.4.0)
P Rcpp 1.1.1 2026-01-10 [?] CRAN (R 4.5.2)
P readr * 2.1.6 2025-11-14 [?] CRAN (R 4.5.2)
P remotes 2.5.0 2024-03-17 [?] RSPM (R 4.4.0)
renv 1.1.4 2025-03-20 [1] RSPM (R 4.4.0)
VP rlang 1.1.7 2025-04-11 [?] RSPM (R 4.4.0) (on disk 1.1.6)
P rmarkdown 2.30 2025-09-28 [?] RSPM (R 4.5.0)
P rprojroot * 2.1.1 2025-08-26 [?] RSPM (R 4.5.0)
P rstudioapi 0.18.0 2026-01-16 [?] CRAN (R 4.5.2)
P S7 0.2.1 2025-11-14 [?] CRAN (R 4.5.2)
P scales 1.4.0 2025-04-24 [?] RSPM (R 4.4.0)
P sessioninfo 1.2.3 2025-02-05 [?] RSPM (R 4.4.0)
P sf * 1.0-24 2026-01-13 [?] RSPM (R 4.5.2)
P stringi 1.8.7 2025-03-27 [?] RSPM (R 4.4.0)
P stringr * 1.6.0 2025-11-04 [?] RSPM (R 4.5.0)
P svglite 2.2.2 2025-10-21 [?] RSPM (R 4.5.1)
P systemfonts 1.3.1 2025-10-01 [?] RSPM (R 4.5.0)
P terra * 1.8-93 2026-01-12 [?] CRAN (R 4.5.2)
P textshaping 1.0.4 2025-10-10 [?] RSPM (R 4.5.0)
P tibble 3.3.0 2025-06-08 [?] RSPM (R 4.5.0)
P tidyr * 1.3.2 2025-12-19 [?] CRAN (R 4.5.2)
P tidyselect 1.2.1 2024-03-11 [?] RSPM (R 4.4.0)
P timechange 0.4.0 2026-01-29 [?] CRAN (R 4.5.2)
P tzdb 0.5.0 2025-03-15 [?] RSPM (R 4.4.0)
P units * 1.0-0 2025-10-09 [?] RSPM (R 4.5.0)
P utf8 1.2.6 2025-06-08 [?] RSPM (R 4.5.0)
P vctrs 0.6.5 2023-12-01 [?] RSPM (R 4.4.0)
P viridisLite 0.4.3 2026-02-04 [?] CRAN (R 4.5.2)
P vroom 1.7.0 2026-01-27 [?] CRAN (R 4.5.2)
P withr 3.0.2 2024-10-28 [?] RSPM (R 4.4.0)
P xfun 0.56 2026-01-18 [?] CRAN (R 4.5.2)
P xml2 1.5.2 2026-01-17 [?] CRAN (R 4.5.2)
P yaml 2.3.12 2025-12-10 [?] CRAN (R 4.5.2)
[1] /media/floris/DATA/PROJECTS/09685_NatuurlijkMilieu/160 Bewerkingen en resultaat/Repos_en_data/n2khab-mne-design_wtree_poc/100_design_common/010_prototyping_sampling_and_revisit_design/renv/library/linux-linuxmint-noble/R-4.5/x86_64-pc-linux-gnu
[2] /home/floris/.cache/R/renv/sandbox/linux-linuxmint-noble/R-4.5/x86_64-pc-linux-gnu/9a444a72
* ── Packages attached to the search path.
V ── Loaded and on-disk version mismatch.
P ── Loaded and on-disk path mismatch.
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────(Note to self: with renv active, a previous renv-cached terra version can be restored by updating renv.lock with renv::record("terra@1.8-86"); then run renv::restore(packages="terra"). Restart R as needed.)