[R-sig-Geo] Speeding up SpatialPolygonsDataFrame - possibly by making it less detailed

Peter Ellis (Wellington) Peter.Ellis at med.govt.nz
Fri Jun 15 08:28:22 CEST 2012


Hi

I am using the digital boundaries for New Zealand shapefiles available from Statistics New Zealand at http://www.stats.govt.nz/browse_for_stats/people_and_communities/Geographic-areas/digital-boundary-files.aspx.

The aim is to use these to produce choropleth maps.

I have no problem in doing this using code based on Hadley Wickham's https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles . However, manipulating the shapefiles into something I can merge with statistics is painfully slow.  For example, to draw the 20 or so regional council boundaries with the code below involves creating a data frame (REGC12.df) with 3.2 million rows.  It produces a lovely looking graphic I could expand up to very large size, but is a pain in the neck for playing around with.

Is there a function in R that can take an object of class sp::SpatialPolygonsDataFrame and reduce the fine level of detail, while keeping the basic shapes of the polygons to some specified degree of approximation?  Or is this a job for a specialist GIS package?

Example code:

REGC12 <- readOGR(dsn=".", layer="REGC12")
REGC12 at data$id <- rownames(REGC12 at data)
REGC12.points <- fortify(REGC12, region="id")
REGC12.df <- join(REGC12.points, REGC12 at data, by="id")

ggplot(REGC12.df) +
	aes(long, lat, group=group, fill=NAME) +
	geom_polygon()

thanks
PE

Peter Ellis | Manager Research and Evaluation 
Tourism, Events and Consumer Affairs Branch
Ministry of Economic Development | Manutū Ōhanga
33 Bowen Street | PO Box 1473 | Wellington 6011 | New Zealand
p. 04 498 7448| mb. 029 771 0135 | www.tourismresearch.govt.nz | www.med.govt.nz
 

newzealand.govt.nz - connecting you to New Zealand central & local government services

Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer.



More information about the R-sig-Geo mailing list