Geographic Data Science

Théo Boulakia

18 septembre 2024

Packages

library(sf)
Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
library(stars)
Le chargement a nécessité le package : abind
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Geographic Tables

Vector data model

Simple features standard

  • An open standard created by the Open Geopspatial Consortium (OGC)

  • A feature = a thing

  • Features = geometry + attributes

  • Geometries = points.

  • Points = coordinates

  • Geometry types : POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION.

Read

velibs = sf::st_read("data/velibs.geojson", quiet = TRUE)

Inspect

class(velibs)
[1] "sf"         "data.frame"
velibs
Simple feature collection with 1499 features and 2 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 2.165597 ymin: 48.76462 xmax: 2.538242 ymax: 48.95757
Geodetic CRS:  WGS 84
First 10 features:
                                      name capacity                  geometry
1                           Artois - Berri       23 POINT (2.306426 48.87394)
2             Félix Ziem - Armand Gauthier       25  POINT (2.333394 48.8895)
3                         Boudreau - Auber       14 POINT (2.329423 48.87219)
4                         Pereire - Ternes       48 POINT (2.288012 48.87974)
5               Claude Decaen - Cannebière       27 POINT (2.397254 48.83761)
6  Institut du Monde Arabe - Saint-Germain       40 POINT (2.355809 48.84906)
7        Notre-Dame-des-Champs - Stanislas       19  POINT (2.329338 48.8448)
8                  Cimetière de Montmartre       43  POINT (2.33289 48.88647)
9               Victor Hugo - Jeanne Jugan       28 POINT (2.415081 48.84395)
10                Conservatoire de Musique       25 POINT (2.403401 48.77094)

Plot

ggplot(velibs) +
  geom_sf()

sf object

namecapacitygeometry
Artois - Berri23c(2.30642583221197, 48.8739352124082)
Sénat - Condé33c(2.33793944120407, 48.8495422778846)
Chateau22c(2.3135878035462, 48.774661399959)
Cadix - Hameau37c(2.28951618075371, 48.8340107632249)
Centquatre42c(2.37078543752432, 48.8893335384554)
Mairie d'Issy41c(2.2723111510277, 48.823767792468)
Musée d'Orsay65c(2.3258604481816, 48.859726157909)
Place Violet30c(2.29057565331459, 48.844878938365)
Quai de Valmy26c(2.36818604171276, 48.8812695157943)

Feature

namecapacitygeometry
Artois - Berri23c(2.30642583221197, 48.8739352124082)
Sénat - Condé33c(2.33793944120407, 48.8495422778846)
Chateau22c(2.3135878035462, 48.774661399959)
Cadix - Hameau37c(2.28951618075371, 48.8340107632249)
Centquatre42c(2.37078543752432, 48.8893335384554)
Mairie d'Issy41c(2.2723111510277, 48.823767792468)
Musée d'Orsay65c(2.3258604481816, 48.859726157909)
Place Violet30c(2.29057565331459, 48.844878938365)
Quai de Valmy26c(2.36818604171276, 48.8812695157943)

Attributs

namecapacitygeometry
Artois - Berri23c(2.30642583221197, 48.8739352124082)
Sénat - Condé33c(2.33793944120407, 48.8495422778846)
Chateau22c(2.3135878035462, 48.774661399959)
Cadix - Hameau37c(2.28951618075371, 48.8340107632249)
Centquatre42c(2.37078543752432, 48.8893335384554)
Mairie d'Issy41c(2.2723111510277, 48.823767792468)
Musée d'Orsay65c(2.3258604481816, 48.859726157909)
Place Violet30c(2.29057565331459, 48.844878938365)
Quai de Valmy26c(2.36818604171276, 48.8812695157943)

Geometries

namecapacitygeometry
Artois - Berri23c(2.30642583221197, 48.8739352124082)
Sénat - Condé33c(2.33793944120407, 48.8495422778846)
Chateau22c(2.3135878035462, 48.774661399959)
Cadix - Hameau37c(2.28951618075371, 48.8340107632249)
Centquatre42c(2.37078543752432, 48.8893335384554)
Mairie d'Issy41c(2.2723111510277, 48.823767792468)
Musée d'Orsay65c(2.3258604481816, 48.859726157909)
Place Violet30c(2.29057565331459, 48.844878938365)
Quai de Valmy26c(2.36818604171276, 48.8812695157943)

Points

namecapacitygeometry
Artois - Berri23c(2.30642583221197, 48.8739352124082)
Sénat - Condé33c(2.33793944120407, 48.8495422778846)
Chateau22c(2.3135878035462, 48.774661399959)
Cadix - Hameau37c(2.28951618075371, 48.8340107632249)
Centquatre42c(2.37078543752432, 48.8893335384554)
Mairie d'Issy41c(2.2723111510277, 48.823767792468)
Musée d'Orsay65c(2.3258604481816, 48.859726157909)
Place Violet30c(2.29057565331459, 48.844878938365)
Quai de Valmy26c(2.36818604171276, 48.8812695157943)

Plotting vector data

La BD Topo

st_layers("data/BDT_3-4_GPKG_LAMB93_D053-ED2024-06-15.gpkg")
Driver: GPKG 
Available layers:
                        layer_name     geometry_type features fields
1                 troncon_de_route    3D Line String   196898     83
2        route_numerotee_ou_nommee Multi Line String      767     12
3                 itineraire_autre Multi Line String       15      9
4           troncon_de_voie_ferree    3D Line String      539     21
5          equipement_de_transport  3D Multi Polygon     1040     20
6                piste_d_aerodrome  3D Multi Polygon       13     14
7                        aerodrome     Multi Polygon        6     19
8                  point_de_repere             Point     7695     19
9                non_communication             Point       83      7
10                 point_du_reseau          3D Point     2671     17
11              voie_ferree_nommee Multi Line String        2      9
12             toponymie_transport             Point      535      8
13                        batiment  3D Multi Polygon   481047     28
14                       cimetiere  3D Multi Polygon      444     17
15           construction_lineaire    3D Line String     6858     17
16         construction_ponctuelle          3D Point     6104     18
17         construction_surfacique  3D Multi Polygon      122     17
18                       reservoir  3D Multi Polygon      731     20
19              ligne_orographique    3D Line String    13503     15
20                          pylone          3D Point     2104     13
21                terrain_de_sport  3D Multi Polygon     1241     14
22                  toponymie_bati             Point      113      8
23                     cours_d_eau Multi Line String     2832     15
24          troncon_hydrographique    3D Line String    48408     40
25    bassin_versant_topographique     Multi Polygon       99     20
26                      plan_d_eau     Multi Polygon      384     22
27          surface_hydrographique  3D Multi Polygon    24544     29
28            noeud_hydrographique          3D Point     2839     22
29           detail_hydrographique             Point      544     17
30          toponymie_hydrographie             Point     1225      8
31               zone_d_habitation     Multi Polygon    34831     17
32             lieu_dit_non_habite             Point      801     14
33             detail_orographique             Point       74     15
34          toponymie_lieux_nommes             Point    38769      8
35                    canalisation    3D Line String      107     14
36                ligne_electrique    3D Line String      109     13
37         poste_de_transformation  3D Multi Polygon       35     15
38                             erp             Point     7621     34
39    zone_d_activite_ou_d_interet     Multi Polygon     5068     19
40 toponymie_services_et_activites             Point     2895      8
41                     voie_nommee Multi Line String    32628     16
42                 parc_ou_reserve     Multi Polygon       27     15
43                  foret_publique     Multi Polygon       23     13
44    toponymie_zones_reglementees             Point       51      8
45                            haie       Line String   595670     11
46              zone_de_vegetation     Multi Polygon   326671     10
47                  arrondissement     Multi Polygon       12     10
48    commune_associee_ou_deleguee     Multi Polygon       94     14
49                         commune     Multi Polygon      379     25
50                            epci     Multi Polygon       26      9
51       collectivite_territoriale     Multi Polygon        7     10
52                     departement     Multi Polygon        7     10
53                          region     Multi Polygon        3      9
54                     adresse_ban             Point   223365     20
55        batiment_rnb_lien_bdtopo             Point   481643      5
56        lien_adresse_vers_bdtopo       Line String   221568     15
57     section_de_points_de_repere       Line String     1234     11
58                info_metadonnees                NA        1      6
59                 metadonnees_lot                NA        1     31
60               metadonnees_theme                NA        9      3
61                    layer_styles                NA       64     12
                crs_name
