Shapefiles are a fundamental data format in GIS used both for exchanging data as well as performing GIS analysis. In this section, we'll learn how to work with these files extensively. In Chapter 2, Geospatial Data, we discussed shapefiles as a format which can have many different file types associated with it. For editing shapefiles and most other operations, we are only concerned with two types: the
.shp file and the
.shp file contains the geometry while the
.dbf file contains the attributes of the corresponding geometry. For each geometry record in a shapefile, there is one
dbf record. The records aren't numbered or identified in any way. This means while adding and deleting information from a shapefile, you must be careful to remove or add a record to each file type to match.
As discussed in Chapter 4, Geospatial Python Toolbox, there are two libraries to edit shapefiles in Python. One is the Python bindings to the OGR library. The other is the