如何使用免费工具将ESRI或MapInfo GIS数据转换为图像?

4
澳大利亚选举委员会提供免费的ESRI和MapInfo格式的GIS图层,包括澳大利亚选区边界,可供下载。我想使用免费工具将这些数据转换为缩略多边形图像。
3个回答

4

我假设你想为每个选区单独使用一张图片?如果是这样,我建议使用Python采用以下方法:

使用GDAL/OGR读取几何信息:

安装GDAL/OGR工具及其Python绑定。下载选举边界的ESRI shapefile文件。确保您可以使用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()

使用shapely和descartes通过matplotlib输出几何图形

安装matplotlibshapelydescartes。修改以上脚本,通过shapely和descartes将每个多边形加载到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()

显然,您需要对此进行一些修复,以使其按照您的要求绘制,但一般的方法应该是可行的。


2

下载并使用QGIS - www.qgis.org 这个方便的开源工具运行良好,并能够本地打开许多常见格式(例如由ESRI开发的shape文件)。它还内置了OGR工具。

此外,它非常有趣且易于使用。


1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接