12.07.2015 Views

PostGIS 1.5.8 Manual - Fedora Project Packages GIT repositories

PostGIS 1.5.8 Manual - Fedora Project Packages GIT repositories

PostGIS 1.5.8 Manual - Fedora Project Packages GIT repositories

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PostGIS</strong> <strong>1.5.8</strong> <strong>Manual</strong>39 / 310This query selects the same geometries, but it does it in a more efficient way. Assuming there is a GiST index on the_geom,the query planner will recognize that it can use the index to reduce the number of rows before calculating the result of the d-istance() function. Notice that the BOX3D geometry which is used in the && operation is a 200 unit square box centeredon the original point - this is our "query box". The && operator uses the index to quickly reduce the result set down to onlythose geometries which have bounding boxes that overlap the "query box". Assuming that our query box is much smaller thanthe extents of the entire geometry table, this will drastically reduce the number of distance calculations that need to be done.Change in BehaviorAs of <strong>PostGIS</strong> 1.3.0, most of the Geometry Relationship Functions, with the notable exceptions of ST_Disjoint andST_Relate, include implicit bounding box overlap operators.4.7.2 Examples of Spatial SQLThe examples in this section will make use of two tables, a table of linear roads, and a table of polygonal municipality boundaries.The table definitions for the bc_roads table is:Column | Type | Description------------+-------------------+-------------------gid | integer | Unique IDname | character varying | Road Namethe_geom | geometry | Location Geometry (Linestring)The table definition for the bc_municipality table is:Column | Type | Description-----------+-------------------+-------------------gid | integer | Unique IDcode | integer | Unique IDname | character varying | City / Town Namethe_geom | geometry | Location Geometry (Polygon)1. What is the total length of all roads, expressed in kilometers?You can answer this question with a very simple piece of SQL:SELECT sum(ST_Length(the_geom))/1000 AS km_roads FROM bc_roads;km_roads------------------70842.1243039643(1 row)2. How large is the city of Prince George, in hectares?This query combines an attribute condition (on the municipality name) with a spatial calculation (of the area):SELECTST_Area(the_geom)/10000 AS hectaresFROM bc_municipalityWHERE name = ’PRINCE GEORGE’;hectares------------------32657.9103824927(1 row)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!