1  RGF93 v1 / Lambert-93
2  RGF93 v1 / Lambert-93
3  RGF93 v1 / Lambert-93
4  RGF93 v1 / Lambert-93
5  RGF93 v1 / Lambert-93
6  RGF93 v1 / Lambert-93
7  RGF93 v1 / Lambert-93
8  RGF93 v1 / Lambert-93
9  RGF93 v1 / Lambert-93
10 RGF93 v1 / Lambert-93
11 RGF93 v1 / Lambert-93
12 RGF93 v1 / Lambert-93
13 RGF93 v1 / Lambert-93
14 RGF93 v1 / Lambert-93
15 RGF93 v1 / Lambert-93
16 RGF93 v1 / Lambert-93
17 RGF93 v1 / Lambert-93
18 RGF93 v1 / Lambert-93
19 RGF93 v1 / Lambert-93
20 RGF93 v1 / Lambert-93
21 RGF93 v1 / Lambert-93
22 RGF93 v1 / Lambert-93
23 RGF93 v1 / Lambert-93
24 RGF93 v1 / Lambert-93
25 RGF93 v1 / Lambert-93
26 RGF93 v1 / Lambert-93
27 RGF93 v1 / Lambert-93
28 RGF93 v1 / Lambert-93
29 RGF93 v1 / Lambert-93
30 RGF93 v1 / Lambert-93
31 RGF93 v1 / Lambert-93
32 RGF93 v1 / Lambert-93
33 RGF93 v1 / Lambert-93
34 RGF93 v1 / Lambert-93
35 RGF93 v1 / Lambert-93
36 RGF93 v1 / Lambert-93
37 RGF93 v1 / Lambert-93
38 RGF93 v1 / Lambert-93
39 RGF93 v1 / Lambert-93
40 RGF93 v1 / Lambert-93
41 RGF93 v1 / Lambert-93
42 RGF93 v1 / Lambert-93
43 RGF93 v1 / Lambert-93
44 RGF93 v1 / Lambert-93
45 RGF93 v1 / Lambert-93
46 RGF93 v1 / Lambert-93
47 RGF93 v1 / Lambert-93
48 RGF93 v1 / Lambert-93
49 RGF93 v1 / Lambert-93
50 RGF93 v1 / Lambert-93
51 RGF93 v1 / Lambert-93
52 RGF93 v1 / Lambert-93
53 RGF93 v1 / Lambert-93
54 RGF93 v1 / Lambert-93
55 RGF93 v1 / Lambert-93
56 RGF93 v1 / Lambert-93
57 RGF93 v1 / Lambert-93
58                  <NA>
59                  <NA>
60                  <NA>
61                  <NA>

Cours d’eau

cours_d_eau = st_read("data/BDT_3-4_GPKG_LAMB93_D053-ED2024-06-15.gpkg",
                      layer = "cours_d_eau")
Reading layer `cours_d_eau' from data source 
  `/home/theo/enquetes-quantitatives/data/BDT_3-4_GPKG_LAMB93_D053-ED2024-06-15.gpkg' 
  using driver `GPKG'
Simple feature collection with 2832 features and 15 fields
Geometry type: MULTILINESTRING
Dimension:     XY
Bounding box:  xmin: 295216.4 ymin: 6716245 xmax: 517921.6 ymax: 6854598
Projected CRS: RGF93 v1 / Lambert-93

Forêts publiques

foret_publique = st_read(dsn = "data/BDT_3-4_GPKG_LAMB93_D053-ED2024-06-15.gpkg",
                         layer = "foret_publique")
Reading layer `foret_publique' from data source 
  `/home/theo/enquetes-quantitatives/data/BDT_3-4_GPKG_LAMB93_D053-ED2024-06-15.gpkg' 
  using driver `GPKG'
Simple feature collection with 23 features and 13 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 389284 ymin: 6742285 xmax: 489008.5 ymax: 6843152
Projected CRS: RGF93 v1 / Lambert-93

Pylônes

pylone = st_read(dsn = "data/BDT_3-4_GPKG_LAMB93_D053-ED2024-06-15.gpkg",
                 layer = "pylone")
