I file contenuti in questo archivio sono derivati dai dati di OpenStreetMap e sono distribuiti sotto la Licenza Open Database 1.0. Per maggiori informazioni sul progetto, visita www.openstreetmap.org.
Questo file contiene dati di OpenStreetMap aggiornati al 2024-08-23T20:21:17Z. Ogni giorno verrà resa disponibile una nuova versione di questo file al seguente link:
http://download.geofabrik.de/europe/italy/centro-latest-free.shp.zip
Una documentazione sui livelli di questo shapefile è disponibile qui:
http://download.geofabrik.de/osm-data-in-gis-formats-free.pdf
Ci sono 17 file .shp all’interno del file zip scaricato al 27-08-2024. Ho selezionato un file che si chiama “places” e “free”, sperando che la struttura fosse adatta per esercitarmi.
The files in this archive are derived from OpenStreetMap data and are licensed under the Open Database 1.0 License. For more details, visit OpenStreetMap.
Cookbooks that helped the learning process.
Risorse che hanno supportato il processo di apprendimento.
Practical exercise using ggplot and layering data from two .shp files
designated as centro Italia. Esercizio pratico che utilizza
ggplot e sovrappone i dati di due file .shp etichettati
come “centro Italia”.
library("ggplot2")
## Warning: package 'ggplot2' was built under R version 4.3.3
theme_set(theme_bw())
library("sf")
## Warning: package 'sf' was built under R version 4.3.3
## Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
library("dplyr")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#After importing a file, use st_read to read it into R.
italy_shp <- st_read("C:\\Users\\Public\\Downloads\\centro-latest-free.shp\\gis_osm_places_free_1.shp")
## Reading layer `gis_osm_places_free_1' from data source
## `C:\Users\Public\Downloads\centro-latest-free.shp\gis_osm_places_free_1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 22941 features and 5 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 9.69903 ymin: 40.89324 xmax: 14.0258 ymax: 44.47594
## Geodetic CRS: WGS 84
‘italy_shp’ examined using a tibble and ‘italy_shp1’ reviewed with str.
Il file italy_shp viene analizzato con un tibble, mentre
italy_shp1 è esaminato utilizzando la funzione
str.
italy_shp1 <- st_read("C:\\Users\\Public\\Downloads\\centro-latest-free.shp\\gis_osm_places_a_free_1.shp")
## Reading layer `gis_osm_places_a_free_1' from data source
## `C:\Users\Public\Downloads\centro-latest-free.shp\gis_osm_places_a_free_1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 527 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 9.772597 ymin: 40.87703 xmax: 13.99135 ymax: 44.42885
## Geodetic CRS: WGS 84
str(italy_shp)
## Classes 'sf' and 'data.frame': 22941 obs. of 6 variables:
## $ osm_id : chr "31120673" "33374771" "36159460" "36159465" ...
## $ code : int 1004 1004 1050 1050 1050 1004 1004 1004 1004 1004 ...
## $ fclass : chr "hamlet" "hamlet" "locality" "locality" ...
## $ population: num 0 0 0 0 0 211 0 0 0 0 ...
## $ name : chr "Montechiaro" "Moraduccio" "Punta del Casotto" "Punta della Gallina" ...
## $ geometry :sfc_POINT of length 22941; first list element: 'XY' num 11.4 43.3
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA
## ..- attr(*, "names")= chr [1:5] "osm_id" "code" "fclass" "population" ...
str(italy_shp1)
## Classes 'sf' and 'data.frame': 527 obs. of 6 variables:
## $ osm_id : chr "24321518" "27129378" "31231951" "34019084" ...
## $ code : int 1020 1020 1020 1010 1010 1010 1010 1010 1010 1010 ...
## $ fclass : chr "island" "island" "island" "suburb" ...
## $ population: num 0 0 0 0 0 0 0 0 0 0 ...
## $ name : chr "Isola Zannone" "Isola di Pianosa" "Palmarola" "Cappuccini" ...
## $ geometry :sfc_MULTIPOLYGON of length 527; first list element: List of 1
## ..$ :List of 1
## .. ..$ : num [1:159, 1:2] 13 13 13 13 13 ...
## ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA
## ..- attr(*, "names")= chr [1:5] "osm_id" "code" "fclass" "population" ...
tibble(italy_shp)
## # A tibble: 22,941 × 6
## osm_id code fclass population name geometry
## <chr> <int> <chr> <dbl> <chr> <POINT [°]>
## 1 31120673 1004 hamlet 0 Montechiaro (11.40474 43.33198)
## 2 33374771 1004 hamlet 0 Moraduccio (11.4877 44.17534)
## 3 36159460 1050 locality 0 Punta del Casot… (10.32821 43.48488)
## 4 36159465 1050 locality 0 Punta della Gal… (10.3301 43.47412)
## 5 36159469 1050 locality 0 Punta Pacchiano (10.33704 43.46837)
## 6 37620144 1004 hamlet 211 Monte Petriolo (12.22759 43.0161)
## 7 56018975 1004 hamlet 0 Sant'Apollinare (11.5877 44.16221)
## 8 56018980 1004 hamlet 0 Misileo (11.58803 44.16046)
## 9 56018981 1004 hamlet 0 Badia di Susina… (11.57582 44.14068)
## 10 56040321 1004 hamlet 0 Coniale (11.45693 44.15242)
## # ℹ 22,931 more rows
Use ggplot give the file a geometric simple form (sf). italy_shp is plotted first then italy_shp1.
Con ggplot, visualizza i file come geometrie semplici
(sf). Prima viene creato il grafico per italy_shp, seguito
da quello per italy_shp1.
# Plot the first shapefile
ggplot(italy_shp)+
geom_sf()
# Plot the second shapefile
ggplot(italy_shp1)+
geom_sf()
### Layered Maps The following code layers both spatial plots. The
selected file, labeled as “Centro,” includes geometric points that
indicate locations considered central in Italy. Il codice sottostante
sovrappone i due grafici spaziali. Il file selezionato, contrassegnato
come “Centro,” mostra punti geometrici che rappresentano località
ritenute centrali in Italia.
# Layer both shapefiles on the same map
ggplot() +
geom_sf(data = italy_shp, fill = "transparent", color = "lightblue", size = 0.5) +
geom_sf(data = italy_shp1, fill = "transparent", color = "darkorange", size = 0.5) +
theme_minimal() +
labs(title = "Layered Spatial Plots",
subtitle = "Overlaying italy_shp and italy_shp1",
caption = "Source: Example Data") +
theme(legend.position = "bottom")