开发者

How do I convert ESRI or MapInfo GIS data to images using free tools? [closed]

开发者 https://www.devze.com 2023-01-06 23:16 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

开发者_运维问答

Closed 7 years ago.

  • We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
  • This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question

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.


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.


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.


Check out FWTools.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号