如何重新排序正式类空间多边形

问题描述 投票:0回答:2

我正在寻找一种方法来重新排序一组正式类空间多边形

我正在使用美国人口普查数据(限于德克萨斯州),并希望从不同的县组合中创建33个多边形。

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)

我已经尝试将Texas_LMA转换为SpatialPolygonsDataFrame

#   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))

但这对我没有用。

r rgdal sp
2个回答
0
投票

你的问题不是很清楚。但我认为这就是你所追求的:

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)

你没有提供LMA数据,所以从这里猜测一下:

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

0
投票
shapefilename[order(shapefilename$column_name),]
© www.soinside.com 2019 - 2024. All rights reserved.