I am working thru "Python Geospatial Programming" and I have a problem in a program in Chapter 6 that I cannot seem to solve.
The small program:
import osgeo.ogr shapefile = osgeo.ogr.Open("TM_WORLD_BORDERS-0.3.shp") layer = shapefile.GetLayer(0) numberFeatures = layer.GetFeatureCount() countries =  # List of (code, name, minLat, maxLat, # minLong, maxLong) tuples. for i in range(numberFeatures): feature = layer.GetFeature(i) countryCode = feature.GetField("ISO3") countryName = feature.GetField("NAME") geometry = feature.GetGeometryRef() minLong, maxLong, minLat, maxLat = geometry.GetEnvelope() countries.append((countryName, countryCode, minLat, maxLat, minLong, maxLong)) countries.sort() for name, code, minLat, maxLat, minLong, maxLong in countries: print "%s (%s) lat=%0.4f..%0.4f, long=%0.4f..%0.4f" % (name, code, minLat, maxLat, minLong, maxLong)
It works perfect if I do not use the "NAME" attribute (field), for example AREA or POP15 which all come as attributes of the world borders shp file. NAME is a string field of 50 characters and all looks good in the dbf file.
The program does not issue any error codes and it comes back as successful but it does not go beyond that line.