Как объединить SpatialPolygons в SpatialPolygonsDataFrame - PullRequest
0 голосов
/ 28 марта 2020

Из моего основного файла «fueltx» я вытаскиваю два наблюдения, чтобы объединить их в одно («фиксированное»). Затем я хочу добавить «фиксированное» наблюдение обратно в основной файл «fueltx».

Вот мой код:

library(sp)
library(rgdal)
library(tidyverse)
library(spdplyr)
library(sf)
library(rgeos)

fueltx <- readOGR("C:/Users/A02305035/Desktop/JamelaResearch/Data/GIS/Combined/fueltx.shp")

wanted <- c(97, 105)    ## 2 observations that need to be merged
problem_tx <- fueltx[fueltx$tunique %in% wanted,]    ## 2 observations that need to be merged

fueltx <- fueltx[!fueltx$tunique %in% wanted,]   ## removing them from the main file. class SpatialPolygonsDataFrame

fixed <- gUnaryUnion(problem_tx)  ## merging into 1 observation, class SpatialPolygons

df <- data.frame(1, 1)               ## making data frame 
fixed.df <- SpatialPolygonsDataFrame(fixed, data = df)   ## changing "fixed" from SpatialPolygons to SpatialPolygonsDataFrame

fueltx <- merge(fueltx, fixed.df)    ## want to add the 1 observation back to the main file
## No error, but observation is not added
...