Skip to content
Back to formatted view

Raw Message

Message-ID: <49F50E8E.3040605@wildintellect.com>
Date: 2009-04-27T01:46:54Z
From: Alex Mandel
Subject: zip code map - huge files!
In-Reply-To: <e303ddae0904261306q24cbc600qa68c798ba9d39346@mail.gmail.com>

Enrico Rossi wrote:
> Hello,
> 
> I have some data at the zip code level, and I'm using the shapefiles
> downloaded from the Census TigerLine website
> (http://www2.census.gov/geo/tiger/TIGER2008/tl_2008_us_zcta5.zip) to
> plot a shaded map of the US. However, the files generated in this way
> are enormous, and take a long time to process, even on a fast machine
> with lots of memory. I'm wondering if there's a more efficient way to
> do this. Maybe rasterize before plotting somehow?
> 
> If anyone on this list has experience working with zip-level data, I'd
> appreciate any advice.
> 
> Here's some example code like what I'm doing:
> 
> # This works, and produces a 1.2GB PDF file! After it's done, I can
> rasterize it using gs to reduce file size, but it takes almost an hour
> library(maptools)
> zip<-readShapePoly("tl_2008_us_zcta5")  # This takes a while!
> val<-runif(length(zip[[1]])) # there are about 32000 zip codes
> pdf("zipplot.pdf")
> plot(zip,xlim=c(-130,-65),ylim=c(20,50),col=grey(val),lty=0)
> dev.off()
> system("gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300
> -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dMaxStripSize=8192
> -sOutputFile=zipplot.png zipplot.pdf")
> 
> # I've tried plotting directly to png, but it just seems to hang, my
> patience ran out after two hours
> png("zipplot.png")
> plot(zip,xlim=c(-130,-65),ylim=c(20,50),col=grey(val),lty=0)
> dev.off()
> 
> # This also takes too long, I never got any output out of it
> library(lattice)
> zip$val<-val
> pdf("zipplot2.pdf")
> spplot(zip,"val",xlim=c(-130,-65),ylim=c(20,50),lty=0)
> dev.off()
> 
> Many thanks!
> Enrico Rossi
> 

Enrico,

What size map are you making, and how is it going to be used?
Zip code seems like a fairly small size area to plot over such a large
area, especially when you think about small cities that are only 5-10
miles wide but have 2-4 zip codes.

Have you considered aggregating neighbors based on some geographic or
other parameter.

Alex