views:

89

answers:

3

The Australian Electoral Commission has free ESRI and MapInfo formate GIS layers of Australian electoral boundaries for download. I want to convert this data to a thumbnail polygon image using a free tool.

+1  A: 

Check out FWTools.

There is also a helpful mailing list if you need help on the conversions.

codekaizen
+2  A: 

I'm assuming you want a separate image for each electorate? If so, I would take the following approach using python:

Read the geometry using GDAL/OGR:

Install the GDAL/OGR tools and their python bindings. Download the ESRI shapefile for the electoral boundaries. Ensure you can read the polygon geometry using OGR:

import sys
import ogr

ds = ogr.Open( "/path/to/boundary/file.shp" )
if ds is None:
    print "Open failed.\n"
    sys.exit( 1 )

lyr = ds.GetLayer(0)

lyr.ResetReading()

feat = lyr.GetNextFeature()
while feat is not None:
    geom = feat.GetGeometryRef()
    if geom is None or geom.GetGeometryType() != ogr.wkbPolygon:
        print "no poly geometry\n"

    feat = lyr.GetNextFeature()

ds.Destroy()

Output the geometry using matplotlib via shapely, descartes

Install matplotlib, shapely and descartes. Modify the above script to load each polygon into matplob via shapely and descartes:

import sys
import ogr
from shapely.wkb import loads
from descartes import PolygonPatch
from matplotlib import pyplot


ds = ogr.Open( "/path/to/boundary/file.shp" )
if ds is None:
    print "Open failed.\n"
    sys.exit( 1 )

lyr = ds.GetLayer(0)

lyr.ResetReading()

feat = lyr.GetNextFeature()
while feat is not None:
    geom = feat.GetGeometryRef()
    if geom is None or geom.GetGeometryType() != ogr.wkbPolygon:
        print "no poly geometry\n"
    else:
      # create matplotlib figure:
      fig = pyplot.figure(1, figsize = [10,10], dpi = 300)   #create 10x10 figure
      ax = fig.addsubplot(111)    #Add the map frame (single plot)

      # add polygon:
      patch = PolygonPatch(loads(feature.GetGeometryRef().ExportToWkb()), plus colour and line considerations)
      ax.addpatch(patch)   # simply add the patch to the subplot

      # set plot vars
      ax.set_xlim(get xmin and xmax values from data)
      ax.set_ylim(get ymin and ymax values from data)
      ax.set_aspect(1)

      # save as image
      pyplot.savefig('somefile.png', some arguments you like)¶

    feat = lyr.GetNextFeature()

ds.Destroy()

Obviously you need to fix this up a bit to get it to draw how you want, but the general approach should be sound.

fmark
+1  A: 

Download and use QGIS - www.qgis.org This handy open source tool works well, and opens many typical formats natively (i.e. shape files, originally developed by ESRI) It also has a built-in OGR tool.

Plus it's just fun to play with, and easy to use.