您能否通过数据框中的值组合SpatialPolygonsDataFrame中的多边形?

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

我正在尝试使用Australian Bureau of Statistics shapefile for Remoteness 2016-下载ESRI shapefile。

我想合并不是澳大利亚主要城市的所有多边形。

library(rgdal)
library(dplyr)
RA_2016 <- readOGR(".", layer = "RA_2016_AUST")
###to simplify only using NSW
RA_2016 <- RA_2016[RA_2016$STE_CODE16 == 1, ]

数据框有5列。一旦创建了是否是大城市的变量,就不需要任何这些数据。

MajorCity <- data.frame(10:14, c("Major City", "Regional", "Regional", "Regional", "Regional"))
names(MajorCity) <- c("RA_CODE16", "Bigsmoke")

RA_2016@data <- left_join(RA_2016@data, MajorCity)

我现在要做的是合并具有MajorCity ==“ Regional”的多边形。我不需要RA_2016的任何原始数据。但我希望它保持SpatialPolygonsDataFrame与“ Bigsmoke”列。

在代码的下一部分中,我将其与澳大利亚统计局的LGA数据结合起来(基本上是这样,我可以将LGA分为区域部分和主要城市部分-在这些部分)。因此,我认为我需要保留少量数据。

是否有这样做的好方法?我还有没有找到的其他帖子会告诉我方法吗?

r geospatial raster rgdal spdf
1个回答
0
投票

这是我的处理方式:

setwd("C:/Users/rhijm/Downloads")
library(raster)

RA_2016 <- shapefile("RA_2016_AUST.shp")
RA_2016 <- RA_2016[RA_2016$STE_CODE16 == 1, ]

MajorCity <- data.frame(RA_CODE16=10:14, Bigsmoke=c("Major City", "Regional", "Regional", "Regional", "Regional"))

m <- merge(RA_2016, MajorCity)
x <- aggregate(m, "Bigsmoke")
x
#class       : SpatialPolygonsDataFrame 
#features    : 2 
#extent      : 140.9993, 159.1092, -37.50508, -28.15702  (xmin, xmax, ymin, ymax)
#crs         : +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs 
#variables   : 1
#names       :   Bigsmoke 
#min values  : Major City 
#max values  :   Regional 
© www.soinside.com 2019 - 2024. All rights reserved.