【问题标题】:What is the proj4 string associated with my shapefile?与我的 shapefile 关联的 proj4 字符串是什么?
【发布时间】:2013-11-05 22:32:08
【问题描述】:

我正在按照this 教程中的“一些简单地图”步骤尝试为here 中的新奥尔良邮政编码地图着色(我正在使用来自该链接的 2011 年新奥尔良数据中的 .shp 文件)。

当我尝试像教程中那样加载文件时,出现以下错误:

nolazip.shp <- readShapePoly("/PathTo/Orleans_ZCTA_2010_SP.shp", proj4string=CRS("+proj=longlat"))
Error in validityMethod(as(object, superClass)) : 
  Geographical CRS given to non-conformant data: 3820725.379655  613426.584024  

根据this 文档,此错误似乎意味着形状文件未使用具有有效 longlat 数据的 proj4string。

它是否使用其他类型的 proj4string 或 CRS 对象?

我执行了这些命令试图找出答案,在输出中搜索 CRS 但没有找到任何东西。

    > summary(orcounty.shp)
    > str(orcounty.shp)

我可以通过在 readShapePoly 命令中省略 proj4string 参数来导入形状文件,但这不是一个可行的解决方案,因为当我遵循“一些简单的地图”部分时,地图不会出现在绘图窗口中(我需要的唯一部分)。

  1. 与我的 shapefile 关联的 proj4 字符串是什么?如何将其作为 readShapePoly 的输入
  2. 是否有其他方法可以导入适用于这种制图方法的 shapefile?同样,简单地省略有问题的参数意味着地图不会显示在 R Studio 的绘图中。

【问题讨论】:

    标签: r gis


    【解决方案1】:

    我会使用readOGR 来解决这个问题,它会保留投影信息,因此您不必像在上面的问题中那样搞乱它。这似乎是相同的 shapefile(从this US government site 下载)读入然后绘制在ggplot2 中。化妆品可能需要整理一下,但这会给你一些练习RColorBrewer 和秤和其他ggplot2 的东西。 [编辑 - 在geom_polygon 中添加了缺少的aes 调用]

    # if the packages are not installed, you will have to install and load them.
    install.packages("rgdal")
    install.packages("ggplot2")
    install.packages("scales")
    library(rgdal)
    library(ggplot2)
    library(scales)
    
    require(rgdal)
    require(ggplot2)
    require(scales)
    
    work.dir <- "your_dirname" # your directory
                                         # no trailing slash
    
    orl <- readOGR(work.dir, layer = "Orleans_ZCTA_2010_SP")
    orl.df <- fortify(orl) # ggplot needs data frame, not spatial object
    
    ggplot(data = orl.df, aes(x = long, y = lat, group = group)) +
        geom_polygon(aes(fill = orl.df$group)) +
        coord_equal() +
        theme(legend.position = "none")
    

    【讨论】:

      【解决方案2】:

      @SlowLearner 的回答很好地解决了根本问题。对于其他刚来这里是为了标题问题的人:

      与我的 shapefile 关联的 proj4 字符串是什么?

      area <- rgdal::readOGR(dsn = "path/to/shape.shp")
      
      rgdal::CRSargs(area@proj4string)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-03
        • 1970-01-01
        • 2014-03-15
        • 2014-10-17
        • 2014-11-27
        • 1970-01-01
        相关资源
        最近更新 更多