2013-10-26 25 views
3

我從this教程中嘗試着從here(我使用該鏈接的新奧爾良2011數據中的.shp文件)着色新奧爾良的郵政編碼地圖的步驟中的「一些簡單的地圖」步驟。與我的shapefile相關的proj4字符串是什麼?

當我嘗試加載該文件就像在教程中,我得到的錯誤如下:

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文檔,它看起來像這樣的錯誤是指形狀文件不使用proj4string與有效longlat數據。

它使用一些其他類型的proj4string或CRS對象嗎?

我做了這些命令試圖找出,搜索CRS的輸出,但沒有找到任何東西。

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

我能夠通過簡單地離開了在readShapePoly命令的proj4string參數導入的形狀文件,但因爲地圖沒有出現在圖形窗口時,我遵循「一些簡單的,是不是一個可行的解決方案地圖「部分(我需要的唯一部分)。

  1. 什麼是proj4字符串與我的shapefile關聯?我如何將它作爲輸入來讀取ShapeShapePoly
  2. 有沒有其他方法可以導入可以使用此映射方法的shapefile文件?同樣,簡單地忽略有問題的參數意味着地圖不會出現在R studio的情節中。

回答

5

我會用readOGR來解決這個問題,它保留了投影信息,因此您不必在上面的問題中弄亂它。這裏是什麼似乎是相同的shapefile(從this US government site下載)讀入,然後繪製在ggplot2。化妝品可能需要整理,但這會給你一些練習RColorBrewer和規模和其他ggplot2東西。 [編輯 - 添加缺少aes呼叫geom_polygon]

# 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

工作很好。謝謝! – bernie2436

0

@SlowLearner的答案是一個很好的解決根本問題。對於剛剛來到這裏的標題問題的其他人:

與我的shapefile關聯的proj4字符串是什麼?

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

rgdal::CRSargs([email protected]) 
相關問題