[R-sig-Geo] shapefiles, images, iimagemaps, and removinginternalboundarylines
Roger Bivand
Roger.Bivand at nhh.no
Fri Oct 20 11:25:26 CEST 2006
On Fri, 20 Oct 2006, Roger Bivand wrote:
> On Thu, 19 Oct 2006 matt.pettis at thomson.com wrote:
>
> > Thanks Roger,
> >
> > I'll try and build my own from source -- I was just hoping there was a
> > binary floating around somewhere.
> >
> > Truthfully, my maps will have very detailed boundaries (Relatively
> > speaking, I think), so I'll give it a try.
After thinking abour using imagemaps, I realised that this will probably
not scale with regard to the client-side/server-side balance. I really
recommend looking at Rpad, and at MapServer for an open-source way of
keeping relatively little on the client side. The harder bits are moving
the data in the data base tables into R and back again maintaining the
correct keys, but I'm sure it can be done. Apart from Rpad, are there
others on the list with experience of using R as middleware for processing
attribute data for web mapping? The O'Reilly "Web Mapping Illustrated"
by Tyler Mitchell has plenty of ideas, but I can't see that they use R.
Roger
>
> 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
>
>
> >
> > I'll be posting some more questions in a bit about
> > 'unionSpatialPolygons', as I am having some troubles with it...
> >
> > Thanks,
> > Matt
> >
> > -----Original Message-----
> > From: Roger Bivand [mailto:Roger.Bivand at nhh.no]
> > Sent: Thursday, October 19, 2006 2:57 PM
> > To: Pettis, Matthew (TLR Corp)
> > Cc: r-sig-geo at stat.math.ethz.ch
> > Subject: RE: [R-sig-Geo] shapefiles, images, iimagemaps, and
> > removinginternalboundarylines
> >
> > On Thu, 19 Oct 2006 matt.pettis at thomson.com wrote:
> >
> > > Thanks! Got it to work.
> > >
> > > However, the install of "imagemap" didn't work for me... I'm on
> > > Windows XP, and the souce comes in a .tar.gz file, which the 'Packages
> >
> > > > Install
> > > packages(s) from local .zip files...' doesn't recognize. Any
> > > alternate location for this, or a method for windows xp to import this
> >
> > > module correctly?
> >
> > The *.tar.gz is a source package. The *.zip are typically Windows binary
> > packages, pre-built. Some Windows users with programming experience do
> > build their own from source, the toolset is described in Appendix E of
> > the R Installation and Administration manual, and package installation
> > in Ch.
> > 6. If that isn't for you (or anybody nearby), say, and someone may have
> > a go at building a Windows binary. Whether it is worth the trouble for
> > spatial objects will however depend on the objects you want to make
> > clickable, if they are simple, it'll work, but if they are polygons with
> > very detailed boundaries (remember that the image map is raster while
> > the boundaries are vector), it may not scale well. Probably worth
> > trying, though.
> >
> > Roger
> >
> > >
> > > Thanks,
> > > matt
> > >
> > > -----Original Message-----
> > > From: Roger Bivand [mailto:Roger.Bivand at nhh.no]
> > > Sent: Thursday, October 19, 2006 11:14 AM
> > > To: Pettis, Matthew (TLR Corp)
> > > Cc: r-sig-geo at stat.math.ethz.ch
> > > Subject: RE: [R-sig-Geo] shapefiles, images, iimagemaps, and
> > > removinginternalboundary lines
> > >
> > > On Thu, 19 Oct 2006 matt.pettis at thomson.com wrote:
> > >
> > > > Hi Roger,
> > > >
> > > > Thanks again for the response. To answer your questions:
> > > >
> > > > - I am currently running on R 2.3.1. I was at 2.4.x, but some of
> > > > the packages I thought I needed weren't available on the cran
> > > > interface in
> > >
> > > > the rgui (I was experimenting, and I can't remember what they were
> > > > now, so that may no longer be true). It sounds like you are fine
> > > > running R at 2.4, though, and I could probably upgrade, as my sole
> > > > purpose for having R right now is to deal with shapefiles and create
> > > image maps.
> > > >
> > > > - Related to the above, I don't see the spgpc package on my mirror
> > > > (USA (IA)), but that may be related to being at 2.3?
> > >
> > > No, but it isn't on CRAN, only on the little sp extras repository on
> > > sourceforge:
> > >
> > > rSpatial <- "http://r-spatial.sourceforge.net/R"
> > > install.packages("spgpc", repos=rSpatial)
> > >
> > > so this should install it. In fact there isn't yet a Windows binary
> > > for 2.4, so 2.3 is OK.
> > >
> > > >
> > > > Also, I saw the 'unionSpatialPolygons' command in Debarchana Ghosh's
> >
> > > > code, but didn't know what it did. I'll investigate the paths you
> > > > have listed here.
> > > >
> > > > Thanks again,
> > > > Matt
> > > >
> > > > -----Original Message-----
> > > > From: Roger Bivand [mailto:Roger.Bivand at nhh.no]
> > > > Sent: Thursday, October 19, 2006 2:32 AM
> > > > To: Pettis, Matthew (TLR Corp)
> > > > Cc: r-sig-geo at stat.math.ethz.ch
> > > > Subject: Re: [R-sig-Geo] shapefiles, images, iimagemaps, and
> > > > removing internalboundary lines
> > > >
> > > > On Wed, 18 Oct 2006 matt.pettis at thomson.com wrote:
> > > >
> > > > > I have sucessfully inputted a shapefile into a
> > > > > SpatialPolygonsDataFrame object. I would like to output this file
> >
> > > > > as a .gif/.png/.bmp/.jpeg image and generate an imagemap for the
> > > > > outputted image. Does anybody know the best way to approach this?
> > > >
> > > > RSiteSearch("imagemap")
> > > >
> > > > gets you to:
> > > >
> > > > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/28035.html
> > > >
> > > > This installs on R 2.4.0 from source - which platform are you using
> > > > and can you install source packages? The documentation in
> > > > imagemap/inst/doc/imagemap-howto.pdf is clear, addRegion(im) <- for
> > > > each clickable object. How to go from there depends on what you want
> >
> > > > to be clickable.
> > > >
> > > > Alternatives might be Rpad:
> > > >
> > > > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77952.html
> > > >
> > > > or using ogr2ogr in FWTools (external software) to generate a KML
> > > > for Google Earth (if the bubble that pops up is enough - I don't
> > > > know how to put a link into it, though I guess it could be done), or
> >
> > > > writing the KML from R:
> > > >
> > > > http://bbs.keyhole.com/ubb/showflat.php/Cat/0/Number/221682/Main/219
> > > > 13
> > > > 1
> > > >
> > > > > secondly (and i may need to start another thread for this), but
> > > > > is there an easy function to remove the interior lines of
> > > > > aggregated shapes (and generate an imagemap again, etc.)? For
> > > > > example, If I have
> > > >
> > > > > a map of the U.S.'s with a polygon for each state, could I remove
> > > > > all internal state boundaries to leave just the national border?
> > > >
> > > > Using the objects you have now, you need to install the spgpc
> > package:
> > > >
> > > > rSpatial <- "http://r-spatial.sourceforge.net/R"
> > > > install.packages("spgpc", repos=rSpatial)
> > > >
> > > > and install gpclib from CRAN. Then
> > > >
> > > > ?unionSpatialPolygons
> > > >
> > > > to dissolve internal boundaries. This is for arbitrary polygons, if
> > > > you really just need to dissolve US states, perhaps using the CRAN
> > > > maps package with its built-in database, and its own dissolve
> > > > mechanism would save re-doing topology, but it only works for
> > > > polygons
> > > in the database.
> > > >
> > > > Roger
> > > >
> > > > >
> > > > > thanks,
> > > > > Matt
> > > > >
> > > > > _______________________________________________
> > > > > 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
> > > >
> > >
> > > --
> > > 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
> > >
> > >
> >
> > --
> > 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
> >
>
>
--
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