You are previewing Python Geospatial Development.
O'Reilly logo
Python Geospatial Development

Book Description

Build a complete and sophisticated mapping application from scratch using Python tools for GIS development

  • Build applications for GIS development using Python

  • Analyze and visualize Geo-Spatial data

  • Comprehensive coverage of key GIS concepts

  • Recommended best practices for storing spatial data in a database

  • Draw maps, place data points onto a map, and interact with maps

  • A practical tutorial with plenty of step-by-step instructions to help you develop a mapping application from scratch

  • In Detail

    Open Source GIS (Geographic Information System) is a growing area with the explosion of applications such as Google Maps, Google Earth, and GPS. The GIS market is growing rapidly and as a Python developer you will find yourself either wanting grounding in GIS or needing to get up to speed to do your job. In today's location-aware world, all commercial Python developers can benefit from an understanding of GIS development gained using this book.

    Working with geo-spatial data can get complicated because you are dealing with mathematical models of the Earth's surface. Since Python is a powerful programming language with high-level toolkits, it is well suited to GIS development. will familiarize you with the Python tools required for geo-spatial development such as Mapnik, which is used for mapping in Python. It introduces GIS at the basic level with a clear, detailed walkthrough of the key GIS concepts such as location, distance, units, projections, datums, and GIS data formats. We then examine a number of Python libraries and combine these with geo-spatial data to accomplish a variety of tasks. The book provides an in-depth look at the concept of storing spatial data in a database and how you can use spatial databases as tools to solve a variety of geo-spatial problems.

    It goes into the details of generating maps using the Mapnik map-rendering toolkit, and helps you to build a sophisticated web-based geo-spatial map-editing application using GeoDjango, Mapnik, and PostGIS. By the end of the book, you will be able to integrate spatial features into your applications and build a complete mapping application from scratch.

    A hands-on tutorial about accessing, manipulating, and displaying Geo-Spatial data efficiently using a range of Python tools for GIS development

    Table of Contents

    1. Python Geospatial Development
      1. Python Geospatial Development
      2. Credits
      3. About the Author
      4. About the Reviewers
      5. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      6. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      7. 1. Geo-Spatial Development Using Python
        1. Python
        2. Geo-spatial development
        3. Applications of geo-spatial development
          1. Analyzing geo-spatial data
          2. Visualizing geo-spatial data
          3. Creating a geo-spatial mash-up
        4. Recent developments
        5. Summary
      8. 2. GIS
        1. Core GIS concepts
          1. Location
          2. Distance
          3. Units
          4. Projections
            1. Cylindrical projections
            2. Conic projections
            3. Azimuthal projections
            4. The nature of map projections
          5. Coordinate systems
          6. Datums
          7. Shapes
        2. GIS data formats
        3. Working with GIS data manually
        4. Summary
      9. 3. Python Libraries for Geo-Spatial Development
        1. Reading and writing geo-spatial data
          1. GDAL/OGR
            1. GDAL design
            2. GDAL example code
            3. OGR design
            4. OGR example code
          2. Documentation
          3. Availability
        2. Dealing with projections
          1. pyproj
          2. Design
            1. Proj
            2. Geod
          3. Example code
          4. Documentation
          5. Availability
        3. Analyzing and manipulating geo-spatial data
          1. Shapely
          2. Design
          3. Example code
          4. Documentation
          5. Availability
        4. Visualizing geo-spatial data
          1. Mapnik
          2. Design
          3. Example code
          4. Documentation
          5. Availability
        5. Summary
      10. 4. Sources of Geo-Spatial Data
        1. Sources of geo-spatial data in vector format
          1. OpenStreetMap
            1. Data format
            2. Obtaining and using OpenStreetMap data
              1. The OpenStreetMap API
              2. Planet.osm
              3. Mirror sites
              4. Working with OpenStreetMap XML data
          2. TIGER
            1. Data format
            2. Obtaining and using TIGER data
          3. Digital Chart of the World
            1. Data format
            2. Available layers
            3. Obtaining and using DCW data
          4. GSHHS
            1. Data format
            2. Obtaining the GSHHS database
          5. World Borders Dataset
            1. Data format
            2. Obtaining the World Borders Dataset
        2. Sources of geo-spatial data in raster format
          1. Landsat
            1. Data format
            2. Obtaining Landsat imagery
          2. GLOBE
            1. Data format
            2. Obtaining and using GLOBE data
          3. National Elevation Dataset
            1. Data format
            2. Obtaining and using NED data
        3. Sources of other types of geo-spatial data
          1. GEOnet Names Server
            1. Data format
            2. Obtaining and using GEOnet Names Server data
          2. GNIS
            1. Data format
            2. Obtaining and using GNIS data
        4. Summary
      11. 5. Working with Geo-Spatial Data in Python
        1. Prerequisites
        2. Reading and writing geo-spatial data
          1. Task: Calculate the bounding box for each country in the world
          2. Task: Save the country bounding boxes into a Shapefile
          3. Task: Analyze height data using a digital elevation map
        3. Changing datums and projections
          1. Task: Change projections to combine Shapefiles using geographic and UTM coordinates
          2. Task: Change datums to allow older and newer TIGER data to be combined
        4. Representing and storing geo-spatial data
          1. Task: Calculate the border between Thailand and Myanmar
          2. Task: Save geometries into a text file
        5. Working with Shapely geometries
          1. Task: Identify parks in or near urban areas
        6. Converting and standardizing units of geometry and distance
          1. Task: Calculate the length of the Thai-Myanmar border
          2. Task: Find a point 132.7 kilometers west of Soshone, California
        7. Exercises
        8. Summary
      12. 6. GIS in the Database
        1. Spatially-enabled databases
        2. Spatial indexes
        3. Open source spatially-enabled databases
          1. MySQL
          2. PostGIS
            1. Installing and configuring PostGIS
            2. Using PostGIS
            3. Documentation
            4. Advanced PostGIS features
          3. SpatiaLite
            1. Installing SpatiaLite
              1. Mac OS X
              2. MS Windows
              3. Linux
            2. Installing pysqlite
            3. Accessing SpatiaLite from Python
            4. Documentation
            5. Using SpatiaLite
            6. SpatiaLite capabilities
        4. Commercial spatially-enabled databases
          1. Oracle
          2. MS SQL Server
        5. Recommended best practices
          1. Use the database to keep track of spatial references
          2. Use the appropriate spatial reference for your data
            1. Option 1: Use a database that supports geographies
            2. Option 2: Transform features as required
            3. Option 3: Transform features from the outset
            4. When to use unprojected coordinates
          3. Avoid on-the-fly transformations within a query
          4. Don't create geometries within a query
          5. Use spatial indexes appropriately
          6. Know the limits of your database's query optimizer
            1. MySQL
            2. PostGIS
            3. SpatiaLite
        6. Working with geo-spatial databases using Python
          1. Prerequisites
          2. Working with MySQL
          3. Working with PostGIS
          4. Working with SpatiaLite
          5. Speed comparisons
        7. Summary
      13. 7. Working with Spatial Data
        1. About DISTAL
        2. Designing and building the database
        3. Downloading the data
          1. World Borders Dataset
          2. GSHHS
          3. Geonames
          4. GEOnet Names Server
        4. Importing the data
          1. World Borders Dataset
          2. GSHHS
          3. US placename data
          4. Worldwide placename data
        5. Implementing the DISTAL application
          1. The "Select Country" script
          2. The "Select Area" script
            1. Calculating the bounding box
            2. Calculating the map's dimensions
            3. Setting up the datasource
              1. MySQL
              2. PostGIS
              3. SpatiaLite
            4. Rendering the map image
          3. The "Show Results" script
            1. Identifying the clicked-on point
            2. Identifying features by distance
              1. Calculating distances manually
              2. Using angular distances
              3. Using projected coordinates
              4. A hybrid approach
              5. Spatial joins
              6. Identifying points by true distance
            3. Displaying the results
        6. Application review and improvements
          1. Usability
          2. Quality
            1. Placename issues
            2. Lat/Long coordinate problems
          3. Performance
            1. Finding the problem
            2. Improving performance
            3. Calculating the tiled shorelines
            4. Using the tiled shorelines
            5. Analyzing the performance improvement
            6. Further performance improvements
            7. Scalability
        7. Summary
      14. 8. Using Python and Mapnik to Generate Maps
        1. Introducing Mapnik
        2. Creating an example map
        3. Mapnik in depth
          1. Data sources
            1. Shapefile
            2. PostGIS
            3. GDAL
            4. OGR
            5. SQLite
            6. OSM
            7. PointDatasource
          2. Rules, filters, and styles
            1. Filters
            2. Scale denominators
            3. "Else" rules
          3. Symbolizers
            1. Drawing lines
              1. LineSymbolizer
                1. Line color
                2. Line width
                3. Opacity
                4. Line caps
                5. Line joins
                6. Dashed and dotted lines
              2. LinePatternSymbolizer
            2. Drawing polygons
              1. PolygonSymbolizer
                1. Fill color
                2. Opacity
                3. Gamma correction
              2. PolygonPatternSymbolizer
            3. Drawing labels
              1. TextSymbolizer
                1. Specifying the text to be displayed
                2. Selecting a suitable font
                3. Drawing semi-transparent text
                4. Controlling text placement
                5. Repeating labels
                6. Controlling text overlap
                7. Drawing text on a dark background
                8. Adjusting the position of the text
                9. Splitting labels across multiple lines
                10. Controlling character and line spacing
                11. Controlling capitalization
            4. Drawing points
              1. PointSymbolizer
              2. ShieldSymbolizer
            5. Drawing raster images
            6. Using colors
          4. Maps and layers
            1. Map attributes and methods
            2. Layer attributes and methods
          5. Map rendering
        4. MapGenerator revisited
          1. The MapGenerator's interface
          2. Creating the main map layer
          3. Displaying points on the map
          4. Rendering the map
          5. What the map generator teaches us
        5. Map definition files
        6. Summary
      15. 9. Web Frameworks for Python Geo-Spatial Development
        1. Web application concepts
          1. Web application architecture
            1. A bare-bones approach
            2. Web application stacks
            3. Web application frameworks
            4. Web services
          2. Map rendering
          3. Tile caching
          4. Web servers
          5. User interface libraries
          6. The "slippy map" stack
          7. The geo-spatial web application stack
        2. Protocols
          1. The Web Map Service (WMS) protocol
            1. WMS-C
          2. The Web Feature Service (WFS) protocol
          3. The TMS (Tile Map Service) protocol
        3. Tools
          1. Tile caching
            1. TileCache
            2. mod_tile
            3. TileLite
          2. User interface libraries
            1. OpenLayers
            2. Mapiator
          3. Web application frameworks
            1. GeoDjango
              1. Understanding Django
              2. GeoDjango
            2. MapFish
            3. TurboGears
        4. Summary
      16. 10. Putting it All Together: A Complete Mapping Application
        1. About the ShapeEditor
        2. Designing the application
          1. Importing a Shapefile
          2. Selecting a feature
          3. Editing a feature
          4. Exporting a Shapefile
        3. Prerequisites
        4. The structure of a Django application
          1. Models
          2. Views
          3. Templates
        5. Setting up the database
        6. Setting up the GeoDjango project
        7. Setting up the ShapeEditor application
        8. Defining the data models
          1. Shapefile
          2. Attribute
          3. Feature
          4. AttributeValue
          5. The models.py file
        9. Playing with the admin system
        10. Summary
      17. 11. ShapeEditor: Implementing List View, Import, and Export
        1. Implementing the "List Shapefiles" view
        2. Importing Shapefiles
          1. The "import shapefile" form
          2. Extracting the uploaded Shapefile
          3. Importing the Shapefile's contents
            1. Open the Shapefile
            2. Add the Shapefile object to the database
            3. Define the Shapefile's attributes
            4. Store the Shapefile's features
            5. Store the Shapefile's attributes
          4. Cleaning up
        3. Exporting Shapefiles
          1. Define the OGR Shapefile
          2. Saving the features into the Shapefile
          3. Saving the attributes into the Shapefile
          4. Compressing the Shapefile
          5. Deleting temporary files
          6. Returning the ZIP archive to the user
        4. Summary
      18. 12. ShapeEditor: Selecting and Editing Features
        1. Selecting a feature to edit
          1. Implementing the Tile Map Server
            1. Setting up the base map
            2. Tile rendering
              1. Parsing the query parameters
              2. Setting up the map
              3. Defining the base layer
              4. Defining the feature layer
              5. Rendering the Map Tile
              6. Completing the Tile Map Server
          2. Using OpenLayers to display the map
          3. Intercepting mouse clicks
          4. Implementing the "find feature" view
        2. Editing features
        3. Adding features
        4. Deleting features
        5. Deleting Shapefiles
        6. Using ShapeEditor
        7. Further improvements and enhancements
        8. Summary