R 空间:具有相同 CRS 的 2 个形状文件之间的纬度/经度不匹配

R Spatial: Mismatch of latitude / longitude between 2 shapefiles with same CRS

我的目标是计算非洲国家以下地区极端天气事件的频率。为此,我设置了一个包含非洲省份的 shapefile,主要使用 GADM data and the new geocoded EMDAT GDIS dataset 作为天气事件的点数据。

这是区域形状文件的样子:

    library(sf)

    st_geometry(africa_map)
    Geometry set for 796 features 
    Geometry type: GEOMETRY
    Dimension:     XY
    Bounding box:  xmin: -25.36042 ymin: -46.96575 xmax: 63.49391 ymax: 37.3452
    Geodetic CRS:  WGS 84
    First 5 geometries:
    MULTIPOLYGON (((-4.821226 24.99475, -4.821355 2...
    MULTIPOLYGON (((1.853562 35.8605, 1.8424 35.865...
    MULTIPOLYGON (((-1.361976 35.3199, -1.358957 35...
    MULTIPOLYGON (((2.984874 36.81497, 3.014171 36....
    MULTIPOLYGON (((7.262677 37.076, 7.266449 37.07..

以及将经纬度转换为WGS 84后的GDIS数据集:

    gdis_africa_sf <- st_as_sf(x = gdis_africa, 
                    coords = c("longitude", "latitude"),
                    crs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")

    st_geometry(gdis_africa_sf)
    Geometry set for 5171 features 
    Geometry type: POINT
    Dimension:     XY
    Bounding box:  xmin: -34.04233 ymin: -25.19619 xmax: 37.08849 ymax: 63.4228
    CRS:           +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
    First 5 geometries:
    POINT (-17.09348 15.66576)
    POINT (-16.53153 15.77399)
    POINT (-16.20006 15.84419)
    POINT (-17.09348 15.66576)
    POINT (-16.53153 15.77399)

到现在为止,您已经可以看出有什么地方不对劲了,因为边界框根本不对应,即使投影看起来很合适。

    st_crs(africa_map)==st_crs(gdis_africa_sf)
[1] TRUE

将两者并排绘制时,无论我使用新的 shapefile 还是仅应用数据框的经度和纬度,问题都会变得更加清晰。

    ggplot() +
      geom_sf(data = africa_map) +
      geom_sf(data = gdis_africa_sf)

Plot 1

    ggplot(data = africa_map) +
      geom_sf() +
      geom_point(data = gdis_africa, aes(x = longitude, y = latitude),
                 color = "red",
                 alpha = 0.3,
                 size = 2, 
                 shape = 1) 

Plot 2

天气事件坐标似乎向西北方向偏移了数千公里 - 但来源是什么?我该如何解决这个问题并使我的两个地理数据兼容?任何提示将不胜感激。

看来你误诊了问题,这不是翻译,而是对角线的反映 - 你在你的站点点交换了纬度和经度。尝试:

 gdis_africa_sf <- st_as_sf(x = gdis_africa, 
                    coords = c("latitude", "longitude"),
                    crs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")