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.
Answer
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')
No comments:
Post a Comment