Géotéca - Paris - 2021/05/20
sf
Une interface entre R et plusieurs librairies géographiques :
Format des objets spatiaux sf
Import de données
library(sf)
## Linking to GEOS 3.7.1, GDAL 3.1.2, PROJ 7.1.0
mtq <- st_read("data/martinique.shp")
## Reading layer `martinique' from data source `/home/tim/Documents/prz/geoteca_mapsf/data/martinique.shp' using driver `ESRI Shapefile' ## Simple feature collection with 34 features and 23 fields ## Geometry type: POLYGON ## Dimension: XY ## Bounding box: xmin: 690574.4 ymin: 1592426 xmax: 736126.5 ymax: 1645660 ## Projected CRS: WGS 84 / UTM zone 20N
Affichage de données
plot(st_geometry(mtq))
Extraire les centroïdes
mtq_c <- st_centroid(mtq)
## Warning in st_centroid.sf(mtq): st_centroid assumes attributes are constant over ## geometries of x
plot(st_geometry(mtq)) plot(st_geometry(mtq_c), add=TRUE, cex=1.2, col="red", pch=20)
Construire une matrice de distances
mat <- st_distance(x=mtq_c,y=mtq_c) mat[1:5,1:5]
## Units: [m] ## [,1] [,2] [,3] [,4] [,5] ## [1,] 0.000 35297.56 3091.501 12131.617 17136.310 ## [2,] 35297.557 0.00 38332.602 25518.913 18605.249 ## [3,] 3091.501 38332.60 0.000 15094.702 20226.198 ## [4,] 12131.617 25518.91 15094.702 0.000 7177.011 ## [5,] 17136.310 18605.25 20226.198 7177.011 0.000
Agréger des polygones
mtq_u <- st_union(mtq) plot(st_geometry(mtq), col="lightblue") plot(st_geometry(mtq_u), add=T, lwd=2, border = "red")
Construire une zone tampon
mtq_b <- st_buffer(x = mtq_u, dist = 5000) plot(st_geometry(mtq), col="lightblue") plot(st_geometry(mtq_u), add=T, lwd=2) plot(st_geometry(mtq_b), add=T, lwd=2, border = "red")
Réaliser une intersection
m <- rbind(c(700015,1624212), c(700015,1641586), c(719127,1641586), c(719127,1624212), c(700015,1624212)) p <- st_sf(st_sfc(st_polygon(list(m))), crs = st_crs(mtq)) plot(st_geometry(mtq)) plot(p, border="red", lwd=2, add=T)
Réaliser une intersection
mtq_z <- st_intersection(x = mtq, y = p) plot(st_geometry(mtq)) plot(st_geometry(mtq_z), col="red", border="green", add=T)
Construire des polygones de Voronoi
mtq_v <- st_voronoi(x = st_union(mtq_c)) mtq_v <- st_intersection(st_cast(mtq_v), st_union(mtq)) mtq_v <- st_join(x = st_sf(mtq_v), y = mtq_c, join=st_intersects) mtq_v <- st_cast(mtq_v, "MULTIPOLYGON") plot(st_geometry(mtq_v), col='lightblue')
mapsf
La fonction mf_map()
est la fonction principale du package :
mf_map(x = objet_sf, var = "variable", type = "type de carte", ...)
mf_map()
mf_title() mf_arrow() mf_credits() mf_scale() mf_layout() mf_annotation() mf_label() mf_shadow()
riatelab.github.io/mapsf/
github.com/rCarto/geoteca_mapsf
github.com/riatelab/mapsf
@rgeomatic
rgeomatic.hypotheses.org