no boundaries between countries by using unionSpatialPolygons
On Wed, 7 Jan 2009, Hans-J?rg Bibiko wrote:
Hi, I have a tiny problem. I'm using Roger Bivand's ( http://spatial.nhh.no/R/etc/TM_WORLD_BORDERS_SIMPL-0.2.RData ) to create a plot showing two countries without boundaries. I did this: library("foreign") library("sp") library("maptools") library("gpclib") load("TM_WORLD_BORDERS_SIMPL-0.2.RData") pe_bo_data <- wrld_simpl[wrld_simpl$NAME %in% c("Bolivia","Peru"),] lps <- coordinates(pe_bo_data) ID <- cut(lps[,1], quantile(lps[,1]), include.lowest=TRUE) pe_bo <- unionSpatialPolygons(pe_bo_data, ID, threshold = NULL) plot(pe_bo)
Excellent question - easy to reproduce! Your ID has two unique values:
ID
[1] (-67.1,-64.6] [-74.4,-71.9] Levels: [-74.4,-71.9] (-71.9,-69.5] (-69.5,-67.1] (-67.1,-64.6] with two country polygons:
length(slot(pe_bo_data, "polygons"))
[1] 2
so you get two output polygons. If you do:
ID2 <- rep("pe_bo", length(slot(pe_bo_data, "polygons")))
pe_bo <- unionSpatialPolygons(pe_bo_data, ID2)
gives one output polygon:
length(slot(pe_bo, "polygons"))
[1] 1 and no boundary. Roger
but the plot still shows the boundary between Peru and Bolivia. I also tried to set a proper threshold but unfortunately no success. What's wrong with my approach? I'd be glad for any hint! I'm using R version 2.8.0 (2008-10-20) on Mac OSX 10.5.6 (Intel) Thanks in advance, --Hans
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no