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

4
我正在按照这里的“一些简单地图”步骤尝试对新奥尔良的邮政编码地图进行着色,数据来自此处(我使用该链接中新奥尔良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  

根据此文档,看起来这个错误意味着该形状文件未使用包含有效经纬度数据的proj4string。

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

我执行了以下命令以尝试查找,搜索输出以获取CRS,但没有发现任何内容。

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

我可以在readShapePoly命令中省略proj4string参数,从而导入此shapefile,但这不是可行的解决方案,因为当我按照“一些简单地图”部分(我需要的唯一部分)时,地图不会出现在绘图窗口中。

  1. 我的shapefile关联的proj4字符串是什么?我如何将其作为输入提供给readShapePoly?
  2. 是否有其他方法可以导入shapefile,并与此地图制作方法配合使用?同样,简单地省略问题的参数意味着地图在R studio的绘图中不会显示。
2个回答

6
我会使用readOGR来处理这个问题,它会保留投影信息,因此您不必像您在上面的问题中那样进行操作。这是似乎是从这个美国政府网站下载的相同shapefile,然后在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")

orleans


0
@SlowLearner的答案是解决根本问题的好方法。对于其他人,他们只是因为标题问题而来到这里:
我的shapefile关联的proj4字符串是什么?
area <- rgdal::readOGR(dsn = "path/to/shape.shp")

rgdal::CRSargs(area@proj4string)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接