PostGIS in Action [Pap/Psc ed.] 1935182269, 9781935182269

Whether you're canvassing a congressional district, managing a sales region, mapping city bus schedules, or analyzi

265 81 6MB

English Pages 522 Year 2011

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
PostGIS-front......Page 1
brief contents......Page 6
contents......Page 8
foreword......Page 16
preface......Page 18
acknowledgments......Page 20
about this book......Page 22
Who should read this book?......Page 23
Roadmap......Page 25
Code downloads......Page 27
About the title......Page 28
about the cover illustration......Page 29
Part 1 Learning PostGIS......Page 30
1.1 Thinking spatially......Page 32
1.1.1 Introducing the geometry data type......Page 35
1.2 Modeling......Page 36
1.2.1 Imagine the possibilities......Page 37
1.3.1 PostgreSQL strengths......Page 38
1.3.2 PostGIS, adding GIS to PostgreSQL......Page 42
1.3.3 Alternatives to PostgreSQL and PostGIS......Page 43
1.3.4 What works with PostGIS......Page 44
1.4 Getting started with PostGIS......Page 45
1.4.2 Creating geometries with PostGIS......Page 46
1.5 Working with real data......Page 49
1.5.1 Loading comma-separated data......Page 50
1.5.2 Spatializing flat file data......Page 51
1.5.3 Loading data from spatial data sources......Page 54
1.6 Using spatial queries to analyze data......Page 57
1.6.1 Proximity queries......Page 58
1.6.2 Viewing spatial data with OpenJUMP......Page 59
1.7 Summary......Page 60
2 Geometry types......Page 62
2.1.1 The geometry_columns table......Page 63
2.1.2 Interacting with the geometry_columns table......Page 66
2.2.1 What’s a geometry?......Page 67
2.2.2 Points......Page 68
2.2.3 Linestrings......Page 69
2.2.4 Polygons......Page 70
2.2.5 Collection geometries......Page 72
2.2.6 Curved geometries......Page 76
2.2.7 3D geometries......Page 80
2.3 Summary......Page 81
3.1 Spatial storage approaches......Page 82
3.1.1 Heterogeneous geometry columns......Page 83
3.1.2 Homogeneous geometry columns......Page 85
3.1.3 Table inheritance......Page 86
3.2 Modeling a real city......Page 89
3.2.1 Modeling using a heterogeneous geometry column......Page 90
3.2.2 Modeling using homogeneous geometry columns......Page 93
3.2.3 Modeling using inheritance......Page 95
3.3.1 Rules versus triggers......Page 98
3.3.2 Using rules......Page 100
3.3.3 Using triggers......Page 102
3.4 Summary......Page 107
4 Geometry functions......Page 109
4.1.1 Creating geometries from well-known text and well-known binary representations......Page 110
4.1.2 Autocasting in PostgreSQL/PostGIS......Page 112
4.2 Outputs......Page 113
4.2.2 Keyhole Markup Language......Page 114
4.2.5 Scalable Vector Graphics......Page 115
4.2.7 Examples of output functions......Page 116
4.3.1 Getting and setting spatial reference system......Page 117
4.3.2 Transform to a different spatial reference......Page 118
4.3.3 Geometry type......Page 119
4.3.4 Coordinate and geometry dimensions......Page 120
4.3.5 Geometry validity......Page 121
4.3.6 Number of points that define a geometry......Page 122
4.4 Measurement functions......Page 123
4.4.1 Planar measures for geometry types......Page 124
4.4.2 Geodetic measurement for geometry types......Page 125
4.4.3 Measurement with geography type......Page 127
4.5.1 Boxes and envelopes......Page 128
4.5.2 Coordinates......Page 130
4.5.3 Boundaries......Page 131
4.5.4 Point marker for a geometry: centroid, point on surface, and nth point......Page 132
4.5.5 Breaking down multi and collection geometries......Page 134
4.6.1 Making points......Page 137
4.6.2 Making polygons......Page 139
4.7 Simplification......Page 141
4.7.1 Coordinate rounding using ST_SnapToGrid......Page 142
4.7.2 Simplifying geometries......Page 143
4.8 Summary......Page 144
5 Relationships between geometries......Page 146
5.1 Introducing spatial relationship functions......Page 147
5.2 Intersections......Page 148
5.2.1 Segmenting linestrings with polygons......Page 149
5.2.2 Clipping polygons with polygons......Page 150
5.3.1 Interior, exterior, and boundary of a geometry......Page 152
5.3.2 Contains and Within......Page 154
5.3.3 Covers and CoveredBy......Page 156
5.3.4 ContainsProperly......Page 157
5.3.6 Touching geometries......Page 158
5.3.7 Crossing geometries......Page 159
5.4 The remainder: ST_Difference and ST_SymDifference......Page 160
5.5 Nearest neighbor......Page 163
5.5.2 Finding N closest objects......Page 164
5.5.3 Using SQL Window functions to number results......Page 166
5.6.1 The bounding box......Page 168
5.6.2 Bounding box and geometry operators......Page 169
5.7 The many faces of equality......Page 170
5.7.2 Geometric equality......Page 171
5.7.3 Bounding box equality......Page 173
5.8.1 The intersection matrix......Page 176
5.8.2 Equality and the intersection matrix......Page 177
5.8.3 Using the intersection matrix with ST_Relate......Page 178
5.9 Summary......Page 181
6 Spatial reference system considerations......Page 182
6.1.1 The geoid......Page 183
6.1.2 Ellipsoids......Page 185
6.1.5 Projection......Page 187
6.1.6 Different kinds of projections......Page 188
6.2.1 Pros and cons of using EPSG:4326......Page 191
6.2.2 Geography data type for EPSG:4326......Page 192
6.2.3 Mapping just for presentation......Page 193
6.2.4 Covering the globe when distance is a concern......Page 195
6.3 Determining the spatial reference system of source data......Page 197
6.3.1 Guessing at a spatial reference system......Page 198
6.4 Summary......Page 201
7 Working with real data......Page 202
7.1.2 PostGIS packaged tools......Page 203
7.1.3 OGR2OGR: all-purpose vector data loader......Page 204
7.1.4 Quantum GIS Shapefile to PostGIS Import Tool......Page 206
7.2 Loading data......Page 208
7.2.1 Getting and extracting compressed files......Page 209
7.2.2 Using PostGIS and PostgreSQL tools to load data......Page 211
7.2.3 Loading data with OGR2OGR......Page 216
7.2.4 Importing OpenStreetMap data with osm2pgsql......Page 222
7.3 Exporting data from PostGIS......Page 224
7.3.1 Using pgsql2shp to dispense PostGIS data......Page 225
7.3.2 Using OGR2OGR to dispense PostGIS data......Page 226
7.4 Summary......Page 228
Part 2 Putting PostGIS to work......Page 230
8 Techniques to solve spatial problems......Page 232
8.1.1 Check for intersections and measuring distances......Page 233
8.1.2 Convert to different units of measurement......Page 236
8.1.3 Measure large distances......Page 238
8.1.4 Choose spatial reference systems when measuring area......Page 241
8.2.1 Techniques for generating dummy data......Page 244
8.2.2 Tag data to a specific region......Page 245
8.2.3 Snapping points to closest linestring......Page 246
8.2.4 Geocoding an address to a point on a street......Page 248
8.3.1 Create linestrings from points......Page 250
8.3.2 Break linestrings into smaller segments......Page 252
8.4.1 Create a single multipolygon from many multipolygon records......Page 256
8.4.2 Tessellate areas......Page 257
8.4.3 Create equal-area slices......Page 260
8.5 Translating, scaling, and rotating geometries......Page 264
8.5.1 Move a geometry along X, Y, Z......Page 265
8.5.2 Increase and decrease size of geometry......Page 267
8.5.3 Rotate a geometry......Page 268
8.6 Summary......Page 269
9 Performance tuning......Page 270
9.1 The query planner......Page 271
9.1.1 Planner statistics......Page 272
9.2 Using explain to diagnose problems......Page 274
9.2.1 Text explain versus pgAdmin III graphical explain......Page 275
9.2.2 The plan without an index......Page 276
9.3.1 The plan with a spatial index scan......Page 279
9.3.2 Options for defining indexes......Page 282
9.4 Common SQL patterns and how they affect performance......Page 286
9.4.1 SELECT subselects......Page 287
9.4.2 FROM subselects and basic common table expressions......Page 292
9.4.3 Window functions and self-joins......Page 293
9.5 System and function settings......Page 294
9.5.1 Key system variables that affect plan strategy......Page 295
9.5.2 Function-specific settings......Page 297
9.6.2 Reducing number of vertices with simplification......Page 298
9.6.3 Removing holes......Page 301
9.6.4 Clustering......Page 302
9.7 Summary......Page 304
Part 3 Using PostGIS with other tools......Page 306
10 Enhancing SQL with add-ons......Page 308
10.1 Georeferencing with the TIGER geocoder......Page 309
10.1.2 Loading TIGER data......Page 310
10.1.3 Geocoding and address normalization......Page 312
10.2.2 Shortest route......Page 315
10.2.3 Traveling salesperson problem......Page 317
10.2.4 Summary......Page 318
10.3.2 What can you do with a non-native PL......Page 319
10.4.1 Getting started with PL/R......Page 321
10.4.2 Saving datasets and plotting......Page 322
10.4.3 Using R packages in PL/R......Page 325
10.4.4 Quick primer on rgdal......Page 327
10.4.5 Getting PostGIS geometries into R spatial objects......Page 330
10.5.1 Installing PL/Python......Page 333
10.5.3 Using Python packages......Page 335
10.5.4 Geocoding with PL/Python......Page 338
10.6 Summary......Page 340
11 Using PostGIS in web applications......Page 341
11.1.1 Limitations of conventional web technologies......Page 342
11.1.2 Mapping servers......Page 343
11.1.3 Mapping clients......Page 346
11.1.4 Proprietary services......Page 347
11.2.1 Installing MapServer......Page 348
11.2.2 Creating WMS and WFS services......Page 349
11.2.3 Calling a mapping service using a reverse proxy......Page 351
11.3.1 Installing GeoServer......Page 353
11.3.2 Setting up PostGIS workspaces......Page 354
11.3.3 Accessing PostGIS Layers via GeoServer WMS/WFS......Page 355
11.4 Basics of OpenLayers and GeoExt......Page 356
11.4.1 Using OpenLayers......Page 357
11.4.2 Enhancing OpenLayers with GeoExt......Page 362
11.5.1 Using PostGIS output functions with PHP......Page 366
11.5.2 Displaying data in Google Earth......Page 369
11.5.3 Loading custom layers with GeoExt......Page 370
11.5.4 Proximity queries with PostGIS geography......Page 371
11.6 Summary......Page 372
12 Using PostGIS in a desktop environment......Page 374
12.1.1 Capsule review......Page 375
12.1.2 Spatial database support......Page 376
12.1.3 Format support......Page 378
12.1.4 Web services supported......Page 379
12.2 OpenJUMP Workbench......Page 380
12.2.1 Feature summary......Page 381
12.2.2 Register data source......Page 382
12.2.3 Rendering PostGIS geometry data......Page 384
12.3.1 Feature summary......Page 386
12.3.2 Adding a PostGIS connection......Page 388
12.3.3 Viewing and filtering PostGIS data......Page 389
12.3.5 Loading other vector and raster layers......Page 390
12.4 uDig......Page 391
12.4.1 Feature summary......Page 392
12.4.2 Connecting to PostGIS and other spatial databases......Page 393
12.4.4 Exporting data......Page 394
12.5.1 Feature summary......Page 395
12.5.2 Adding a PostGIS layer to a view......Page 397
12.5.3 Exporting data......Page 398
12.6 Summary......Page 399
13 PostGIS raster......Page 400
13.1 What is PostGIS raster?......Page 401
13.1.1 What is raster data and how is it different from vector data?......Page 402
13.1.3 Getting started with raster support in PostGIS......Page 405
13.2.1 Options for storage......Page 406
13.2.2 Using a loader to load data......Page 407
13.3 Raster maintenance tables and functions......Page 412
13.3.1 raster_columns metadata table......Page 413
13.4.1 Common accessors......Page 414
13.4.2 Georeferencing functions......Page 418
13.5.2 Intersects and Intersections......Page 421
13.5.3 Adding bands......Page 424
13.5.4 Adding additional attributes to raster records......Page 426
13.6 Exporting raster data into other raster formats......Page 427
13.6.1 Gdal_translate basics to convert to other formats......Page 428
13.6.2 Using gdalwarp to transform from one spatial ref to another......Page 429
13.7 Viewing raster data with MapServer......Page 430
13.8.1 Input/output functionality......Page 431
13.8.3 Database raster functions......Page 432
13.9 Summary......Page 433
Getting-started tutorials......Page 434
Noteworthy PostGIS blogs and sites......Page 435
Noteworthy R, PL/R sites, and newsgroups......Page 437
pgRouting installation and examples......Page 438
Raster-related information......Page 439
Installers and self-contained suites that include/work with PostGIS......Page 440
Free open source desktop GIS......Page 441
Proprietary tools that support PostGIS......Page 442
All geographic regions......Page 443
North America......Page 444
Sample data for training......Page 446
Spatial reference systems resources......Page 447
Desktop Linux, Windows, Mac OS X using one-click installers......Page 448
Installing on Linux server (Red Hat EL, CentOS) using YUM......Page 449
Compiling and installing from PostGIS source......Page 450
Creating a PostGIS database......Page 451
Creating template_postgis under PostGIS 1.4,1.5+......Page 452
Spatially enabling an existing PostgreSQL database......Page 454
Hard upgrades......Page 455
Information_schema......Page 459
SELECT, FROM, WHERE, and ORDER BY clauses......Page 461
JOINs......Page 465
Sets......Page 469
Using SQL aggregates......Page 472
Window functions and window aggregates......Page 474
Updates......Page 475
INSERTs......Page 476
DELETEs......Page 479
General......Page 480
Core configuration files......Page 481
Launching psql......Page 482
Connection difficulties......Page 483
Enabling advanced administration for pgAdmin III......Page 484
Connection rules......Page 485
Users and groups (roles)......Page 486
Rights management......Page 487
Backup and restore......Page 491
Backup......Page 492
Setting up automated jobs for backup......Page 493
PostgreSQL objects......Page 494
Built-in data types......Page 496
Anatomy of a database function......Page 497
Creating tables and views......Page 499
When to use SQL functions......Page 500
Creating rules......Page 501
Creating aggregate functions......Page 503
When to use PL/PgSQL functions......Page 504
Creating a PL/PgSQL function......Page 505
Creating triggers......Page 506
Index......Page 509
Summary......Page 510
D......Page 512
G......Page 513
I......Page 514
N......Page 515
O......Page 516
R......Page 517
S......Page 518
Z......Page 520
V......Page 519
PostGIS-back......Page 522

PostGIS in Action [Pap/Psc ed.]
 1935182269, 9781935182269

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers