Skip to Content
Mastering Geospatial Analysis with Python
book

Mastering Geospatial Analysis with Python

by Silas Toms, Paul Crickard, Eric van Rees
April 2018
Beginner to intermediate content levelBeginner to intermediate
440 pages
11h 36m
English
Packt Publishing
Content preview from Mastering Geospatial Analysis with Python

Triggers

In any database, when data is inserted, updated, or deleted, you can have the table launch a trigger. For example, if a user inserts a record, you could launch a trigger to make sure that the record meets some specified criteria—no null values. Spatial databases allow you to use the same triggers. You can create these in several languages, including Python and SQL. The following example will use PL/pgsql.

You create triggers using SQL expressions. The following code will create a trigger to prevent entering an incomplete incident:

query=('CREATE FUNCTION newcrime()'+'\n' 'RETURNS trigger' +'\n' 'AS $newcrime$' +'\n' 'BEGIN' +'\n' 'IF NEW.crimetype IS NULL THEN'+'\n' 'RAISE EXCEPTION' +" '% Must Include Crime Type', NEW.address;"+'\n' ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Geospatial Analysis with Python

Learning Geospatial Analysis with Python

Joel Lawhead

Publisher Resources

ISBN: 9781788293334Supplemental Content