2016-06-29 12 views
0

ich nach einer Möglichkeit, eine Reihe von Formal Klasse Spatial Polygonen neu zu bestellenWie neu anordnen Formal Klasse Spatial Polygonen

mit Ich verwende US Census Daten (Limited to Texas) und wollen 33 schaffen Polygone aus verschiedenen County-Kombinationen.

library(tmap) 
library(maptools) 
library(ggplot2) 
library(rgeos) 
library(sp) 
library(mapdata) 
library(rgdal) 
library(raster) 

# Download the map of texas and get the LMAs boundaries 
# Download shape 
f <- tempfile() 
download.file("http://www2.census.gov/geo/tiger/GENZ2010/gz_2010_us_050_00_20m.zip", destfile = f) 
unzip(f, exdir = ".") 
US <- read_shape("gz_2010_us_050_00_20m.shp") 

# Select only Texas 
Texas <- US[(US$STATE %in% c("48")),] 


# Load the LMA append data 
LMAs = read.table('LMA append data.csv',header=T, sep=',') 

# Append LMA data to Texas shape 
Texas$FIPS <- paste0(Texas$STATE, Texas$COUNTY) 
Texas <- append_data(Texas, LMAs, key.shp = "FIPS", key.data = "FIPS") 
Texas <- Texas[order(Texas$LMA),] 

# Create shape object with LMAs polygons 
Texas_LMA <- unionSpatialPolygons(Texas, IDs=Texas$LMA) 

Ich habe versucht, Texas_LMA in eine SpatialPolygonsDataFrame mit

# Create shape object with LMAs polygons 
Texas_LMA <- unionSpatialPolygons(Texas, IDs=Texas$LMA) 
spp <- SpatialPolygonsDataFrame(Texas_LMA,data=matrix(1:33,nrow=33,ncol=1)) 

Umwandlung Aber das hat sich für mich nicht funktioniert.

Antwort

0

Ihre Frage ist nicht sehr klar. Aber ich denke, das ist, was Sie nach:

library(raster) 
f <- tempfile() download.file("http://www2.census.gov/geo/tiger/GENZ2010/gz_2010_us_050_00_20m.zip", destfile = f) 
unzip(f, exdir = ".") 
US <- shapefile("gz_2010_us_050_00_20m.shp") 
Texas <- US[(US$STATE %in% c("48")),] 
LMAs = read.csv('LMA append data.csv') 
Texas$FIPS <- paste0(Texas$STATE, Texas$COUNTY) 

Sie nicht die LMA Daten lieferten, so ein wenig von hier zu raten:

Texas <- merge(Texas, LMAs, by="FIPS") 
Texas_LMA <- aggregate(Texas, by='LMA') 
+0

, dass es in einem SpatialPolygonDataFrame bekommt und es lässt mich re- Ordne die Polygone in der richtigen Reihenfolge an. Danke für die Hilfe! – rskinner593