[R-sig-Geo] spplot vs sp.polygon - Problem when drawing polygon with holes/islands overlay
Maarten Plieger
plieger at knmi.nl
Fri Oct 29 15:10:40 CEST 2010
Hi all,
I am having a (known) problem with plotting polygons with islands and
holes. I would like to visually mask my raster data with a polygon
overlay. The problem is that my polygon data has islands/holes, and
these are not drawn correctly when used as an overlay with the spplot
panel function.
When I use spplot directly to plot my polygons there is no problem:
spplot(countryOverlay [which(countryOverlay
$FID_Countr==0),],"CNTRYNAME", ylim=c(300000,624000),
xlim=c(0,285000),col.regions=c("transparent","transparent","transparent","blue","transparent")
)
(see spplot.png)
Now I would like to use the spplot panel function to draw the same data
as an overlay:
spplot(countryOverlay,"CNTRYNAME" ,ylim=c(300000,624000),
xlim=c(0,285000) ,
panel = function(...) {
sp.polygons( countryOverlay [which(countryOverlay $FID_Countr==0),],
fill = "blue",col = "black")
}
)
But now, the islands are gone! (see sp.polygons.png)
(The example above is just to demonstrate this problem/feature, it does
not draw my gridded data.)
Is it possible to draw the polygons as an overlay, and preserve the
islands? Maybe use another function?
I see that sp.polygon uses grid::polygonGrob, and is documented that
this function does not preserve the holes.
I find it strange that spplot itself can draw the dataset correctly, so
it must be possible to draw the polygon correctly as an overlay... or not?
If people are interested, I have a small R script available with some
test data to demonstrate the problem.
Best Regards,
Maarten Plieger
--
Maarten Plieger
KNMI, R&D Information and Observation Technology, De Bilt
(t) +31 30 2206330
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sp.polygons.png
Type: image/png
Size: 10830 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101029/8e805da2/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: spplot.png
Type: image/png
Size: 10795 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101029/8e805da2/attachment-0001.png>
More information about the R-sig-Geo
mailing list