At last, we are ready to start working with some geospatial data. Open up a command line or terminal window and
cd into the
TM_WORLD_BORDERS-0.3 directory you unzipped earlier. Then type
python to fire up your Python interpreter.
We're going to start by loading the OGR library we installed earlier:
>>> import osgeo.ogr
We next want to open the
shapefile using OGR:
>>> shapefile = osgeo.ogr.Open("TM_WORLD_BORDERS-0.3.shp")
After executing this statement, the
shapefile variable will hold an
osgeo.ogr.Datasource object representing the geospatial data source we have opened. OGR data sources can support multiple layers of information, even though a
shapefile has only a single layer. For this reason, we next need to extract the ...