Я пытаюсь нанести точечные данные (координаты) на многоплановую карту.Но я не могу получить их друг на друга и в правильной форме.
Основные данные прогноза Нидерландов multipolygon
данные:
Simple feature collection with 1 feature and 3 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: 13565.4 ymin: 306846.2 xmax: 278026.1 ymax: 619232.6
epsg (SRID): 28992
proj4string: +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.4171,50.3319,465.5524,-0.398957,0.343988,-1.87740,4.0725 +units=m +no_defs
Ссылка для скачивания на.zip
с 4 Geopackage файлами из Нидерландов
Базовые point
данные проекции координат:
Simple feature collection with 1466 features and 4 fields
geometry type: POINT
dimension: XY
bbox: xmin: 3.389737 ymin: 50.77106 xmax: 7.187327 ymax: 53.44402
epsg (SRID): 28992
proj4string: +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.4171,50.3319,465.5524,-0.398957,0.343988,-1.87740,4.0725 +units=m +no_defs
несколько строк df
фрейм данных:
df <- structure(list(brouwerijnaam = c("Almelosche", "HertogJan", "HertogJan",
"Bavaria", "Bavaria", "Brand"), begin_datum_jaar = c(1987, 1981,
1981, 1719, 1719, 1340), eind_datum_jaar = c(1990, 0, 0, 0, 0,
0), plaats = c("Almelo", "Arcen", "Arcen", "Lieshout", "Lieshout",
"Wijlre"), lon = c(52.35192, 51.473427, 51.473427, 51.518607,
51.518607, 50.832695), lat = c(6.660562, 6.181219, 6.181219,
5.597416, 5.597416, 5.895593)), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
некоторые строки points
фрейма данных:
points <- structure(list(brouwerijnaam = c("Almelosche", "HertogJan", "HertogJan",
"Bavaria", "Bavaria", "Brand"), begin_datum_jaar = c(1987, 1981,
1981, 1719, 1719, 1340), eind_datum_jaar = c(1990, 0, 0, 0, 0,
0), plaats = c("Almelo", "Arcen", "Arcen", "Lieshout", "Lieshout",
"Wijlre"), geometry = structure(list(structure(c(52.35192, 6.660562
), class = c("XY", "POINT", "sfg")), structure(c(51.473427, 6.181219
), class = c("XY", "POINT", "sfg")), structure(c(51.473427, 6.181219
), class = c("XY", "POINT", "sfg")), structure(c(51.518607, 5.597416
), class = c("XY", "POINT", "sfg")), structure(c(51.518607, 5.597416
), class = c("XY", "POINT", "sfg")), structure(c(50.832695, 5.895593
), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT",
"sfc"), precision = 0, bbox = structure(c(xmin = 50.832695, ymin = 5.597416,
xmax = 52.35192, ymax = 6.660562), class = "bbox"), crs = structure(list(
epsg = NA_integer_, proj4string = NA_character_), class = "crs"), n_empty = 0L)), row.names = c(NA,
-6L), sf_column = "geometry", agr = structure(c(brouwerijnaam = NA_integer_,
begin_datum_jaar = NA_integer_, eind_datum_jaar = NA_integer_,
plaats = NA_integer_), .Label = c("constant", "aggregate", "identity"
), class = "factor"), class = c("sf", "tbl_df", "tbl", "data.frame"
))
Код, который я использовал для формирования координат x и y в sf-объекте с теми же crs мультиполигональных данных.
library(sf)
library(tidyverse)
points <- df %>%
filter(!is.na(lon)) %>%
st_as_sf(coords = c("lat", "lon"))
points <- st_set_crs(brouwerijen_sf, 28992)
ggplot() +
geom_sf(data = multipolygon) +
geom_sf(data = points) +
coord_sf(datum = NA)