澳大利亚选举委员会具有免费和ESRI MapInfo甲酸GIS层的澳大利亚选举的边界 下载.我想要转换这些数据,以缩略多边形图像的使用免费工具。

有帮助吗?

解决方案

我假设你想要一个单独的图像对每个选民?如果是这样,我将采取以下方法使用蟒蛇:

阅读几何使用GDAL/OGR:

安装的 GDAL/OGR工具 和他们的 蟒蛇绑定的.下载ESRI形状的选举界限。确保你可以读取多边形几何使用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()

输出的几何使用matplotlib通过匀称的,笛卡尔

安装 matplotlib, 身材匀称笛卡尔.修改上述脚本以负载各多边形成matplob通过匀称和笛卡尔:

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

很明显你需要修复这一点得到它提请你怎么想的,但一般的做法应该是声音。

其他提示

下载和使用QGIS-www.qgis.org 这个方便的开放源码工具的工作良好,并打开了许多典型的格式本身(即形状的文件,最初是由ESRI)它也有一个内置的OGR工具。

加上这只是好玩,并且容易使用。

检查了 FWTools.

还有一个 有用的邮件列表 如果你需要帮助的转换。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top