In the final three chapters of this book, we will bring together all the topics discussed in previous chapters to implement a sophisticated web-based mapping application called ShapeEditor. In this chapter, we will cover:
As we have seen, Shapefiles are commonly used to store, make available, and transfer geo-spatial data. We have worked with Shapefiles extensively in this book, obtaining freely-available geo-spatial data in Shapefile format, writing programs to load data from a Shapefile, and creating Shapefiles programmatically.
While it is easy enough to edit the attributes associated with a Shapefile's features, editing the features themselves is a lot more complicated. One approach would be to install a GIS system, use it to import the data, make changes, and then export the data into another Shapefile. While this works, it is hardly convenient if all you want to do is make a few changes to a Shapefile's features. It would be much easier if we had a web application specifically designed for editing Shapefiles.
This is precisely what we are going to implement: a web-based Shapefile editor. Rather unimaginatively, we'll call this program ShapeEditor.
The following flowchart depicts the ShapeEditor's basic workflow:
The user starts by importing a Shapefile using the ShapeEditor's web interface:
Our ShapeEditor implementation wasn't chosen for its good looks; instead, it concentrates on getting the features working. It would be easy to add stylesheets and edit the HTML templates to improve the appearance of the application, but doing so would make the code harder to understand. This is why we've taken such a minimalist approach to the user interface. Making it pretty is an exercise left to the reader.
Once the Shapefile has been imported, the user can view the Shapefile's features on a map, and can select a feature by clicking on it. In this case, we have imported the World Borders Dataset used several times throughout this book:
The user can then edit the selected feature's geometry, as well as see a list of the attributes associated with that feature:
Once the user has finished making changes to the Shapefile, he or she can export the Shapefile again by clicking on the Export hyperlink on the main page:
That pretty much covers all of the ShapeEditor's functionality. It's a comparatively simple application, but it can be very useful if you need to work with geo-spatial data in Shapefile format. And, of course, through the process of implementing the ShapeEditor, you will learn how to write your own complex geo-spatial web applications using GeoDjango.
3.16.139.8