root/Shapely/trunk/examples/world.py

Revision 749 (checked in by seang, 2 years ago)

Add example of connecting OGR to matplotlib through shapely and numpy

  • Property svn:eol-style set to native
Line 
1 import ogr
2 import pylab
3 from numpy import asarray
4
5 from shapely.wkb import loads
6
7 source = ogr.Open("/var/gis/data/world/world_borders.shp")
8 borders = source.GetLayerByName("world_borders")
9
10 fig = pylab.figure(1, figsize=(4,2), dpi=300)
11
12 while 1:
13     feature = borders.GetNextFeature()
14     if not feature:
15         break
16    
17     geom = loads(feature.GetGeometryRef().ExportToWkb())
18     a = asarray(geom)
19     pylab.plot(a[:,0], a[:,1])
20
21 pylab.show()
Note: See TracBrowser for help on using the browser.