---------- Forwarded message ---------- From: Markus Loecher <mar...@sensenetworks.com> To: Patrick Crutcher <pcrutc...@gmail.com> Date: Mon, 18 Jan 2010 11:31:05 -0500 Subject: Re: Plotting shapefiles on top of Google map tiles
sorry, I was not at a computer that could run R last night when I came up with the code, it needs some modification: shp=importShapefile(shpFile,projection="LL"); bb <- qbbox(lat = shp[,"Y"], lon = shp[,"X"]); MyMap <- GetMap.bbox(bb$lonR, bb$latR, destfile = "DC.jpg"); PlotPolysOnStaticMap(MyMap, shp, lwd=.5, col = rgb(0.25,0.25,0.25,0.025), add = F); and for an example that color codes the polygons individually #North Carolina SIDS data set: shpFile <- system.file("shapes/sids.shp", package="maptools"); bb <- qbbox(lat = shp[,"Y"], lon = shp[,"X"]); MyMap <- GetMap.bbox(bb$lonR, bb$latR, destfile = "SIDS.jpg"); #compute regularized SID rate sid <- 100*attr(shp, "PolyData")$SID74/(attr(shp, "PolyData")$BIR74+500) b <- as.integer(cut(sid, quantile(sid, seq(0,1,length=8)) )); b[is.na(b)] <- 1; opal <- col2rgb(grey.colors(7), alpha=TRUE)/255; opal["alpha",] <- 0.2; shp[,"col"] <- rgb(0.1,0.1,0.1,0.2); for (i in 1:length(b)) shp[shp[,"PID"] == i,"col"] <- rgb(opal[1,b[i]],opal[2,b[i]],opal[3,b[i]],opal[4,b[i]]); PlotPolysOnStaticMap(MyMap, shp, lwd=.5, col = shp[,"col"], add = F); Markus On Sun, Jan 17, 2010 at 9:13 PM, Markus Loecher <mar...@sensenetworks.com >wrote: > Good question, I should have added a proper example to the > PlotPolysOnStaticMap() function, which I wrote for that exact purpose. > > One way of overlaying, e.g. Census polygons on a Google static map would be > the following: > > require(PBSmapping); > shp=importShapefile('bg11_d00.shp'); > bb <- qbbox(shp[,"X"], shp[,"Y"]); > MyMap <- GetMap.bbox(bb$lonR, bb$latR, destfile = "DC.png"); > PlotPolysOnStaticMap(MyMap, shp, lwd=.25, col = 'lightgray', add = T); > > Here, I use the package PBSmapping to read the shapefile into a convenient > data frame format. > The shapefile bg11_d00.shp happens to be the census shapefile for > Washington DC (you'll also need the corresponding .dbf and .shx in the same > directory); I am planning to include a small shapefile in the library in the > future. > PlotPolysOnStaticMap() overlays the corresponding polygons on the map. > > Let me know if this works for you, > > Markus > > > > > > On Sat, Jan 16, 2010 at 8:35 PM, Patrick Crutcher <pcrutc...@gmail.com >wrote: > >> I have some shapefiles I want to plot over Google Maps tiles. I have >> polygons, lines and point data. What's the most efficient way to do this? >> One path might be to use the pkg RgoogleMaps, however, it is still unclear >> to me how to do this. I assume using PlotonStaticMap with some combination >> of reformatting the shapefile data. Thanks. >> >> P. >> > > [[alternative HTML version deleted]] [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo