[R-sig-Geo] splancs and the use of a shapefile with a hole

Roger Bivand Roger.Bivand at nhh.no
Sat May 26 20:25:01 CEST 2007


On Sat, 26 May 2007, Marco Helbich wrote:

> Dear list,
> 
> my problem concerns the library splancs and the use of a shapefile with
> a hole. I found a part of code in another thread
> (http://finzi.psych.upenn.edu/R/Rhelp02a/archive/61525.html) saying that
> if I've "more than one shape, and/or more than one ring in that shape,
> adjust the [[Shape]])[[ring]]" in the
> "getPolygonCoordsSlot(getPolygonsPolygonsSlot(getSpPpolygonsSlot(pol)[[2]])[[1]])".
> My problem is that I can choose with the two parameters between the hole
> studyarea (inkluding the hole) or the hole itself but not among the
> studyarea excluding the hole. Below you can find the code.

The polygon used by splancs can only consist of a single ring. The typical 
fix is to join the external ring to the internal ring by two lines, 
creating an link between inner and outer, so that there no longer is a 
hole. This can be done with care and coffee, and the example you found 
from some time ago is not too easy to follow. Are you able to make an 
Rdata file of your polygon-and-hole object available?

Best wishes,

Roger

> 
> I appreciate every hint! Thanks
> 
> Marco
> 
> 
> > library(splancs)
> > library(maptools)
> > setwd("c:/test")
> > getwd()
> [1] "c:/test"
> > 
> > pol <- readShapePoly("stadtreg_owin.shp", verbose=T)
> Shapefile type: Polygon, (5), # of Shapes: 1
> > edv <- read.table("C:/test/edv.txt", header=T,
> +   sep=";", na.strings="NA", dec=",", strip.white=T)
> > poi <- as.points(edv[,-c(1:25)])
> > ls()
> [1] "edv"          "poi"          "pol"          "splancs_poly"
> > 
> > poi <- coordinates(poi)
> > splancs_poly <- getPolygonCoordsSlot(getPolygonsPolygonsSlot(
> +   getSpPpolygonsSlot(pol)[[1]])[[2]])
> > polymap(splancs_poly)
> 
> __________________________
> Marco Helbich
> ISR
> A-1010 Vienna, Postgasse 7/4/2
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> 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




More information about the R-sig-Geo mailing list