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.

  • 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. Nov 1 '10 at 16:22
  • Good points, edits applied.
    – user890
    Nov 2 '10 at 1:02

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.


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.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()

  • 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

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.


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.


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.


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


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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