SQL Control Bar
Check or uncheck View > Show/Hide > SQL to toggle the visibility of the SQL Control Bar.
ST Commands
The SQL console treats an SWD as a database, an Overlay as a table within that database and a schema column as a column within that table.
The console is based on SQLite and supports most normal SQLite SELECT syntax but not any of the Data definition language (DDL), eg CREATE TABLE, etc.
See here for more information on ST Commands.
SIS Item geometry (automatically converted to OGC Simple Features-compatible types) is accessed using the built-in sis_geometry column.
In addition to the normal SQL syntax, SIS Desktop adds the following (based on their ISO SQL/MM standard equivalents) where possible:
ST_Area |
Returns the area of a polygon or multipolygon. SELECT ST_Area(overlay1.sis_geometry) FROM overlay1;
|
ST_Binary
|
Returns the Well-Known Binary (WKB) representation of the geometry/geography. SELECT ST_Binary |
ST_AsGeoJSON |
Returns the geometry as a GeoJSON element. Example command line: SELECT ST_AsGeoJSON |
ST_AsText |
Returns the Well-Known Text (WKT) representation of the geometry/geography. SELECT ST_AsText |
ST_Boundary |
Returns the closure of the combinatorial boundary of the geometry. SELECT ST_Boundary(overlay1.sis_geometry) FROM overlay1; |
ST_Buffer |
Returns a geometry covering all points within a given distance from the input geometry. SELECT ST_Buffer(overlay2.sis_geometry, 100) from overlay2; |
ST_Centroid |
Returns the geometric centre of a geometry. SELECT ST_Centroid |
ST_Contains |
Returns true if and only if no points of B lie in the exterior of A, and at least one point of the interior of B lies in the interior of A. SELECT ST_Contains |
ST_ConvexHull |
Returns the convex hull of a geometry object. SELECT ST_ConvexHull(overlay2.sis_geometry) from overlay2; |
ST_Crosses |
Returns TRUE if the supplied geometries have some, but not all, interior points in common. SELECT ST_Crosses |
ST_Difference |
Returns a geometry that represents that part of geometry A that does not intersect with geometry B. (Also available as an aggregate function). SELECT ST_Difference(overlay1.sis_geometry,overlay2.sis_geometry) from overlay1,overlay2; |
ST_Dimension |
Returns the inherent dimension of the Geometry object, which must be less than or equal to the coordinate dimension. SELECT ST_Dimension(overlay3.sis_geometry) from overlay3 |
ST_Disjoint |
Returns TRUE if the Geometries do not "spatially intersect", ie if they do not share any space together. SELECT ST_Disjoint |
ST_Distance |
Returns the distance between two geometries. The distance is measured from the closest vertices of the two geometries. SELECT ST_Distance |
ST_DWithin |
Returns true if the geometries are within the specified distance of one another SELECT ST_DWithin |
ST_Envelope |
Returns a geometry representing the bounding box of the supplied geometry. Uses double-precision.. SELECT ST_Envelope(overlay2.sis_geometry) from overlay2; |
ST_Equals |
Returns true if the given geometries represent the same geometry. Directionality is ignored. SELECT ST_Equals |
ST_Expand |
Returns bounding box expanded in all directions from the bounding box of the input geometry. Uses double-precision. SELECT ST_Expand |
ST_Extent |
An aggregate function that returns the bounding box that bounds rows of geometries. SELECT ST_Extent |
ST_First |
Only available as an aggregate function, ie function used to aggregate the results of a SQL query. SELECT ST_First |
ST_GeomFromGeoJSON |
Takes a geojson representation of a geometry and outputs a PostGIS geometry object. SELECT ST_GeomFromGeoJSON |
ST_GeomFromText |
Returns a specified ST_Geometry value from Well-Known Text representation (WKT). SELECT ST_GeomFromText |
ST_GeomFromWKB |
Creates a geometry instance from a Well-Known Binary geometry representation (WKB) and optional SRID (Spatial Reference System Identifier). SELECT ST_GeomFromWKB |
ST_Intersection |
Returns a geometry that represents the shared portion of geometry A and geometry B. (Also available as an aggregate function). Select ST_Intersection(overlay1.sis_geometry,overlay2.sis_geometry) from overlay1,overlay2; |
ST_Intersects |
Returns TRUE if the Geometries spatially intersect in 2D - ie share any portion of space, and FALSE if they do not, ie they are Disjoint. SELECT ST_Intersects |
ST_Length |
Returns the 2D length of the geometry if it is a LineString or MultiLineString. Select ST_Length(linestring4326.sis_geometry) FROM linestring4326; |
ST_Length_Spheroid |
Returns the 2D or 3D length/perimeter of a geometry on an ellipsoid. Select ST_Length_Spheroid(linestring.sis_geometry) from linestring; |
ST_MakeLine |
Creates a LineString from Point, MultiPoint, or LineString geometries. (Also available as an aggregate function). SELECT ST_MakeLine |
ST_Overlaps |
Returns TRUE if the Geometries share space, are of the same dimension, but are not completely contained by each other. SELECT ST_Overlaps |
ST_Perimeter |
Returns the length measurement of the boundary of an ST_Surface or ST_MultiSurface geometry. SELECT ST_Perimeter(overlay1.sis_geometry) FROM overlay1; SELECT ST_Perimeter(ST_GeomFromText(('POLYGON((743238,2967416,743238 2967450,743265 2967450, 743265.625 2967416,743238 2967416))', 2249))
|
ST_PointOnSurface |
Returns an ST_Point guaranteed to lie on the surface of an ST_Polygon or ST_MultiPolygon. SELECT ST_PointOnSurface |
ST_Relate |
Compares two geometries and returns true if one Geometry is spatially related to another Geometry, by testing for intersections between the Interior, Boundary and Exterior of the two geometries. SELECT ST_Relate |
ST_SetSRID |
Sets the SRID (Spatial Reference System Identifier) of a geometry to a particular integer value. SELECT ST_SetSRID(circle.sis_geometry,4326) FROM circle; |
ST_SRID |
Returns the SRID (Spatial Reference System Identifier) of a geometry object. SELECT ST_SRID(overlay1.sis_geometry) FROM overlay1; |
ST_SRIDFromText |
Takes a text representation and a spatial reference ID and returns a geometry object. SELECT ST_SRIDFromText |
ST_SymDifference |
Returns Symmetric Difference (also available as an aggregate function) SELECT ST_SymDifference(overlay1.sis_geometry,overlay.sis_geometry) FROM overlay1,overlay2; |
ST_Touches |
Returns TRUE if the only points in common between geometry 1 and geometry 2 lie in the union of the boundaries of the two geometries. SELECT ST_Touches |
ST_Transform |
Transforms the ST_Geometry into the spatial reference specified by the spatial reference ID SRID (Spatial Reference System Identifier). SELECT ST_Transform (circles.sis_geometry, 3857) FROM circles; The overlay 'circles' was in EPSG 4326. |
ST_Union |
Returns an ST_Geometry object that is the union of two source objects. (Also available as an aggregate function). SELECT ST_Union (features.sis_geometry) FROM features WHERE Value='A'; |
ST_Within |
Returns TRUE if the first object is completely within the second. SELECT ST_Within |
The SQL console also contains the following additional non-SQL commands:
.cls |
Clears the console screen |
.echo on|off |
Turn command echo on or off |
.explain ?on|off? |
Turn output mode suitable for EXPLAIN on or off. With no args, it turns EXPLAIN on |
.headers on|off |
Turn display of headers on or off |
.help |
Shows help, ie displays this list of non-SQL commands. |
.mode MODE ?TABLE? |
Set output mode where MODE is one of:
To change mode, type .mode followed by the mode name (no semi-colon) eg “.mode find” |
.nullvalue STRING |
Use STRING in place of NULL values |
.output ?FILENAME? |
Send output to FILENAME or console |
.read FILENAME |
Execute SQL in FILENAME |
.schema TABLE |
Show the schema of TABLE |
.separator COL ?ROW? |
Change the column separator and optionally the row separator for the output mode |
.show |
Show the current values for various settings |
.tables ?TABLE? |
List names of tables. If TABLE specified, only list tables matching LIKE PATTERN ?TABLE? |
.width NUM1 NUM2 ... |
Set column widths for "column" mode. Negative values right-justify |
The Query Dataset is included; this stores the Items resulting from any SQL SELECTquery as understood by the Developer control bar SQL console.
The stored results can be refreshed using the Regenerate command and are rebuilt whenever an SWD containing a Query Dataset is re-opened.
The Execute API method is included for running any SQL query as understood by the Developer control bar SQL console, with the results returned as JSON.
Spatial joins are overloaded on the SQLite MATCH keyword, eg SELECT ovl2.*,ovl1.column1,ovl2.column2 FROM ovl2 INNER JOIN ovl1 ON ovl2.sis_geometry MATCH ovl1.sis_geometry AND ST_Intersects(ovl2.sis_geometry,ovl1.sis_geometry).
If an entry is made at the SQL> prompt which is incorrect and the ..> prompt appears, type ; to stop the process and return to the SQL> prompt.
Joining Tables
1. Adding one column to another table
At the SQL> prompt enter .mode add to set the output mode to add. Press Return.
At the SQL> prompt enter SELECT Oracle_CENSUSUK11DATA.POPY,OA2011_Greater_London.* FROM Oracle_CENSUSUK11DATA JOIN OA2011_Greater_London ON Oracle_CENSUSUK11DATA.OACODE = OA2011_Greater_London.OA11CD;
Press Return.
In this example the overlay Oracle_CENSUSUK11DATA column POPY are joined to the overlay OA2011_Greater_London table.
2. Adding multiple columns to another table
At the SQL> prompt enter .mode add to set the output mode to add. Press Return.
At the SQL> prompt enter SELECT OA2011_Greater_London.*,Oracle_CENSUSUK11DATA.POPY,Oracle_CENSUSUK11DATA.POPX FROM Oracle_CENSUSUK11DATA JOIN OA2011_Greater_London ON Oracle_CENSUSUK11DATA.OACODE = OA2011_Greater_London.OA11CD;
Press Return.
In this example the overlay Oracle_CENSUSUK11DATA columns POPX and POPY are joined to the overlay OA2011_Greater_London table.
3. Adding all columns to another table
At the SQL> prompt enter .mode add to set the output mode to add. Press Return.
At the SQL> prompt enter SELECT OA2011_Greater_London.*, Oracle_CENSUSUK11DATA.* FROM Oracle_CENSUSUK11DATA JOIN OA2011_Greater_London ON Oracle_CENSUSUK11DATA.OACODE = OA2011_Greater_London.OA11CD;
Press Return.
In this example all the columns in the overlay Oracle_CENSUSUK11DATA columns are joined to the overlay OA2011_Greater_London table.
See here for SQL examples.