Foreword |
|
xix | |
Preface |
|
xxi | |
Acknowledgments |
|
xxii | |
About this book |
|
xxiv | |
Part 1 Introduction To Postgis |
|
1 | (244) |
|
1 What is a spatial database? |
|
|
3 | (24) |
|
|
4 | (2) |
|
|
6 | (8) |
|
|
7 | (3) |
|
|
10 | (2) |
|
|
12 | (2) |
|
|
14 | (3) |
|
|
15 | (1) |
|
|
15 | (1) |
|
|
16 | (1) |
|
|
17 | (1) |
|
|
17 | (9) |
|
|
18 | (1) |
|
|
19 | (2) |
|
|
21 | (3) |
|
|
24 | (1) |
|
Viewing spatial data with OpenJump |
|
|
25 | (1) |
|
|
26 | (1) |
|
|
27 | (33) |
|
|
28 | (1) |
|
|
28 | (1) |
|
Spatial reference identifier |
|
|
29 | (1) |
|
|
29 | (23) |
|
|
30 | (1) |
|
|
31 | (1) |
|
|
32 | (2) |
|
|
34 | (4) |
|
|
38 | (2) |
|
|
40 | (2) |
|
Polyhedral surfaces and TINS |
|
|
42 | (2) |
|
|
44 | (5) |
|
Spatial catalog for geometry |
|
|
49 | (2) |
|
Managing geometry columns |
|
|
51 | (1) |
|
|
52 | (2) |
|
Differences between geography and geometry |
|
|
53 | (1) |
|
Spatial catalogs for geography |
|
|
54 | (1) |
|
|
54 | (5) |
|
|
55 | (1) |
|
|
56 | (2) |
|
Spatial catalog for rasters |
|
|
58 | (1) |
|
|
59 | (1) |
|
3 Spatial reference system considerations |
|
|
60 | (22) |
|
3.1 Spatial reference systems: what are they? |
|
|
61 | (8) |
|
|
61 | (2) |
|
|
63 | (2) |
|
|
65 | (1) |
|
Coordinate reference system |
|
|
65 | (1) |
|
Spatial reference system essentials |
|
|
66 | (1) |
|
|
66 | (3) |
|
3.2 Selecting a spatial reference system for storing data |
|
|
69 | (7) |
|
Pros and cons of using EPSG:4326 |
|
|
70 | (1) |
|
Geography data type for EPSG:4326 |
|
|
71 | (1) |
|
Mapping just for presentation |
|
|
71 | (3) |
|
Covering the globe when distance is a concern |
|
|
74 | (2) |
|
3.3 Determining the spatial reference system of source data |
|
|
76 | (5) |
|
Guessing at a spatial reference system |
|
|
77 | (3) |
|
|
|
reference system is missing from spatial ref sys table |
|
|
80 | (1) |
|
|
81 | (1) |
|
|
82 | (31) |
|
|
83 | (3) |
|
PostgreSQL built-in tools |
|
|
83 | (1) |
|
|
84 | (1) |
|
|
85 | (1) |
|
4.2 Importing and exporting shapefiles |
|
|
86 | (6) |
|
|
87 | (1) |
|
Importing and exporting with shp2pgsql-gui |
|
|
88 | (3) |
|
|
91 | (1) |
|
4.3 Importing and exporting vector data with ogr2ogr |
|
|
92 | (7) |
|
|
93 | (1) |
|
|
93 | (1) |
|
|
93 | (4) |
|
|
97 | (2) |
|
4.4 Importing OpenStreetMap data with osm2pgsql |
|
|
99 | (4) |
|
|
100 | (1) |
|
Loading OSM-formatted data with osm2pgsql |
|
|
101 | (2) |
|
4.5 Importing and exporting raster data |
|
|
103 | (8) |
|
Using gdalinfo to inspect rasters |
|
|
103 | (2) |
|
Importing raster data with |
|
|
|
|
105 | (3) |
|
Gdal translate and gdalwarp |
|
|
108 | (2) |
|
Using PostgreSQL functions to output raster data |
|
|
110 | (1) |
|
|
111 | (2) |
|
5 Using PostGIS on the desktop |
|
|
113 | (27) |
|
5.1 Desktop viewing tools at a glance |
|
|
114 | (6) |
|
|
114 | (2) |
|
|
116 | (1) |
|
|
117 | (2) |
|
|
119 | (1) |
|
|
120 | (6) |
|
|
120 | (1) |
|
|
121 | (1) |
|
|
122 | (1) |
|
Rendering PostGIS geometries |
|
|
123 | (2) |
|
|
125 | (1) |
|
|
126 | (7) |
|
|
126 | (1) |
|
|
126 | (5) |
|
Importing and exporting layers |
|
|
131 | (2) |
|
|
133 | (2) |
|
|
133 | (1) |
|
|
134 | (1) |
|
Viewing and filtering PostGIS data |
|
|
134 | (1) |
|
|
135 | (4) |
|
|
136 | (3) |
|
|
139 | (1) |
|
|
139 | (1) |
|
6 Geometry and geography functions |
|
|
140 | (35) |
|
|
141 | (5) |
|
Well-known binary (WKB) and well-known text (WKT) |
|
|
142 | (1) |
|
Keyhole Markup Language (KML) |
|
|
142 | (1) |
|
Geography Markup Language (GML) |
|
|
142 | (1) |
|
Geometry JavaScript Object Notation (GeoJSON) |
|
|
143 | (1) |
|
Scalable Vector Graphics (SVG) |
|
|
143 | (1) |
|
Extensible 3D Graphics (X3D) |
|
|
144 | (1) |
|
Examples of output functions |
|
|
144 | (1) |
|
|
145 | (1) |
|
6.2 Constructor functions |
|
|
146 | (5) |
|
Creating geometries from text and binary formats |
|
|
146 | (4) |
|
Creating geographies from text and binary formats |
|
|
150 | (1) |
|
Using text or binary representations as function arguments |
|
|
150 | (1) |
|
6.3 Accessor and setter functions |
|
|
151 | (7) |
|
Spatial reference identifiers |
|
|
151 | (1) |
|
Transforming geometry to different spatial references |
|
|
152 | (1) |
|
Using transformation with the geography type |
|
|
153 | (1) |
|
|
153 | (2) |
|
Geometry and coordinate dimensions |
|
|
155 | (1) |
|
|
155 | (1) |
|
Checking geometry validity |
|
|
156 | (1) |
|
Number of points that defines a geometry |
|
|
156 | (2) |
|
6.4 Measurement functions |
|
|
158 | (3) |
|
Geometry planar measurements |
|
|
159 | (1) |
|
|
160 | (1) |
|
6.5 Decomposition functions |
|
|
161 | (7) |
|
Bounding box of geometries |
|
|
161 | (2) |
|
Boundaries and converting polygons to linestrings |
|
|
163 | (2) |
|
Centroid and point on surface |
|
|
165 | (1) |
|
Returning points defining a geometry |
|
|
166 | (1) |
|
Decomposing multi-geometries and geometry collections |
|
|
167 | (1) |
|
6.6 Composition functions |
|
|
168 | (4) |
|
|
169 | (1) |
|
|
170 | (1) |
|
Promoting single geometries to multi-geometries |
|
|
171 | (1) |
|
6.7 Simplification functions |
|
|
172 | (2) |
|
Grid snapping and coordinate rounding |
|
|
172 | (1) |
|
|
172 | (2) |
|
|
174 | (1) |
|
|
175 | (28) |
|
|
176 | (2) |
|
|
178 | (8) |
|
Converting geometries to rasters with ST AsRaster |
|
|
179 | (2) |
|
Loading rasters with raster2pgsql |
|
|
181 | (1) |
|
Constructing rasters from scratch: ST MakeEmptyRaster and ST AddBand |
|
|
182 | (1) |
|
Setting pixels: ST SetValue and ST SetValues |
|
|
182 | (2) |
|
Creating rasters from other rasters |
|
|
184 | (2) |
|
Converting other raster formats with |
|
|
|
|
186 | (1) |
|
7.3 Raster output functions |
|
|
186 | (4) |
|
ST AsPNG, ST AsJPEG, and ST AsTiff |
|
|
186 | (1) |
|
Output using ST AsGDALRaster |
|
|
187 | (2) |
|
Using psql to export rasters |
|
|
189 | (1) |
|
7.4 Raster accessors and setters |
|
|
190 | (6) |
|
Basic raster metadata properties |
|
|
191 | (1) |
|
|
192 | (1) |
|
|
193 | (2) |
|
|
195 | (1) |
|
7.5 Georeferencing functions |
|
|
196 | (4) |
|
|
196 | (1) |
|
|
197 | (3) |
|
|
200 | (1) |
|
7.7 Polygonizing functions |
|
|
201 | (1) |
|
|
201 | (1) |
|
|
201 | (1) |
|
|
201 | (1) |
|
|
201 | (1) |
|
|
202 | (1) |
|
|
203 | (15) |
|
8.1 Installing the PostGIS TIGER geocoder |
|
|
204 | (1) |
|
|
205 | (2) |
|
|
205 | (1) |
|
Loading nation and state data |
|
|
205 | (2) |
|
8.3 Normalizing addresses |
|
|
207 | (4) |
|
|
207 | (1) |
|
Using the PAGC address normalizer |
|
|
208 | (3) |
|
|
211 | (5) |
|
Geocoding using address text |
|
|
212 | (2) |
|
Geocoding using normalized addresses |
|
|
214 | (1) |
|
|
214 | (2) |
|
|
216 | (1) |
|
|
217 | (1) |
|
|
218 | (27) |
|
9.1 Bounding box and geometry comparators |
|
|
219 | (3) |
|
|
219 | (2) |
|
|
221 | (1) |
|
9.2 Relating two geometries |
|
|
222 | (12) |
|
Interior, exterior, and boundary of a geometry |
|
|
222 | (1) |
|
|
222 | (5) |
|
|
227 | (1) |
|
|
228 | (2) |
|
|
230 | (1) |
|
|
230 | (2) |
|
|
232 | (1) |
|
|
232 | (1) |
|
|
233 | (1) |
|
|
234 | (1) |
|
9.3 The faces of equality: geometry |
|
|
234 | (5) |
|
Spatial equality versus geometric equality |
|
|
235 | (1) |
|
|
236 | (3) |
|
9.4 Underpinnings of relationship functions |
|
|
239 | (5) |
|
|
240 | (1) |
|
|
241 | (3) |
|
|
244 | (1) |
Part 2 Putting Postgis To Work |
|
245 | (162) |
|
|
247 | (14) |
|
10.1 Nearest neighbor searches |
|
|
248 | (7) |
|
Which places are within X distance? |
|
|
248 | (1) |
|
Using ST DWithin and ST Distance for N closest results |
|
|
248 | (1) |
|
Using ST DWithin and DISTINCT ON to find closest locations |
|
|
249 | (1) |
|
Intersects with tolerance |
|
|
250 | (1) |
|
Finding N closest places using KNN distance bounding-box operators |
|
|
250 | (2) |
|
Combining KNN distance-box operators with ST Distance |
|
|
252 | (2) |
|
Using window functions to find closest N places |
|
|
254 | (1) |
|
10.2 Using KNN with geography types |
|
|
255 | (1) |
|
|
256 | (3) |
|
Tagging data to a specific region |
|
|
257 | (1) |
|
Linear referencing: snapping points to the closest linestring |
|
|
258 | (1) |
|
|
259 | (2) |
|
11 Geometry and geography processing |
|
|
261 | (26) |
|
11.1 Using spatial aggregate functions |
|
|
262 | (3) |
|
Creating a multipolygon from many multipolygon records |
|
|
262 | (2) |
|
Creating linestrings from points |
|
|
264 | (1) |
|
11.2 Clipping, splitting, tessellating |
|
|
265 | (9) |
|
|
266 | (1) |
|
|
267 | (1) |
|
|
268 | (6) |
|
11.3 Breaking linestrings into smaller segments |
|
|
274 | (5) |
|
|
274 | (1) |
|
Creating two-point linestrings from many-point linestrings |
|
|
275 | (1) |
|
Breaking linestrings at point junctions |
|
|
276 | (3) |
|
11.4 Translating, scaling, and rotating geometries |
|
|
279 | (5) |
|
|
279 | (2) |
|
|
281 | (2) |
|
|
283 | (1) |
|
11.5 Using geometry functions to manipulate and create geographies |
|
|
284 | (2) |
|
|
284 | (1) |
|
Transformation-recommended functions |
|
|
285 | (1) |
|
|
286 | (1) |
|
|
287 | (22) |
|
12.1 Loading and preparing data |
|
|
288 | (2) |
|
12.2 Forming larger rasters using spatial aggregate functions |
|
|
290 | (2) |
|
Reconstituting tiled files |
|
|
290 | (1) |
|
Carving out areas of interest using clipping and unioning |
|
|
291 | (1) |
|
Using specific expression types with ST Union |
|
|
291 | (1) |
|
|
292 | (2) |
|
Using ST AddBand to form multiband rasters from single-band rasters |
|
|
292 | (1) |
|
Using ST Band to process a subset of bands |
|
|
293 | (1) |
|
|
294 | (1) |
|
12.5 Raster and geometry intersections |
|
|
295 | (4) |
|
|
296 | (1) |
|
Adding a Z coordinate to a 2D linestring using ST Value |
|
|
297 | (1) |
|
Converting 2D polygon to 3D polygon |
|
|
298 | (1) |
|
|
299 | (4) |
|
|
299 | (2) |
|
Raster statistics functions |
|
|
301 | (2) |
|
|
303 | (5) |
|
Choosing between expression or callback function |
|
|
304 | (1) |
|
Using a single-band map algebra expression |
|
|
304 | (1) |
|
Using a single-band map algebra function |
|
|
305 | (1) |
|
Map algebra with neighborhoods |
|
|
306 | (2) |
|
|
308 | (1) |
|
13 Building and using topologies |
|
|
309 | (28) |
|
|
310 | (1) |
|
|
311 | (8) |
|
Installing the topology extension |
|
|
312 | (1) |
|
|
312 | (4) |
|
|
316 | (3) |
|
Recap of using topologies |
|
|
319 | (1) |
|
13.3 Topology of Victoria, BC |
|
|
319 | (7) |
|
Creating the Victoria topology |
|
|
319 | (1) |
|
Adding primitives to a topology |
|
|
320 | (3) |
|
|
323 | (3) |
|
13.4 Fixing topogeometry issues by editing topology primitives |
|
|
326 | (5) |
|
Removing faces by removing edges |
|
|
328 | (2) |
|
Checking for shared faces |
|
|
330 | (1) |
|
|
330 | (1) |
|
13.5 Inserting and editing large data sets |
|
|
331 | (2) |
|
13.6 Simplifying with topology in mind |
|
|
333 | (2) |
|
13.7 Topology validation and summary functions |
|
|
335 | (1) |
|
|
336 | (1) |
|
14 Organizing spatial data |
|
|
337 | (32) |
|
14.1 Spatial storage approaches |
|
|
338 | (8) |
|
|
338 | (2) |
|
|
340 | (1) |
|
Typmod versus constraints |
|
|
341 | (2) |
|
|
343 | (3) |
|
14.2 Modeling a real city |
|
|
346 | (11) |
|
Modeling using heterogeneous geometry columns |
|
|
348 | (4) |
|
Modeling using homogeneous geometry columns |
|
|
352 | (1) |
|
Modeling using inheritance |
|
|
353 | (4) |
|
14.3 Making auto-updateable views |
|
|
357 | (1) |
|
14.4 Using rules and triggers |
|
|
358 | (10) |
|
|
358 | (2) |
|
|
360 | (1) |
|
|
361 | (7) |
|
|
368 | (1) |
|
15 Query performance tuning |
|
|
369 | (38) |
|
|
370 | (2) |
|
Different kinds of spatial queries |
|
|
370 | (2) |
|
Common table expressions and how they affect plans |
|
|
372 | (1) |
|
|
372 | (2) |
|
15.3 Using explain to diagnose problems |
|
|
374 | (6) |
|
Text explain versus pgAdmin graphical explain |
|
|
375 | (1) |
|
|
376 | (4) |
|
|
380 | (6) |
|
The plan with a spatial index |
|
|
381 | (1) |
|
Options for defining indexes |
|
|
382 | (4) |
|
15.5 Common SQL patterns and how they affect plans |
|
|
386 | (12) |
|
|
386 | (6) |
|
FROM subqueries and basic CTEs |
|
|
392 | (1) |
|
Window functions and self-joins |
|
|
393 | (2) |
|
|
395 | (3) |
|
15.6 System and function settings |
|
|
398 | (4) |
|
Key system variables that affect plan strategy |
|
|
399 | (2) |
|
Function-specific settings |
|
|
401 | (1) |
|
15.7 Optimizing spatial data |
|
|
402 | (4) |
|
Fixing invalid geometries |
|
|
403 | (1) |
|
Reducing the number of vertices by simplification |
|
|
403 | (1) |
|
|
403 | (3) |
|
|
406 | (1) |
Part 3 Using Postgis With Other Tools |
|
407 | (72) |
|
16 Extending PostGIS with pgRouting and procedural languages |
|
|
409 | (33) |
|
16.1 Solving network routing problems with pgRouting |
|
|
410 | (6) |
|
|
411 | (1) |
|
|
411 | (3) |
|
|
414 | (2) |
|
16.2 Extending PostgreSQL with PLs |
|
|
416 | (2) |
|
Basic installation of PLs |
|
|
416 | (1) |
|
|
417 | (1) |
|
|
418 | (9) |
|
Getting started with PL/R |
|
|
419 | (1) |
|
Saving data sets and plotting |
|
|
420 | (3) |
|
|
423 | (2) |
|
Converting geometries into R spatial objects and plotting spatial objects |
|
|
425 | (2) |
|
Outputting plots as binaries |
|
|
427 | (1) |
|
|
427 | (6) |
|
|
428 | (1) |
|
Writing a PL/Python function |
|
|
429 | (1) |
|
|
430 | (2) |
|
|
432 | (1) |
|
16.5 PL/V8, CoffeeScript, and LiveScript |
|
|
433 | (8) |
|
|
434 | (1) |
|
Using other favaScript libraries and functions in PL/V8 |
|
|
434 | (4) |
|
Using PL/V8 to write map algebra functions |
|
|
438 | (3) |
|
|
441 | (1) |
|
17 Using PostGIS in web applications |
|
|
442 | (37) |
|
17.1 Limitations of conventional web technologies |
|
|
443 | (1) |
|
|
444 | (4) |
|
|
445 | (1) |
|
|
446 | (1) |
|
|
447 | (1) |
|
|
448 | (2) |
|
|
448 | (2) |
|
|
450 | (6) |
|
|
450 | (2) |
|
Creating WMS and WFS services |
|
|
452 | (2) |
|
Calling a mapping service using a reverse proxy |
|
|
454 | (2) |
|
|
456 | (4) |
|
|
456 | (1) |
|
Setting up PostGIS workspaces |
|
|
457 | (2) |
|
Accessing PostGIS layers via GeoServer WMS/WFS |
|
|
459 | (1) |
|
17.6 Basics of OpenLayers and Leaflet |
|
|
460 | (8) |
|
|
462 | (4) |
|
|
466 | (1) |
|
Synopsis of the three different APIs |
|
|
467 | (1) |
|
17.7 Displaying data with PostGIS queries and web scripting |
|
|
468 | (10) |
|
Displaying PostGIS rasters using raster queries |
|
|
468 | (5) |
|
Using PostGIS and PostgreSQL geometry output functions |
|
|
473 | (5) |
|
|
478 | (1) |
Appendix A Additional Resources |
|
479 | (6) |
Appendix B Installing, Compiling, And Upgrading |
|
485 | (8) |
Appendix C Sql Primer |
|
493 | (23) |
Appendix D Postgresql Features |
|
516 | (36) |
Index |
|
552 | |