Exporting shapefiles

We next need to implement the ability to export a shapefile. The process of exporting a shapefile is basically the reverse of the importing logic, and involves the following steps:

  1. Create an OGR shapefile to receive the exported data.
  2. Save the features and their attributes into the shapefile.
  3. Compress the shapefile into a ZIP archive.
  4. Delete our temporary files.
  5. Send the ZIP file back to the user's web browser.

All this work will take place in the shapefileIO.py module, with help from some utils.py functions. Before we begin, let's define the export_data() function so that we have somewhere to place our code. Edit shapefileIO.py, and add the following new function:

def export_data(shapefile):
    return "More to come..."

While we're at ...

Get Python Geospatial Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.