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.

A colleague and I recently released an Open Source project called Mapoteca which is a set of Python Scripts that integrates with a GDAL/FWTools installation allowing a full walk-through of directories looking for spatial data and extracting extent, geometry, number of elements, projection and user writing it into a csv file. We are working on the part that describes the DBF files associated and we wanted to generate a thumbnail image of each shapefile, do you know of a way to generate these thumbnails in jpeg or png using Python?

share|improve this question
add comment

6 Answers

You could integrate Mapnik for rendering the images.

share|improve this answer
add comment

I had posted a question on creating images from vector data that you might find useful. The accepted answer, the combination of shapely, ogr, matplotlib, and numpy seems like it would work nicely for you.

share|improve this answer
add comment

The simplest way would be to call gdal_rasterize using subprocess.call(), but I suspect it doesn't do any interpolation so it would alias to the point of illegibility if you generated a thumbnail-sized image straight from the data. So you should generate a "reasonably sized"* temporary image and use the Python image library to scale it to the size you want.

But I expect the biggest problem will be on which attribute(s) will you base your styling on? Shapefiles have no inherent display information as I'm sure you're aware, so you will need to find a way of deciding which colours to use. gdal_rasterize does give you the capability to do this, but the choice is normally based on domain-specific knowledge. To have a generic tool, you're going to have to have a generic styling scheme.

*This too is something for which you may have to make a few hard-coded rules. Perhaps start with an ideal pixel size (say 10m per pixel), and increase that if the resulting image is too large to be practical.

share|improve this answer
add comment

Mapnik and gdal_rasterize are good options. I usually create a simple mapfile styled however I want and then use Mapserver's shp2img executable. There are good tutorials on creating mapfiles.

share|improve this answer
add comment

Just for the sake of completeness - mapserver can also render good looking maps from a range of base data, on commandline using the shp2img utility. Again, you will need to decide on a very generic, very simple style that fits your purposes.

share|improve this answer
add comment

Another related question: Repetitive automated mapping: which platform? There mapserver was suggested.

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.