April 2018
Beginner to intermediate
440 pages
11h 36m
English
A spatial database allows you to store spatial data, but you can also perform operations on the data and get different geometries back. The most common of these operations would be a buffer. You have a table of points, but using ST_Buffer(), you can have the database return a polygon around the point with a specified radius. The following code shows you how:
cursor.execute("SELECT ST_AsText(ST_Buffer(a.location,25.00,'quad_segs=2')) from pieces a WHERE a.code='101'")cursor.fetchall()
The previous code grabs a record from the table where the art code field equals 101, and selects a buffer with a radius of 25 around the location. The result will be a polygon, which is shown as follows: