Skip to content
Prev 1409 / 29559 Next

shapefiles, images, iimagemaps, and removinginternalboundarylines

On Thu, 19 Oct 2006 matt.pettis at thomson.com wrote:

            
A possible dirty fix is to overlay the polygons with a low-resolution grid 
and take the convex hull of cell centres within each polygon as the object 
passed to the HTML code as a clickable mask - there will be "no-hit" 
slivers, and overlaps for convex/concave boundaries, but life is too short 
...

library(maptools)
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], 
  IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
grd <- GridTopology(c(-84.5, 33.75), c(0.025, 0.025), c(360, 120))
mask <- SpatialGrid(grd, proj4string=CRS("+proj=longlat +ellps=clrk66"))
where <- overlay(mask, xx) # takes some time
incrds <- coordinates(mask)[!is.na(where),]
inwhere <- where[!is.na(where)]
incrds1 <- split(data.frame(incrds), inwhere)
chulls <- lapply(incrds1, function(x) {xx <- as.matrix(x); 
  xx[chull(xx),]})
plot(xx, border="blue")
lapply(chulls, polygon, col="yellow")

There are slivers/overlaps, it'll need fine tuning, but these image map 
polygons have many fewer boundary points that the originals. In addition 
multiple polygon objects are not treated gracefully. 

Roger