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.

Can anyone suggest a quick (and preferably open source) way to create an image from a shapefile. For example, I have a shapefile containing parcel boundaries, I want to create a png file depicting these parcels. The symbology required for this image will be bare-bones (solid outline and fill).

I know that shp2img from MapServer would do the trick. I am just curious if there is anything else available.

Any references to pre-compiled tools or api's/sdks welcome.

share|improve this question
    
Perhaps this question could be retitled "Creating simple image from vector data (eg Shape)" so that it's a more generic question? You still get your answer, but there's more of an incentive for other folk to view/answer too. I'd also suggest changing "and open source" to "preferably open source" for the same reason. –  Mark Ireland Nov 1 '10 at 16:22
    
Good points, edits applied. –  user890 Nov 2 '10 at 1:02

6 Answers 6

up vote 14 down vote accepted

You can use python (modules: shapley, GDAL/OGR, numpy, matplotlib) and GDAL/OGR to draw image from almost any vector data souce, in you case shapefile. Maybe this will help you.

Example:

from shapely.geometry import Polygon
from shapely.wkb import loads
from osgeo import ogr
from matplotlib import pyplot

def drawPoligon(poligon,graf):
    xLista,yLista = poligon.exterior.xy
    graf.fill(xLista,yLista,"y")
    graf.plot(xLista,yLista, "k-")

fig = pyplot.figure(figsize=(4, 4),dpi=180)
ax = fig.add_subplot(111)
file1 = ogr.Open("d:\\temp02\\datafile.shp")

layer = file1.GetLayerByName("datafile")
parcel = layer.GetNextFeature()

while parcel is not None:
    geometryParcel = loads(parcel.GetGeometryRef().ExportToWkb())
    drawPoligon(geometryParcel , ax)
    parcel = layer.GetNextFeature()


pyplot.savefig('datafile.png')
share|improve this answer
    
Exactly what I needed. This approach is especially useful since it is not tied to shapefile data sources. Thanks. –  user890 Nov 2 '10 at 0:58

GeoTools http://geotools.org contains all the bits you need to do this, I'd be surprised if someone doesn't already have the code somewhere to do this.

share|improve this answer

I guess that it depends on what you mean by quick. Do you mean something easy to install or something that is easy to use once you have it installed.

You mention MapServer and shp2img. If you have MapServer installed, you could probably write a pretty simple MapScript (Python or php) script that would loop through a folder of shapefiles and render images of them with default symbology.

share|improve this answer

Quick, cheap (and dirty):

  • open and symbolise your shape file with a qgis, udig, openjump or any other free GIS,
  • press "print screen" button,
  • paste in gimp and save as png file.

Drawback: of course, the image resolution cannot be finer than the screen's one.

share|improve this answer

This question is already answered, but I'll put some additional information, as it might be helpful for someone. This mailing list explains how to convet SHP to Images, and currently I am working with it to complete the task: http://lists.osgeo.org/pipermail/qgis-user/2010-October/010239.html

share|improve this answer

I documented this soltuion a little while back using two different methods.

One using pure Python which will run anywhere Python does: http://geospatialpython.com/2010/12/rasterizing-shapefiles-2-pure-python.html

And one using the Python Imaging Library: http://geospatialpython.com/2010/12/rasterizing-shapefiles.html

share|improve this answer

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.