[R-sig-Geo] proj4string in rworldmap

Andy South southandy at gmail.com
Mon Nov 4 19:03:13 CET 2013


Rob Robinson <rob.robinson <at> bto.org> writes:

> 
> Prompted by a recent post,  I have discovered rworldmap, which look set to
> make my life much easier, apart from a wrinkle I can't get my head round.
> 
> I am writing a function to plot a map clipped to a given extent, and I'd
> like to be able to do so at different resolutions. This is easy to do 
using
> the different datasets (eg countriesCoarse, countriesHigh). I have two
> problems (i) they have (slightly) different proj4strings and (ii) when I
> pick up the proj4string to assign it to my clipping polygon CRS() alters
> it, causing the gDifference (etc) to complain they are different. Any
> thoughts on the best way to straighten this out?
> many thanks
> rob

Hi Rob,

I'm pleased that rworldmap might make your life easier even if that hasn't 
quite been realised yet.
 
I can fix problem (i) in rworldmap. Would someone like to suggest which of 
the 2 proj4strings is preferable ?

Seems likely that (ii) occurs in sp or further back, someone else might like 
to comment.

If you'd like to email me direct about your function, pleased do (I'm only 
just up the road!).

Best wishes,
Andy 




> Example:
> library(rworldmap)
> library(rworldxtra)
> data(countriesCoarse)
> data(countriesHigh)
> 
> proj4string(countriesCoarse)
> # [1] "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
> proj4string(countriesHigh)
> # [1] " +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
> 
> clip_poly <- readWKT("POLYGON((-50 40,-50 70,50 70,50 40,-50 40))")
> proj4string(clip_poly) <- CRS(proj4string(countriesCoarse))
> proj4string(clip_poly)
> # [1] "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
> # the +towgs84 tag has been added
> 
> res <- gDifference(clip_poly, countriesCoarse)
> # generates Warning: spgeom1 and spgeom2 have different proj4 strings
> 

> Dr Rob Robinson, Principal Ecologist
> British Trust for Ornithology, The Nunnery, Thetford, Norfolk, IP24 2PU
> Ph: +44 (0)1842 750050     E: rob.robinson <at> bto.org
> Fx: +44 (0)1842 750030     W: www.bto.org/about-bto/our-staff/rob-robinson
> 
> ====== "How can anyone be enlightened, when truth is so poorly lit" 
=======
> 
> 	[[alternative HTML version deleted]]
>



More information about the R-sig-Geo mailing list