Skip to content

plotting holes of esri shape files

4 messages · sluedtke, Mathieu Rajerison, Stefan Luedtke +1 more

#
Dear friends, 


am trying to overlay a polygon data set as a SpatialPolygonDateFrame to
an existing plot. The data set has a hole in the middle, and I do not
want to have any filling in there. If a check the shape in a GIS,
everything looks fine, but using the following commands to do the plot,
the hole is filled. 

That is the code I am using, the data is attached. Thanks in advance!

Stefan



################################################################################################

library(sp)
library(rgdal)
library(raster)
library(latticeExtra)


###############################################################################################
#read the DEM from the ASCII format

dem_ascii=raster(readGDAL("./zerafshan_mod_dem.asc"))


###############################################################################################
# read additional data for printing
mask=readOGR("./", "mask_zerafshan")

###############################################################################################

#plot this stuff
plot_dem=spplot(dem_ascii, col.regions=terrain.colors(400),
colorkey=list(width=1, space="right"))+
layer(sp.polygons(mask,fill="lightgray"))

print(plot_dem) 
################################################################################################



mask_zerafshan.dbf (110 bytes) <http://r-sig-geo.2731867.n2.nabble.com/attachment/7580992/0/mask_zerafshan.dbf>
mask_zerafshan.prj (143 bytes) <http://r-sig-geo.2731867.n2.nabble.com/attachment/7580992/1/mask_zerafshan.prj>
mask_zerafshan.shp (173K) <http://r-sig-geo.2731867.n2.nabble.com/attachment/7580992/2/mask_zerafshan.shp>
mask_zerafshan.shx (150 bytes) <http://r-sig-geo.2731867.n2.nabble.com/attachment/7580992/3/mask_zerafshan.shx>
zerafshan_mod_dem.asc (1M) <http://r-sig-geo.2731867.n2.nabble.com/attachment/7580992/4/zerafshan_mod_dem.asc>




--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/plotting-holes-of-esri-shape-files-tp7580992.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
1 day later
5 days later
#
Stefan,

with the help of

http://www.stat.auckland.ac.nz/~paul/R/Paths/MurrellPaths.pdf

I corrected this in spplot. To run it, you'd need to compile from source
on svn, or source this in your R session:

https://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/sp/R/spplot.R?root=rspatial

or wait for the next release on CRAN (due soon, I hope).

spplot now also supports holes in polygons when the polygons are the
main object to plot, contain holes, and something in the background
should shine through.

Building on the example in
https://stat.ethz.ch/pipermail/r-sig-geo/2012-September/016116.html

p1 = spplot(mask, col.regions='lightgrey',
    sp.layout = list("sp.grid", as(dem_ascii, "SpatialGridDataFrame"),
    col = bpy.colors(), first = TRUE), main = "spplot of mask")
p2 = spplot(dem_ascii, col.regions=bpy.colors(), main = "spplot of dem",
    sp.layout = list("sp.polygons", mask, fill = 'lightgray', first =
FALSE))
png('spplot.png', 600, 600)
print(p1, split = c(1,1,1,2), more = TRUE)
print(p2, split = c(1,2,1,2))
dev.off()

gives http://ifgi.uni-muenster.de/~epebe_01/spplot.png as output. Mind
the legends.

With best regards,
On 09/20/2012 10:32 AM, sluedtke wrote: