
Learning Geospatial Analysis with Python
Joel Lawhead
Table of Contents
Preface ix
Chapter 1: Learning Geospatial Analysis with Python 1
Geospatial analysis and our world 1
Beyond disasters 4
History of geospatial analysis 4
Geographic information systems 9
Remote sensing 11
Elevation data 17
Computer-aided drafting 18
Geospatial analysis and computer programming 18
Object-oriented programming for geospatial analysis 19
Importance of geospatial analysis 21
Geographic information system concepts 21
Thematic maps 22
Spatial databases 23
Spatial indexing 24
Metadata 24
Map projections 24
Rendering 26
Remote sensing concepts 27
Images as data 27
Remote sensing and color 28
Common vector GIS concepts 28
Data structures 28
Buffer 30
Dissolve 30
Generalize 31
Intersection 32
Merge 32
Point in polygon 33
Union 34
Join 34
Geospatial rules about polygons 35
Common raster data concepts 35
Band math 35
Change detection 36
Histogram 37
Feature extraction 37
Supervised classifcation 38
Unsupervised classifcation 38
Creating the simplest possible Python GIS 38
Getting started with Python 38
Building SimpleGIS 39
Step by step 40
Summary 47
Chapter 2: Geospatial Data 49
An overview of common data formats 49
Data structures 53
Common traits 53
Geolocation 54
Subject information 54
Spatial indexing 54
Indexing algorithms 54
Quadtree index 55
R-tree index 56
Grids 57
Overviews 57
Metadata 58
File structure 58
Vector data 60
Shapefles 61
CAD fles 64
Tag-based and markup-based formats 65
GeoJSON 67
Raster data 68
TIFF fles 69
JPEG, GIF, BMP, and PNG 70
Compressed formats 70
ASCII Grids 70
World fles 71
Point cloud data 74
Web services 75
Summary 76
Chapter 3: The Geospatial Technology Landscape 77
Data access 80
GDAL 80
OGR 81
Computational geometry 83
The PROJ.4 projection library 84
CGAL 85
JTS 86
GEOS 88
PostGIS 89
Other spatially-enabled databases 92
Oracle spatial and graph 93
ArcSDE 95
Microsoft SQL Server 97
MySQL 97
SpatiaLite 97
Routing 98
Esri Network Analyst and Spatial Analyst 98
pgRouting 98
Desktop tools (including visualization) 99
Quantum GIS 100
OpenEV 102
GRASS GIS 103
uDig 104
gvSIG 106
OpenJUMP 106
Google Earth 106
NASA World Wind 109
ArcGIS 110
Metadata management 112
GeoNetwork 112
CatMDEdit 113
Summary 114
Chapter 4: Geospatial Python Toolbox 115
Installing third-party Python modules 116
Installing GDAL 118
Windows 119
Linux 120
Mac OS X 120
Python networking libraries for acquiring data 121
The Python urllib module 121
FTP 123
ZIP and TAR fles 125
Python markup and tag-based parsers 127
The minidom module 128
ElementTree 130
Building XML 131
Well-known text (WKT) 135
Python JSON libraries 137
The json module 138
The geojson module 139
OGR 139
PyShp 140
dbfpy 141
Shapely 142
Fiona 143
GDAL 145
NumPy 146
PIL 148
PNGCanvas 150
GeoPandas 152
PyMySQL 153
PyFPDF 154
Spectral Python 155
Summary 155
Chapter 5: Python and Geographic Information Systems 157
Measuring distance 158
Pythagorean theorem 161
Haversine formula 163
Vincenty's formula 165
Calculating line direction 167
Coordinate conversion 168
Reprojection 170
Editing shapefles 173
Accessing the shapefle 175
Reading shapefle attributes 176
Reading shapefle geometry 179
Changing a shapefle 180
Adding felds 182
Merging shapefles 182
Merging shapefles with dbfpy 184
Splitting shapefles 186
Subsetting spatially 186
Performing selections 187
Point in polygon formula 187
Bounding Box Selections 188
Attribute selections 189
Creating images for visualization 191
Dot density calculations 191
Choropleth maps 195
Using spreadsheets 197
Using GPS data 199
Geocoding 200
Summary 201
Chapter 6: Python and Remote Sensing 203
Swapping image bands 204
Creating histograms 207
Performing a histogram stretch 211
Clipping images 214
Classifying images 218
Extracting features from images 222
Change detection 228
Summary 232
Chapter 7: Python and Elevation Data 233
ASCII Grid fles 233
Reading grids 234
Writing grids 235
Creating a shaded relief 237
Creating elevation contours 242
Working with LIDAR 247
Creating a grid from LIDAR 247
Using PIL to visualize LIDAR 254
Creating a triangulated irregular network 259
Summary 263
Chapter 8: Advanced Geospatial Python Modeling 265
Creating a Normalized Difference Vegetative Index 266
Setting up the framework 268
Loading the data 269
Rasterizing the shapefle 270
Clipping the bands 272
Using the NDVI formula 272
Classifying the NDVI 273
Additional functions 274
Loading the NDVI 275
Preparing the NDVI 275
Creating classes 275
Creating a flood inundation model 278
The flood fll function 280
Making a flood 282
Creating a color hillshade 286
Least cost path analysis 288
Setting up the test grid 289
The simple A* algorithm 290
Generating the test path 291
Viewing the test output 291
The real-world example 292
Loading the grid 294
Defning the helper functions 295
The real-world A* algorithm 296
Generating a real-world path 298
Routing along streets 301
Geolocating photos 304
Summary 307
Chapter 9: Real-Time Data 309
Tracking vehicles 310
The NextBus agency list 312
The NextBus route list 313
NextBus vehicle locations 313
Mapping NextBus locations 316
Storm chasing 320
Reports from the feld 328
Summary 331
Chapter 10: Putting It All Together 333
A typical GPS report 334
Working with GPX-Reporter.py 334
Stepping through the program 335
The initial setup 336
Working with utility functions 338
Parsing the GPX 342
Getting the bounding box 343
Downloading map and elevation images 344
Creating the hillshade 346
Creating maps 347
Measuring the elevation 351
Measuring the distance 352
Retrieving weather data 353
Summary 358
Index 35

- Log in to post comments

