微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何匹配这个 df/sp 对象的坐标UTM 和几何?

如何解决如何匹配这个 df/sp 对象的坐标UTM 和几何?

如果你能帮我解决这个问题,我会很高兴。我想将 df "daa_84" geom_point 放入 shp 文件 "shp_5"。在stackoverflow上查看了多个相关问题并测试了他们的答案(如从“daa_84”创建一个sp对象并转换UTM坐标以使其与“shp_5”的坐标匹配)后,我只得到了类似情节的东西。另外,我知道“东西”需要UTM区(19S)和与我的国家(32719)相关的坐标系统(wgs84)的epsg代码,哈哈。有什么想法吗?

> head(daa_84)
            # A tibble: 6 x 2
              utm_este utm_norte
                 <dbl>     <dbl>
            1   201787   6364077
            2   244958   6247258
            3   245947   6246281
            4   246100   6247804
            5   246358   6242918
            6   246470   6332356
            
    
    > head(shp_5)
            Simple feature collection with 6 features and 1 field
            geometry type:  MULTIpolyGON
            dimension:      XY
            bBox:           xmin: -7973587 ymin: -3976507 xmax: -7838155 ymax: -3766040
            projected CRS:  WGS 84 / Pseudo-Mercator
                 Comuna                       geometry
            1 Rinconada MULTIpolyGON (((-7871440 -3...
            2   Cabildo MULTIpolyGON (((-7842610 -3...
            3   Petorca MULTIpolyGON (((-7873622 -3...
            4 Panquehue MULTIpolyGON (((-7874932 -3...
            5     Olmué MULTIpolyGON (((-7916865 -3...
            6 Cartagena MULTIpolyGON (((-7973501 -3...
            
        
        ggplot() + geom_sf(data = shp_5,aes()) + 
              geom_point(data = daa_84,aes(x= "utm_este","utm_norte"),alpha = 0.05,size = 0.5) + 
              labs(x = "Latitude",y = "Longitude")+
              theme_bw()

my progress so far

编辑

除了william3031的答案,这段代码也有效

library(sf)
daa_84 = tribble(~utm_este,~utm_norte,201787,6364077,244958,6247258,245947,6246281,246100,6247804,246358,6242918,246470,6332356)


daa_84 = st_as_sf(daa_84,coords=c('utm_este','utm_norte'),crs=st_crs(32719)) %>% 
      st_transform(st_crs(shp_5))

解决方法

这对你有用。我为南美洲使用了不同的数据集,因为您没有提供 reproducible example

library(tidyverse)
library(sf)
library(spData) # just for the 'world' dataset

# original
daa_84 <- data.frame(
  utm_este = c(201787L,244958L,245947L,246100L,246358L,246470L),utm_norte = c(6364077L,6247258L,6246281L,6247804L,6242918L,6332356L)
)

# converted
daa_84_sf <- st_as_sf(daa_84,coords = c("utm_este","utm_norte"),crs = 32719)


# load world to get South America
data("world")
sam <- world %>% 
  filter(continent == "South America")

# plot
ggplot() +
  geom_sf(data = sam) + 
  geom_sf(data = daa_84_sf)

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。