Ejercicio N°1:

Creamos el objeto ‘MAPS’ para facilitar el codeo:

MAPS = "C:/Users/LENOVO/OneDrive/Documentos/ASIE/introgeodf/maps/worldMap.gpkg"

Aquí se pasa a la revisión de las características de cada uno de los layers:

sf::st_layers(MAPS) # a link to github data
## Driver: GPKG 
## Available layers:
##       layer_name geometry_type features fields crs_name
## 1 countryBorders                    252      1   WGS 84
## 2     riverLines                     98      2   WGS 84
## 3     cityPoints         Point      610      3   WGS 84

Pasamos a configurar los datos para la visualización gráfica:

library(sf)
## Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
countries=read_sf(MAPS,layer="countryBorders")
rivers=read_sf(MAPS,layer="riverLines")
cities=read_sf(MAPS,layer="cityPoints")
library(ggplot2)

Visualización gráfica:

baseLayer=ggplot(data=countries)  + geom_sf(fill='ivory') + theme_light()
final=baseLayer + geom_sf(data=rivers, color='blue') + geom_sf(data=cities, color='lightgreen') 
final

Ejercicio N°2

Establecemos los objetos correspodientes a Perú:

peru <- countries[countries$COUNTRY == 'Peru', ]
peru_rivers <- rivers[rivers$SYSTEM == 'Peru', ]
peru_cities <- cities [cities$COUNTRY == 'Peru', ]

Realizamos la intersección entre los objetos “rivers” y “peru”:

peru_rivers_clipped <- st_intersection(rivers, peru)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries

Realizamos el plotting:

baseLayer=ggplot(data=peru)  + geom_sf(fill='ivory') + theme_light()
final=baseLayer + geom_sf(data=peru_rivers_clipped, color='blue') + geom_sf(data=peru_cities, color='red') 
final

Ejercicio N°3:

Descargamos los archivos correspondientes:

library(rio)
data_peruair = "C:/Users/LENOVO/OneDrive/Documentos/ASIE/introgeodf/data/pe-airports.xlsx"
peruair_pre = "C:/Users/LENOVO/OneDrive/Documentos/ASIE/introgeodf/maps/peruair_4326.shp"
peruoair_final =st_read(peruair_pre)
## Reading layer `peruair_4326' from data source 
##   `C:\Users\LENOVO\OneDrive\Documentos\ASIE\introgeodf\maps\peruair_4326.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 203 features and 7 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: -81.27556 ymin: -18.0533 xmax: -68.99421 ymax: -0.119056
## Geodetic CRS:  WGS 84

Creamos la intersección entre nuestros objetos:

peruair_f2 <- st_intersection(peruoair_final, peru)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries

Realizamos el plotting:

baseLayer=ggplot(data=peru)  + geom_sf(fill='ivory') + theme_light()
final=baseLayer + geom_sf(data=peru_rivers_clipped, color='blue') + geom_sf(data=peruair_f2, color='black') + geom_sf(data=peru_cities, color='red') + 
  coord_sf(datum = st_crs(peru))
final