投影问题指向多方数据sf对象

问题描述 投票:0回答:1

我正在尝试在多重聚合物地图上绘制点数据(coördinates)。但是我无法将它们放在彼此之上并且形状正确。

荷兰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

来自荷兰的Downloadlink to a .zip with 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"
))

代码我用来在具有相同crs多面数据的sf对象中对x和ycoördinates进行整形。

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)

multipolygon Point data enter image description here

r sf map-projections
1个回答
1
投票

使用样本数据中的df

points <- st_as_sf( df,
                    coords = c("lat", "lon"),
                    crs = 4326 )

nl <- st_read( "./2019_landsgrens_kustlijn.gpkg")

library(ggplot2)
ggplot() +
  geom_sf(data = nl) +
  geom_sf(data = points)

enter image description here

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.