Géotéca - Paris - 2021/05/20

Le package sf

sf gif
Une interface entre R et plusieurs librairies géographiques :

  • GDAL, Geospatial Data Abstraction Library

  • PROJ4, Coordinate Transformation Software

  • GEOS, Geometry Engine - Open Source

Format des objets spatiaux sf

format 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)