Skip to contents

These functions return information about WKB/WKT geometries. The input geometries may be given as a single raw vector of WKB, a list of WKB raw vectors, or a character vector containing one or more WKT strings.

Usage

g_name(geom, quiet = FALSE)

g_summary(geom, quiet = FALSE)

g_is_empty(geom, quiet = FALSE)

g_is_valid(geom, quiet = FALSE)

Arguments

geom

Either a raw vector of WKB or list of raw vectors, or a character vector containing one or more WKT strings.

quiet

Logical, TRUE to suppress warnings. Defaults to FALSE.

Details

g_is_empty() tests whether a geometry has no points. Returns a logical vector of the same length as the number of input geometries containing TRUE for the corresponding geometries that are empty or FALSE for non-empty geometries.

g_is_valid() tests whether a geometry is valid. Returns a logical vector of the same length as the number of input geometries containing TRUE for the corresponding geometries that are valid or FALSE for invalid geometries.

g_name() returns geometry type names in a character vector of the same length as the number of input geometries.

g_summary() returns text summaries of WKB/WKT geometries in a character vector of the same length as the number of input geometries. Requires GDAL >= 3.7.

Examples

g1 <- "POLYGON ((0 0, 10 10, 10 0, 0 0))"
g2 <- "POLYGON ((5 1, 9 5, 9 1, 5 1))"
g_difference(g2, g1) |> g_is_empty()
#> [1] TRUE

g1 <- "POLYGON ((0 0, 10 10, 10 0, 0 0))"
g2 <- "POLYGON ((0 0, 10 10, 10 0))"
g3 <- "POLYGON ((0 0, 10 10, 10 0, 0 1))"
g_is_valid(c(g1, g2, g3))
#> [1]  TRUE FALSE FALSE

f <- system.file("extdata/ynp_fires_1984_2022.gpkg", package = "gdalraster")
lyr <- new(GDALVector, f, "mtbs_perims")

feat <- lyr$getNextFeature()
g_name(feat$geom)
#> [1] "MULTIPOLYGON"

# g_summary() requires GDAL >= 3.7
if (as.integer(gdal_version()[2]) >= 3070000) {
  feat <- lyr$getNextFeature()
  g_summary(feat$geom) |> print()

  feat_set <- lyr$fetch(5)
  g_summary(feat_set$geom) |> print()
}
#> [1] "MULTIPOLYGON : 3 geometries: POLYGON : 410 points POLYGON : 4 points POLYGON : 8 points"
#> [1] "MULTIPOLYGON : 1 geometries: POLYGON : 302 points"                                                           
#> [2] "MULTIPOLYGON : 1 geometries: POLYGON : 277 points"                                                           
#> [3] "MULTIPOLYGON : 2 geometries: POLYGON : 54 points POLYGON : 7 points"                                         
#> [4] "MULTIPOLYGON : 1 geometries: POLYGON : 159 points"                                                           
#> [5] "MULTIPOLYGON : 4 geometries: POLYGON : 1376 points POLYGON : 17 points POLYGON : 5 points POLYGON : 9 points"

lyr$close()