2011-03-05 16 views
6

यहां पोस्ट द्वारा प्रेरित, Developing Geographic Thematic Maps with R, मैं ज़िप कोड के आधार पर एक choropleth मानचित्र बनाने के बारे में सोच रहा था। मैंने http://www.census.gov/geo/www/cob/z52000.html से न्यू हैम्पशायर और मेन के लिए आकृति फाइलें डाउनलोड की हैं, लेकिन मुझे इन दो राज्यों से .shp फ़ाइलों को संयोजित करने या विलय करने में दिलचस्पी है।आर में एक choropleth बनाने: एकाधिक राज्यों से ज़िप कोड आकारफाइल विलय

वहाँ मर्ज या आप के बाद दो .shp फ़ाइलों के संयोजन के इस प्रकार उन्हें readShapeSpatial() का उपयोग करने में पढ़ कर के लिए maptools पैकेज में एक तंत्र है? उदाहरण के लिए इनपुट का भी स्वागत है RgoogleMaps पैकेज का उपयोग करना आसान होगा।

+1

यह लिंक (http://r-sig-geo.2731867.n2.nabble.com/suggestion-to-MERGE-or-UNION-3-shapefiles-td5914413.html#a5916751) विलय पर। स्थानिक डेटा को संभालने के लिए नाबल संग्रह एक सोने की खान होना चाहिए। –

+0

एमएमएम ... पता नहीं था आर-सिग-भू ने इसे नाबल पर बना दिया था। दुर्भाग्यपूर्ण है कि इसे अन्य आर मंचों के साथ समूहीकृत नहीं किया गया है। – Sharpie

+3

मुझे यह महसूस करने के लिए जीआईएस के लगभग पांच साल लगे लेकिन ... यह "choropleth" नहीं है "chloropleth" –

उत्तर

4

मैंने रोमन लुसट्रिक द्वारा पोस्ट किए गए लिंक पर पीछा किया, और निम्नलिखित उत्तर http://r-sig-geo.2731867.n2.nabble.com/suggestion-to-MERGE-or-UNION-3-shapefiles-td5914413.html#a5916751 का मामूली संशोधन है।

निम्नलिखित कोड आपको Census 2000 5-Digit ZIP Code Tabulation Areas (ZCTAs) Cartographic Boundary Files से प्राप्त .shp फ़ाइलों को मर्ज करने और उन्हें साजिश करने की अनुमति देगा।

इस मामले में, मैंने .shp फ़ाइलों को डाउनलोड किया और .dbf और .shx मैसाचुसेट्स, न्यू हैम्पशायर और मेन के लिए फाइलें डाउनलोड कीं।

library('maptools') 
library('rgdal') 

setwd('c:/location.of.shp.files') 

# this location has the shapefiles for zt23_d00 (Maine), zt25_d00 (Mass.), and zt33_d00 (New Hampshire). 

# columns.to.keep 
# allows the subsequent spRbind to work properly 

columns.to.keep <- c('AREA', 'PERIMETER', 'ZCTA', 'NAME', 'LSAD', 'LSAD_TRANS') 

files <- list.files(pattern="*.shp$", recursive=TRUE, full.names=TRUE) 

uid <-1 

# get polygons from first file 

poly.data<- readOGR(files[1], gsub("^.*/(.*).shp$", "\\1", files[1])) 
n <- length(slot(poly.data, "polygons")) 
poly.data <- spChFIDs(poly.data, as.character(uid:(uid+n-1))) 
uid <- uid + n 
poly.data <- poly.data[columns.to.keep] 

# combine remaining polygons with first polygon 

for (i in 2:length(files)) { 
    temp.data <- readOGR(files[i], gsub("^.*/(.*).shp$", "\\1",files[i])) 
    n <- length(slot(temp.data, "polygons")) 
    temp.data <- spChFIDs(temp.data, as.character(uid:(uid+n-1))) 
    temp.data <- temp.data[columns.to.keep] 
    uid <- uid + n 
    poly.data <- spRbind(poly.data,temp.data) 
} 

plot(poly.data) 

# save new shapefile 

combined.shp <- 'combined.shp' 
writeOGR(poly.data, dsn=combined.shp, layer='combined1', driver='ESRI Shapefile') 
0

GeoMerge आकारफ़ाइल विलय करने के लिए एक निःशुल्क टूल है। एसएचपी और डीबीएफ भागों विलय। ठीक काम करने लगता है, लेकिन मैंने इसे बहुत ज्यादा धक्का नहीं दिया है।