← All work

Case study

Answering park questions with spatial SQL in PostGIS and QGIS

Loaded a national park dataset into PostGIS and answered distance, length, area and proximity questions with spatial SQL, mapping the results in QGIS.

Context
Course lab (GIS 550, Geospatial Data Structures and Web Services), NC State, April 2017. The questions were set by the assignment
Data
George Washington Birthplace National Monument layers and fish survey tables, provided with the assignment
Output
SQL views, query results and QGIS maps

Problem

The lab asked a set of questions about George Washington Birthplace National Monument that had to be answered in the database rather than with point-and-click tools. How far apart are two buildings? How long are the park's streams? How much building footprint is there? And for a hypothetical bird that roosts in trees and eats White Perch: where might it be found, and which buildings sit close enough to its feeding sites to disturb it?

Approach

I loaded the park layers into a PostGIS database, converting their projections to EPSG codes, and connected QGIS to it. I then wrote SQL views for each question and mapped the views in QGIS. The 200 meter disturbance distance was given. For how far the bird would travel from a roost to feed, no distance was given, so I chose 300 meters and said so in my answer.

-- Identify trees within 300 meters of GEWA whitepearch sites
CREATE OR REPLACE VIEW v_birdlocations AS
SELECT DISTINCT ON (t.id) t.id, t.geom, w.siteid
    FROM v_trees t
        RIGHT JOIN v_whitepearch w ON ST_DWithin(t.geom, w.the_geom, 300)
    ORDER BY t.id, ST_Distance(t.geom, w.the_geom);

-- Identify buidlings within 200 meters of GEWA whitepearch sites
CREATE OR REPLACE VIEW v_DangerBuildings AS
SELECT DISTINCT ON (db.feature) db.feature, db.geom, w.siteid
    FROM v_gewa_building db
        RIGHT JOIN v_whitepearch w ON ST_DWithin(db.geom, w.the_geom, 200)
    ORDER BY db.feature, ST_Distance(db.geom, w.the_geom);

Supporting views pulled tree locations from the vegetation layer, and White Perch survey sites by joining the sites, site visits and fish catch tables.

Result

QuestionAnswerMethod
Distance from the Visitor Center to Rockefeller Barn336 m (0.21 mi)ST_Centroid, ST_Distance
Total length of streams11.48 kmST_Length
Total building footprint3,991 m² (42,947 sq ft)ST_Area
Where the bird might roost and feedTrees within 300 m of White Perch sites GEWA03, GEWA28, GEWA30 and GEWA31ST_DWithin view
Buildings that may disturb feedingBuildings within 200 m of White Perch sites, including the Visitor CenterST_DWithin view, QGIS buffer
QGIS map of the park with red 300 meter buffers around trees, green tree points, and red stars at White Perch survey sites such as GEWA28, GEWA30 and GEWA31
Trees within 300 m of White Perch survey sites (red buffers).
QGIS map showing a 200 meter buffer around the Visitor Center, with nearby trees and the GEWA28 and GEWA30 survey sites
200 m around the Visitor Center, with nearby trees and survey sites.
QGIS map of buildings within 200 meters of White Perch survey sites, highlighted in purple, with buffers around the sites
Buildings within 200 m of White Perch sites.

Tools

  • PostgreSQL
  • PostGIS
  • Spatial SQL
  • ST_DWithin
  • ST_Distance
  • ST_Area
  • QGIS
  • pgAdmin