if (FALSE) {
library(sf)
# Load a geometry
x <- read_sf(system.file("extdata/penmarch.shp", package = "happign"))
# Retrieve commune boundaries intersecting x
commune <- get_wfs(
x = x,
layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune"
)
plot(st_geometry(commune), border = "firebrick")
# Attribute-only query (no spatial filter)
# If unknown, available attributes can be retrieved using `get_wfs_attributes()`
attrs <- get_wfs_attributes("LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune")
print(attrs)
plou_communes <- get_wfs(
x = NULL,
layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune",
query = "nom_officiel ILIKE 'PLOU%'"
)
plot(st_geometry(plou_communes))
# Multiple Attribute-only query (no spatial filter)
plou_inf_2000 <- get_wfs(
x = NULL,
layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune",
query = "nom_officiel ILIKE 'PLOU%' AND population < 2000"
)
plot(st_geometry(plou_communes))
plot(st_geometry(plou_inf_2000), col = "firebrick", add = TRUE)
# Spatial predicate usage
layer <- "BDCARTO_V5:rond_point"
bbox_feat <- get_wfs(commune, layer, predicate = bbox())
plot(st_geometry(bbox_feat), col = "red")
plot(st_geometry(commune), add = TRUE)
intersects_feat <- get_wfs(commune, layer, predicate = intersects())
plot(st_geometry(intersects_feat), col = "red")
plot(st_geometry(commune), add = TRUE)
dwithin_feat <- get_wfs(commune, layer, predicate = dwithin(5, "kilometers"))
plot(st_geometry(dwithin_feat), col = "red")
plot(st_geometry(commune), add = TRUE)
}
Run the code above in your browser using DataLab