2010-07-12 6 views

답변

4

각 선거구마다 별도의 이미지를 원한다고 가정하고 있습니까? 그렇다면, 내가 파이썬을 사용하여 다음과 같은 접근 방식을 취할 것입니다 :

는 GDAL/OGR를 사용하여 형상을 읽어

GDAL/OGR toolspython bindings를 설치합니다. 선거 경계를위한 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() 

출력 매끈한를 통해하기 matplotlib를 사용하여 형상, 데카르트

matplotlib, shapelydescartes를 설치합니다.

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

은 분명히 당신이 당신이 원하는 방법을 그릴 얻을 조금이를 해결하기 위해 필요하지만, 일반적인 접근 방식은 소리를해야한다 : 매끈한와 데카르트를 통해 matplob에 각 다각형을로드 위의 스크립트를 수정합니다.

2

QGIS (www.qgis.org)를 다운로드하여 사용하십시오. 이 편리한 오픈 소스 도구는 잘 작동하며 많은 일반적인 형식 (즉, 원래 ESRI에서 개발 한 모양 파일)을 엽니 다. 또한 OGR 도구가 내장되어 있습니다.

플러스하면 놀고 사용하기 쉽습니다.