Numberedheadings | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||
Working with GeometryIf your database has the postgis extension installed, you have access to the hundreds of functions contained in PostGIS for spatial processing. This module explores a few of them and shows how they can be used in Postgres. You can find out more about PostGIS and the functionality it contains on the PostGIS site. Most of these functions are mirrored by processes in QGIS - this module covers how to run them in SQL queries. As for SQL in Postgres, PostGIS functions are not case sensitive. MeasurementsPostGIS has functions for measurements which depend on the geometry type of the features to be measured. LengthFor lines, ST_Length will return the length of each feature in a table, using the name of the geometry column as its only parameter. In the example below, we are also rounding the resulting length to a whole number. The units of the length output are the units of the CRS of the table. AreaFor polygons, ST_Area measures the area, excluding internal rings. Get length, area, perimeter of features
Transforming GeometryPostGIS has functions which will transform a geometry, based on one or more existing features. BufferFor example, you can use ST_Buffer to create a new set of features which describe an area which is within a set distance of an existing feature - whether it is a LINE, POLYGON or POINT. Note that because the source lines are individual segments, by default a single buffer feature is generated for each segment. To dissolve all these buffer features into a single MULTIPOLYGON, you would use ST_Union to merge the result of the buffer: IntersectionST_Intersection will return the area which is common to the geometries of two layers, as shown in the cross-hatched areas below. Result of ST_Intersection shown as cross-hatched Create buffer and intersection
Spatial Relationships and JoinsPostGIS support the ability to query sets of layers to test for spatial relationships between them. In each case, these functions produce a boolean result, i.e. true or false. For example:
These functions in turn allow spatial joins to be created within tables, where instead of using equality between values in corresponding tables to make a join, the SQL looks for a spatial relationship. For example, this query creates a list of settlements with the name of the parish which contains them, using ST_Within. Create a spatial selection
|
Page Comparison
General
Content
Integrations