~meshing/meshing/urop

« back to all changes in this revision

Viewing changes to shape/getCountries.py

  • Committer: Adam Candy
  • Date: 2012-07-06 15:30:52 UTC
  • Revision ID: adam.candy@imperial.ac.uk-20120706153052-63q7bbtir43ts2vp
Import of Varun's branch lp:~varun-verma11/+junk/gshhstoshp into the folder 'shape'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import osgeo.ogr
 
2
 
 
3
shapefile = osgeo.ogr.Open("TM_WORLD_BORDERS-0.3.shp")
 
4
layer = shapefile.GetLayer(0)
 
5
countries = [] # List of (code,name,minLat,maxLat,
 
6
          # minLong,maxLong) tuples.
 
7
for i in range(layer.GetFeatureCount()):
 
8
   feature = layer.GetFeature(i)
 
9
   countryCode = feature.GetField("ISO3")
 
10
   countryName = feature.GetField("NAME")
 
11
   geometry = feature.GetGeometryRef()
 
12
   minLong,maxLong,minLat,maxLat = geometry.GetEnvelope()
 
13
   countries.append((countryName, countryCode,
 
14
      minLat, maxLat, minLong, maxLong))
 
15
   countries.sort()
 
16
for name,code,minLat,maxLat,minLong,maxLong in countries:
 
17
   print "%s (%s) lat=%0.4f..%0.4f, long=%0.4f..%0.4f" \
 
18
     % (name, code,minLat, maxLat,minLong, maxLong)