Table of Contents for
Python Geospatial Development - Third Edition

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Python Geospatial Development - Third Edition by Erik Westra Published by Packt Publishing, 2016
  1. Cover
  2. Table of Contents
  3. Python Geospatial Development Third Edition
  4. Python Geospatial Development Third Edition
  5. Credits
  6. About the Author
  7. About the Reviewer
  8. www.PacktPub.com
  9. Preface
  10. What you need for this book
  11. Who this book is for
  12. Conventions
  13. Reader feedback
  14. Customer support
  15. 1. Geospatial Development Using Python
  16. Geospatial development
  17. Applications of geospatial development
  18. Recent developments
  19. Summary
  20. 2. GIS
  21. GIS data formats
  22. Working with GIS data manually
  23. Summary
  24. 3. Python Libraries for Geospatial Development
  25. Dealing with projections
  26. Analyzing and manipulating Geospatial data
  27. Visualizing geospatial data
  28. Summary
  29. 4. Sources of Geospatial Data
  30. Sources of geospatial data in raster format
  31. Sources of other types of geospatial data
  32. Choosing your geospatial data source
  33. Summary
  34. 5. Working with Geospatial Data in Python
  35. Working with geospatial data
  36. Changing datums and projections
  37. Performing geospatial calculations
  38. Converting and standardizing units of geometry and distance
  39. Exercises
  40. Summary
  41. 6. Spatial Databases
  42. Spatial indexes
  43. Introducing PostGIS
  44. Setting up a database
  45. Using PostGIS
  46. Recommended best practices
  47. Summary
  48. 7. Using Python and Mapnik to Generate Maps
  49. Creating an example map
  50. Mapnik concepts
  51. Summary
  52. 8. Working with Spatial Data
  53. Designing and building the database
  54. Downloading and importing the data
  55. Implementing the DISTAL application
  56. Using DISTAL
  57. Summary
  58. 9. Improving the DISTAL Application
  59. Dealing with the scale problem
  60. Performance
  61. Summary
  62. 10. Tools for Web-based Geospatial Development
  63. A closer look at three specific tools and techniques
  64. Summary
  65. 11. Putting It All Together – a Complete Mapping System
  66. Designing the ShapeEditor
  67. Prerequisites
  68. Setting up the database
  69. Setting up the ShapeEditor project
  70. Defining the ShapeEditor's applications
  71. Creating the shared application
  72. Defining the data models
  73. Playing with the admin system
  74. Summary
  75. 12. ShapeEditor – Importing and Exporting Shapefiles
  76. Importing shapefiles
  77. Exporting shapefiles
  78. Summary
  79. 13. ShapeEditor – Selecting and Editing Features
  80. Editing features
  81. Adding features
  82. Deleting features
  83. Deleting shapefiles
  84. Using the ShapeEditor
  85. Further improvements and enhancements
  86. Summary
  87. Index

Exercises

If you are interested in exploring the techniques used in this chapter further, you might like to challenge yourself with the following tasks:

  • Change the bounding box calculation to exclude outlying islands.

    Tip

    Hint

    You can split each country's MultiPolygon into individual Polygon objects and then check the area of each polygon to exclude those that are smaller than a given total value.

  • Use the World Borders Dataset to create a new shapefile, where each country is represented by a single Point geometry containing the geographical center of each country.

    Tip

    Hint

    You can start with the country bounding boxes we calculated earlier and then calculate the midpoint using this:

    midLat = (minLat + maxLat) / 2
    midLong = (minLong + maxLong) / 2

    For an extra challenge, you could use Shapely's centroid() method to calculate a more accurate representation of each country's center. To do this, you would have to convert the country's outline into a Shapely geometry, calculate the centroid, and then convert the centroid back into an OGR geometry before saving it into the output shapefile.

  • Extend the histogram example to only include height values that fall inside a selected country's outline.

    Tip

    Hint

    Implementing this in an efficient way can be difficult. A good approach would be to identify the bounding box for each of the polygons that make up the country's outline and then iterate over the DEM coordinates within that bounding box. You could then check to see whether a given coordinate is actually inside the country's outline using polygon.contains(point) and only add the height to the histogram if the point is indeed within the country's outline.

  • Optimize the example in the identify nearby parks section so that it can work quickly with larger data sets.

    Tip

    Hint

    One possibility might be to calculate the rectangular bounding box around each urban area and then expand that bounding box north, south, east, and west by the desired angular distance. You could then quickly exclude all the points which aren't in that bounding box before making the time-consuming call to polygon.contains(point).

    Another way of optimizing this program is to exclude urban areas outside of California. To do this, you would have to find a shapefile of US states, download the outline for California, and only include urban areas which lie (fully or partially) inside the state boundary.

  • Calculate the total length of the coastline of the United Kingdom.

    Tip

    Hint

    Remember that a country outline is a MultiPolygon, where each Polygon in the MultiPolygon represents a single island. You will need to extract the exterior ring from each of these individual island polygons and calculate the total length of the line segments within that exterior ring. You can then total the length of each individual island to get the length of the entire country's coastline.

  • Design your own reusable library of geospatial functions that build on OGR, GDAL, Shapely, and pyproj to perform common operations such as those discussed in this chapter.

    Tip

    Hint

    Writing your own reusable library modules is a common programming tactic. Think about the various tasks we solved in this chapter and how they can be turned into generic library functions. For example, you might like to write a function named calcLineStringLength(), which takes a LineString and returns the total length of the LineString's segments, optionally transforming the LineString's coordinates into lat/long values before calling geod.inv().

    You could then write a calcPolygonOutlineLength() function, which uses calcLineStringLength() to calculate the length of a polygon's outer ring.