[R-sig-Geo] rgdal::writeOGR with driver='ESRI Shapefile' converts Polygon object into a hole
Phil Haines
ph||@h@|ne@82 @end|ng |rom gm@||@com
Tue Aug 13 19:50:50 CEST 2019
Dear list,
I have a single Polygons object containing multiple Polygon objects
that share a common border. When I output this using writeOGR() one of
the Polygon objects becomes a hole, as the following example shows.
Create a Polygons object containing two adjoining Polygon objects
> library(rgdal)
> r1 <- rbind(c(1,1),c(1,2),c(2,2),c(2,1),c(1,1))
> r2 <- r1; r2[,1] <- r2[,1]+1
> Ps1 = Polygons(list(Polygon(r1),Polygon(r2)),ID=1)
> SPDF = SpatialPolygonsDataFrame( SpatialPolygons(list(Ps1)), data.frame(Example=c("Minimal")))
Perform a write/readOGR() cycle
> fn <- tempfile()
> writeOGR(SPDF, fn, layer='test', driver='ESRI Shapefile')
> SPDF2 <- readOGR(dsn=fn,layer='test')
Second Polygon object is now a hole
> sapply(SPDF2 using polygons[[1]]@Polygons,slot,"hole")
[1] FALSE TRUE
I see from the sp documentation that "Polygon objects belonging to a
Polygons object should either not overlap one-other, or should be
fully included" but I am not sure how this relates to bordering
Polygon objects. I would welcome any advice as to whether what I am
asking of writeOGR is reasonable?
Thanks in advance for your time,
Phil
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United
Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgdal_1.4-4 sp_1.3-1
loaded via a namespace (and not attached):
[1] compiler_3.5.1 tools_3.5.1 yaml_2.2.0 grid_3.5.1
lattice_0.20-35
More information about the R-sig-Geo
mailing list