Reading layer `pylone' from data source 
  `/home/theo/enquetes-quantitatives/data/BDT_3-4_GPKG_LAMB93_D053-ED2024-06-15.gpkg' 
  using driver `GPKG'
Simple feature collection with 2104 features and 13 fields
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 381627.9 ymin: 6738667 xmax: 479014.9 ymax: 6835443
z_range:       zmin: 43 zmax: 314.4
Projected CRS: RGF93 v1 / Lambert-93

Carte des cours d’eau

ggplot() +
  geom_sf(data = cours_d_eau, color = "blue")

Ajouter les forêts publiques

ggplot() +
  geom_sf(data = cours_d_eau, color = "blue") +
  geom_sf(data = foret_publique, fill = "darkgreen")

Ajouter les pylônes

ggplot() +
  geom_sf(data = cours_d_eau, color = "blue") +
  geom_sf(data = foret_publique, fill = "darkgreen") +
  geom_sf(data = pylone, color = "brown")

Surfaces

Raster data model

Résolution

Lumières nocturnes

Relief

fs::file_size("data/GRAY_HR_SR.tif")
223M
relief = read_stars("data/GRAY_HR_SR.tif", proxy = TRUE)

Plotting rasters

ggplot() +
  geom_stars(data = relief, downsample = 6) +
  theme_void()

Coordinate Reference Systems

Géoïdes

Ellipsoïdes

Familles de projections

CRS with R

Country borders

Simple feature collection with 257 features and 1 field
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -180 ymin: -89.9 xmax: 180 ymax: 83.65187
Geodetic CRS:  WGS 84
First 10 features:
                      CNTR_NAME                       geometry
1      الإمارات العربية المتحدة MULTIPOLYGON (((56.35462 25...
2           افغانستان-افغانستان MULTIPOLYGON (((74.7055 37....
3           Antigua and Barbuda MULTIPOLYGON (((-61.80237 1...
4                      Anguilla MULTIPOLYGON (((-63.05444 1...
5                     Shqipëria MULTIPOLYGON (((19.831 42.4...
6                      Հայաստան MULTIPOLYGON (((46.45984 39...
7                        Angola MULTIPOLYGON (((23.83831 -1...
8                     Argentina MULTIPOLYGON (((-62.87957 -...
9  American Samoa-Sāmoa Amelika MULTIPOLYGON (((-169.3966 -...
10                   Österreich MULTIPOLYGON (((16.88365 48...

Querying a CRS

st_crs(countries)
Coordinate Reference System:
  User input: EPSG:4326 
  wkt:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    USAGE[
        SCOPE["unknown"],
        AREA["World"],
        BBOX[-90,-180,90,180]],
    ID["EPSG",4326]]

Spécifier un CRS

EPSG or ESRI codes

st_transform(countries, crs = "ESRI:54012")

PROJ4 string

st_transform(countries, crs = "+proj=laea +lon_0=100 +lat_0=45")

Sites utiles

WGS84

Code
ggplot(countries) +
  geom_sf(fill = "black") +
  theme_bw()

Robinson

Code
st_transform(countries, "ESRI:54030") |> 
  ggplot() +
  geom_sf(fill = "black") +
  theme_bw()

Eckert 4

Code
st_transform(countries, "+proj=eck4") |> 
  ggplot() +
  geom_sf(fill = "black") +
  theme_bw()

Bonne

Code
st_transform(countries, "+proj=bonne +lat_1=10") |> 
  ggplot() +
  geom_sf(fill = "black") +
  theme_bw()

Lambert azimuthal equal-area

Code
st_transform(countries, "+proj=laea") |> 
  ggplot() +
  geom_sf(fill = "black") +
  theme_bw()

LAEA Asie

Code
st_transform(countries, "+proj=laea +lon_0=100 +lat_0=45") |> 
  ggplot() +
  geom_sf(fill = "black") +
  theme_bw()

LAEA Amérique du Nord

Code
st_transform(countries, "+proj=laea +lon_0=-95 +lat_0=45") |> 
  ggplot() +
  geom_sf(fill = "black") +
  theme_bw()

LAEA Amérique du Sud

Code
st_transform(countries, "+proj=laea +lon_0=-61 +lat_0=-21") |> 
  ggplot() +
  geom_sf(fill = "black") +
  theme_bw()

LAEA Afrique

Code
st_transform(countries, "+proj=laea +lon_0=18 +lat_0=0") |> 
  ggplot() +
  geom_sf(fill = "black") +
  theme_bw()

CRS usuels

  • Monde : Eckert 4 : ESRI:54012 ou +proj=eck4

  • Europe : European Centric Lambert azimuthal equal-area : EPSG:3035

  • France : RGF93 / Lambert-93 : EPSG-2154