You are previewing Python Geospatial Development - Second Edition.
O'Reilly logo
Python Geospatial Development - Second Edition

Book Description

If you’re experienced in Python here’s an opportunity to get deep into Geospatial development, linking data to global locations. No prior knowledge required – this book takes you through it all, step by step.

  • Build your own complete and sophisticated mapping applications in Python.

  • Walks you through the process of building your own online system for viewing and editing geospatial data

  • Practical, hands-on tutorial that teaches you all about geospatial development in Python

  • In Detail

    Geospatial development links your data to places on the Earth’s surface. Writing geospatial programs involves tasks such as grouping data by location, storing and analyzing large amounts of spatial information, performing complex geospatial calculations, and drawing colorful interactive maps. In order to do this well, you’ll need appropriate tools and techniques, as well as a thorough understanding of geospatial concepts such as map projections, datums and coordinate systems.

    Python Geospatial Development - Second Edition teaches you everything you need to know about writing geospatial applications using Python. No prior knowledge of geospatial concepts, tools or techniques is required. The book guides you through the process of installing and using various toolkits, obtaining geospatial data for use in your programs, and building complete and sophisticated geospatial applications in Python.

    Python Geospatial Development teaches you everything you need to know about writing geospatial applications using Python. No prior knowledge of geospatial concepts, tools or techniques is required. The book guides you through the process of installing and using various toolkits, obtaining geospatial data for use in your programs, and building complete and sophisticated geospatial applications in Python.

    This book provides an overview of the major geospatial concepts, data sources and toolkits. It teaches you how to store and access spatial data using Python, how to perform a range of spatial calculations, and how to store spatial data in a database. Because maps are such an important aspect of geospatial programming, the book teaches you how to build your own “slippy map” interface within a web application, and finishes with the detailed construction of a geospatial data editor using Geodjango.

    Whether you want to write quick utilities to solve spatial problems, or develop sophisticated web applications based around maps and geospatial data, this book includes everything you need to know.

    Table of Contents

    1. Python Geospatial Development
      1. Table of Contents
      2. Python Geospatial Development
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. 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. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Geospatial Development Using Python
        1. Python
        2. Geospatial development
        3. Applications of geospatial development
          1. Analyzing geospatial data
          2. Visualizing geospatial data
          3. Creating a geospatial mash-up
        4. Recent developments
        5. Summary
      9. 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
      10. 3. Python Libraries for Geospatial Development
        1. Reading and writing geospatial 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 geospatial data
          1. Shapely
          2. Design
          3. Example code
          4. Documentation
          5. Availability
        4. Visualizing geospatial data
          1. Mapnik
          2. Design
          3. Example code
          4. Documentation
          5. Availability
        5. Summary
      11. 4. Sources of Geospatial Data
        1. Sources of geospatial 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 and extracts
              4. Working with OpenStreetMap data
          2. TIGER
            1. Data format
            2. Obtaining and using TIGER data
          3. Natural Earth
            1. Data format
            2. Obtaining and using Natural Earth vector data
          4. Global, self-consistent, hierarchical, high-resolution shoreline database (GSHHS)
            1. Data format
            2. Obtaining the GSHHS database
          5. World Borders Dataset
            1. Data format
            2. Obtaining World Borders Dataset
        2. Sources of geospatial data in raster format
          1. Landsat
            1. Data format
            2. Obtaining Landsat imagery
          2. Natural Earth
            1. Data format
            2. Obtaining and using Natural Earth raster data
          3. Global Land One-kilometer Base Elevation (GLOBE)
            1. Data format
            2. Obtaining and using GLOBE data
          4. National Elevation Dataset (NED)
            1. Data format
            2. Obtaining and using NED data
        3. Sources of other types of geospatial data
          1. GEOnet Names Server
            1. Data format
            2. Obtaining and using GEOnet Names Server data
          2. Geographic Names Information System (GNIS)
            1. Data format
            2. Obtaining and using GNIS Data
        4. Choosing your geospatial data source
        5. Summary
      12. 5. Working with Geospatial Data in Python
        1. Pre-requisites
        2. Reading and writing geospatial 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 geospatial data
          1. Task – define the border between Thailand and Myanmar
          2. Task – save geometries into a text file
        5. Performing geospatial calculations
          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
      13. 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
            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. Using the database to keep track of spatial references
          2. Using the appropriate spatial reference for your data
            1. Option 1 – using a database that supports geographies
            2. Option 2 – transforming features as required
            3. Option 3 – transforming features from the outset
            4. When to use unprojected coordinates
          3. Avoiding on-the-fly transformations within a query
          4. Don't create geometries within a query
            1. Using spatial indexes appropriately
          5. Knowing the limits of your database's query optimizer
            1. MySQL
            2. PostGIS
            3. SpatiaLite
        6. Working with geospatial databases using python
          1. Prerequisites
          2. Working with MySQL
          3. Working with PostGIS
          4. Working with SpatiaLite
          5. Comparing the databases
        7. Summary
      14. 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. GNIS
          4. GEOnet Names Server
        4. Importing the data
          1. World Borders Dataset
          2. GSHHS
          3. US place name data
          4. Worldwide place name data
        5. Implementing the DISTAL application
          1. The shared "database" module
          2. The "select country" script
          3. The "select area" script
            1. Calculating the bounding box
            2. Calculating the map's dimensions
            3. Setting up the data source
            4. Rendering the map image
          4. 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
            3. Displaying the results
        6. Application review and improvements
          1. Usability
          2. Quality
            1. Place name issues
            2. Lat/Long coordinate problems
          3. Performance
            1. Finding the problem
            2. Improving performance
            3. Calculating the tiled shorelines
            4. Using tiled shorelines
            5. Analyzing the performance improvement
        7. Summary
      15. 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. MemoryDatasource
          2. Rules, filters, and styles
            1. Filters
            2. Scale denominators
            3. "Else" rules
            4. "Also" 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
                7. Drawing roads and other complex linear features
              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
                12. Advanced text placement and formatting
            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 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
      16. 9. Putting It All Together – a Complete Mapping System
        1. About ShapeEditor
        2. Designing ShapeEditor
          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. URL dispatching
          4. Templates
        5. Setting up the database
        6. Setting up the ShapeEditor project
        7. Defining the ShapeEditor's applications
        8. Creating the shared application
        9. Defining the data models
          1. Shapefile
          2. Attribute
          3. Feature
          4. AttributeValue
          5. The models.py file
        10. Playing with the admin system
        11. Summary
      17. 10. ShapeEditor – Implementing List View, Import, and Export
        1. Implementing the "list shapefiles" view
        2. Importing shapefiles
          1. The "import shapefile" view function
          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. Defining 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. 11. ShapeEditor – Selecting and Editing Features
        1. Selecting a feature to edit
          1. Implementing 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
            3. Using OpenLayers to display the map
            4. Intercepting mouse clicks
            5. 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
      19. Index