【问题标题】:out of bounds latitude and longitude values in converted shape file using ggplot使用ggplot转换的形状文件中的纬度和经度值越界
【发布时间】:2019-09-30 16:41:39
【问题描述】:

我正在尝试使用来自PA Geospatial Data Clearinghouse 的数据绘制 Pennyslvania 县的地图。我读入了 shape 文件,然后将其转换为如下数据框:

setwd(proj_path)
dsn <- "Data/PaCounty2019_07/PaCounty2019_07.shp"
map <- readOGR(dsn)
map_df <- tidy(map)

然后我像这样绘制它:

ggplot() +
geom_path(data = map_df, aes(x = long, y = lat, group = group)) +
labs(title = "ggplot map of pa counties")

这可行,但纬度/经度比例非常奇怪。纬度从 -100,000 到 150,000,经度从 -2e+05 到 23+05。如果我尝试在地图上绘制任何点,它们看起来都在 [0,0],因为这些点的纬度和经度值当然都是 Image of PA map with weird scale here

为什么比例会如此扭曲?我该如何解决?

【问题讨论】:

    标签: r ggplot2 latitude-longitude


    【解决方案1】:

    您需要将 shapefile 转换为正常的纬度/经度投影。在定义map_df之前执行此操作...

    map <- spTransform(map, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))
    

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 2022-10-14
      • 2012-12-30
      • 1970-01-01
      • 2022-12-14
      • 2019-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多