# Lade Pakete library(sf) library(terra) library(dplyr) library(ggplot2) # Koordinaten aus OSM Standort <- data.frame(x = 50.671858, y = 7.184699, Anmerkung = " Wir sind hier!") # Als räumliches Objekt Standort <- st_as_sf(Standort, coords = c("x", "y"), crs = 4326) # Alles zusammen Standort <- data.frame(y = 50.671858, x = 7.184699, Anmerkung = " Wir sind hier!") %>% st_as_sf(coords = c("x", "y"), crs = 4326) # Lade Daten aus Natural Earth ----------------------------------------------------------- library(rnaturalearth) DE <- ne_countries(scale = "large", country = "Germany", returnclass = "sf") # Plot ggplot() + geom_sf(data = DE) + geom_sf(data = Standort) + geom_sf_text(data = Standort, aes(label = Anmerkung), nudge_x = 1.2) # Bundeslaender Bundeslaender <- ne_states(country = "Germany", returnclass = "sf") # Plot ggplot() + geom_sf(data = Bundeslaender) + geom_sf(data = Standort) + geom_sf_text(data = Standort, aes(label = Anmerkung), nudge_x = 1.2) # Lade Daten aus OSM --------------------------------------------------------------------- library(osmdata) # Umkreis für die Abfrage Umkreis <- st_buffer(Standort, 10000) ggplot() + geom_sf(data = Umkreis) Strassen <- opq(bbox = st_bbox(Umkreis)) %>% add_osm_feature(key = "highway") %>% osmdata_sf() Strassen <- Strassen$osm_lines # Plot ggplot() + geom_sf(data = Strassen, aes(color = highway)) # Eines genaueren Objektes BBSR <- opq_osm_id(id = 45973002, type = "way") %>% opq_string() %>% osmdata_sf() BBSR <- BBSR$osm_polygons ggplot() + geom_sf(data = BBSR)+ geom_sf(data = Standort) + geom_sf_text(data = Standort, aes(label = Anmerkung), nudge_x = -0.00025) # Lade DEMs mit elevatr ------------------------------------------------------------------ library(elevatr) Umkreis_poly <- st_bbox(Umkreis) %>% st_as_sfc(crs = st_crs(Umkreis)) %>% st_as_sf() DEM <- get_elev_raster(locations = Umkreis_poly, z = 9, clip = "locations") DEM <- rast(DEM) # Plot raster library(tidyterra) ggplot() + geom_spatraster(data = DEM) # Eine interaktive Karte mikt leaflet ---------------------------------------------------- library(leaflet) leaflet() %>% addTiles() %>% addCircleMarkers(data = Standort) # Simpler code for better output library(mapview) mapview(Standort)