[R-sig-Geo] Spatial network plots? -- speeding up rasterization

Nicholas Lewin-Koh nikko at hailmail.net
Thu Dec 16 17:35:59 CET 2010


Hi Robert
Looking over your code, Wouldn't it be much faster
to use Rgooglemaps or something where the map is already rasterized?
The newer versions of R have the lowlevel raster function for plotting
images.
Also, even in base graphics you can use alpha blending so for your
network lines 
lines(rts, col=rgb(1,0,0,alpha=.2))
would look much nicer.

Nicholas

>
> ------------------------------
> 
> Message: 24
> Date: Wed, 15 Dec 2010 15:03:51 -0800
> From: "Robert J. Hijmans" <r.hijmans at gmail.com>
> To: r-sig-geo at r-project.org
> Subject: Re: [R-sig-Geo] Spatial network plots?
> Message-ID:
> 	<AANLkTik=SF4GY34Qf=TSmWoYwmxSqzmJvM_in0aVdSys at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Bogdan,
> 
> The function gcIntermediate  in geosphere can create such lines from
> "from - to" sets of coordinates. Code partly inspired by T Hengl's air
> routes script:  http://spatial-analyst.net/worldmaps/airroute.htm
> 
> library(geosphere)
> library(sp)
> 
> n  <- 20
> from <- data.frame(lon=runif(n)*-175, lat=runif(n)*80)
> to <- data.frame(lon=runif(n)*175, lat=runif(n)*-80)
> 
> d <- distHaversine(from[,c('lon', 'lat')], to[,c('lon', 'lat')]) / 1000
> npts <- pmax(1, round(sqrt(d)/sqrt(2), 0))  # based on T. Hengl's air
> routes example
> rts <- gcIntermediate(from[,c('lon', 'lat')], to[,c('lon', 'lat')],
> npts, breakAtDateLine=TRUE, addStartEnd=TRUE, sp=TRUE)
> 
> library(maptools)
> data(wrld_simpl)
> plot(wrld_simpl)
> plot(rts, col='red', add=T)
> points(from, col='blue')
> points(to, col='green')
> 
> 
> # A next step could be to use the rasterize function in raster to
> create a line-density raster.
> # this takes a long time
> 
> library(raster)
> r <- raster()
> res(r) <- 5
> r <- rasterize(rts, r, fun='count')
> 
> plot(r)
> plot(wrld_simpl, add=T)
> lines(rts, col='red')
> 
> 
> Robert
> 
> 
> On Wed, Dec 15, 2010 at 1:58 PM, Edzer Pebesma
> <edzer.pebesma at uni-muenster.de> wrote:
> > Bogdan, you may also like this:
> >
> > http://www.facebook.com/notes/facebook-engineering/visualizing-friendships/469716398919
> >
> > Earlier this evening I tried to leave a note there to ask the author for
> > the script, but failed, it seems.
> >
> > On 12/15/2010 10:43 PM, Bogdan State wrote:
> >> Hi everyone,
> >>
> >> I hope I am posting on the right list. I have recently started analyzing
> >> some data that involves connections between people in various cities. I
> >> would be extremely grateful if someone could point me towards a solution for
> >> drawing "geographical networks" similar to the flight maps at the back of
> >> airline magazines (i.e. New York connects to L.A. etc.). I have looked at
> >> all the usual suspects so far: sp/maptools for GIS (mostly by using spplot)
> >> and igraph/statnet for social network analysis. None of the packages seems
> >> to do exactly what I need, but I hope I am wrong.
> >>
> >> Thanks in advance,
> >> Bogdan State
> >> PhD Student
> >> Department of Sociology
> >> Stanford University
> >>
> >> bstate at stanford.edu
> >>
> >> ? ? ? [[alternative HTML version deleted]]
> >>
> >> _______________________________________________
> >> R-sig-Geo mailing list
> >> R-sig-Geo at r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
> > --
> > Edzer Pebesma
> > Institute for Geoinformatics (ifgi), University of M?nster
> > Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251
> > 8333081, Fax: +49 251 8339763 ?http://ifgi.uni-muenster.de
> > http://www.52north.org/geostatistics ? ? ?e.pebesma at wwu.de
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo at r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
> 
> 
>



More information about the R-sig-Geo mailing list