Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a shapefile with a few thousand polygons, ArcGIS [9.3] (and even PostGIS). I would like to export each of those polygons into its own thumbnail image file without any real context. What is the best approach?

share|improve this question
add comment

4 Answers

up vote 5 down vote accepted

I know your question is tagged with ArcGIS but I thought it might be interesting to describe an approach that almost solves this problem using R (which is opensource and free). The idea is that you load in any shapefile, and then loop through the list of polygons printing each one out as a png. It is quite quick to produce each png ( a few seconds) - not sure how that compares to ArcGIS. The nice aspect about it is that the code is quite short.

library(maptools) # these are packages that you need to install
library(sp)

setwd("~/Dropbox/") # set working directory    
demo <- readShapePoly('pathtoShapefile/file.shp') # load data

# loop through all the polygons in the shapefile
for(i in 1:length(polygons(demo))) {     
    selected_polygon = demo[i,1]            
    thumbnail <- spplot(selected_polygon, scales=list(draw = F), colorkey=F) # remove scales and key/legend
    outFile = paste(i, '.png', sep='') # name the file using the loop counter
    png(outFile, height=200, width=200, units = 'px') # makes a png 200 x 200
    print(thumbnail); dev.off()
}

Here is an example of what is produced:

enter image description here

I'm not certain if it is possible to directly connect to PostGIS to read the data using the same approach.

share|improve this answer
    
Hi @rasto Just curious - I saw your edit and as far I understand length(polygons(demo)) and length(demo) both return the same values. Are there cases when this is not true and you should choose one over there other? –  djq Dec 13 '11 at 19:26
    
Thanks, looks relatively easy. I ran the code and the output doesn't quite match that--there's a border and no fill. After extensive googling, I couldn't see how to fix it (all I can affect is the line color) or how to reference a table column for the file name in unfamiliar R. Opens the mind though... –  thadk Dec 14 '11 at 2:38
    
Hmm, are you definitely reading the shapefile ok? To remove the border you can put the line trellis.par.set(axis.line=list(col=NA)) above spplot.... to remove the border. Glad it's of interest. –  djq Dec 14 '11 at 4:23
    
Perhaps you need to add an attribute column name in as an argument. The code above ran fine for me, but a more correct version might be to have spplot(demo, "fieldName") –  djq Dec 14 '11 at 4:31
add comment

Data Driven Pages. use the shapefile for your index layer. Set up your layout so that you have no margins and it is the size of the PNG you want. To export, follow the instructions and the bottom of this page under "How to export Data Driven Pages to other formats using ArcMap": http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Exporting_Data_Driven_Pages/00sm00000008000000/ Notice that you can modify the filename before exporting, so you can do a lot of custom combinations to get the PNG filename you want. (If you need help, post the attributes of an individual polygon and how you want the file name built.)

share|improve this answer
    
Sorry, forgot to mention, using ArcGIS 9.3. That looks like a good solution though. It shows off some of the value in the new version and another reason to upgrade. Might there be an alternative path for the legacy ArcGIS users? –  thadk Dec 11 '11 at 21:09
    
So see a few: PLTS MPS Atlas esriaustralia.com.au/esri/5203.html and my present favorite: DS Map Book edndoc.esri.com/arcobjects/9.2/CPP_VB6_VBA_VCPP_Doc/… , if you can suggest a preferred one. –  thadk Dec 11 '11 at 21:13
2  
Install DS Mapbook ( arcscripts.esri.com/details.asp?dbid=16037 ) for the same functionality in ArcGIS9.3. It works very slightly differently but you can still acheive the result you're after. –  Loz Dec 11 '11 at 21:15
add comment

You may also use ArcPy to zoom to each feature and export, see link below.

http://gis.utah.gov/code-python/python10-zoom-to-feature-export-layout

share|improve this answer
add comment

A idea but without using ArcGIS, it might be possible to do it using GDAL and more specially gdal_rasterize: http://www.gdal.org/gdal_rasterize.html

I think that you would need be able to select each polygon using a "-where" statement, so feasibility might depend on your shapefile. You would also have to write some sort of script to avoid to avoid having to export each polygon manually.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.