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

发布于 2024-09-09 09:05:23 字数 1795 浏览 7 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄荷梦 2024-09-16 09:05:23

我假设您想要为每个选民提供单独的图像?如果是这样,我将使用 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 输出几何图形

安装 matplotlib, < a href="http://trac.gispython.org/lab/wiki/Shapely" rel="nofollow noreferrer">shapely 和 笛卡尔。修改上面的脚本,通过 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()

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

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.

公布 2024-09-16 09:05:23

下载并使用 QGIS - www.qgis.org
这个方便的开源工具运行良好,可以本地打开许多典型格式(即形状文件,最初由 ESRI 开发)。它还有一个内置的 OGR 工具。

另外,它玩起来很有趣,而且易于使用。

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.

心如荒岛 2024-09-16 09:05:23

查看 FWTools

如果您需要有关转换的帮助,还有一个有用的邮件列表

Check out FWTools.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文