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