[R] To overlay my raster and its boundary

Michael Sumner mdsumner at gmail.com
Thu Mar 22 08:01:26 CET 2012


plot(test1, add = TRUE)

But, that assumes the test1 object read from shapefile is using the
same coordinate system as the raster, and that it shares at least some
of the same extent. If they are in different coordinate systems
(projection) one or the other must be transformed, if they don't
overlap at all you need to set up the first plot to extend to the
shared region. Use projection() to find out for raster object, and
proj4string() for Spatial objects (sp and rgdal).

R-Sig-Geo is a more appropriate mailing list for questions on the
raster, rgdal and sp packages, and please read the posting guide. Your
code is not reproducible (so my answer is a big guess) and you did not
declare your use of the raster package.

Cheers, Mike.

On Thu, Mar 22, 2012 at 7:49 AM, Komine <momadou at yahoo.fr> wrote:
> Hi
> I want to overlay my raster and its boundary which is a shapefile.
>  When I used thise code separately, all is ok:
> # Open raster
>>Image<-read.table("C:\\Users\\Documents\\Nouveau\\Frequence.txt",sep="",dec=",",header=TRUE)
>  >testo<-rasterFromXYZ(Image)
>>plot(testo)
>>testo2 <- aggregate(testo,fact=10, fun=mean)
>>plot(testo2)
> # open shapefiles= boundary
>>library (rgdal)
>>test1<-readOGR(dsn="C:\\Users\\Documents\\DISC D\\Nouveau",layer="pays")
>>plot(test1)
>
> But How to overlay both layers (raster and shapefile) to have a same map?.
> Thank you in advance
>
> --
> View this message in context: http://r.789695.n4.nabble.com/To-overlay-my-raster-and-its-boundary-tp4493705p4493705.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-help mailing list