Skip to main content
The following sections demonstrate how to ingest and work with WKT data as well as how to use geospatial functions via SQL and the Kinetica Python API. Details about the geospatial functions can be found under Geospatial/Geometry Functions. All geospatial functions are compatible in both native API and SQL.

Prerequisites

Loading Sample Data

Data loading will be done via SQL. First log in to the database:
Create a schema to house the example tables.
Create Geospatial Example Schema
Create tables for geospatial & temporal data within the schema.
Create NYC Neighborhood Shape Table
Create NYC Taxi Trip Table
Create NYC Taxi Zone Shape Table
Populate the example tables with source data. The files are staged into KiFS from the directory that is local to where KiSQL is running. From there, each is loaded into its respective table. Modify these statements as necessary to reflect the location of the data files on the client machine.
Create KiFS Directory for Geospatial Data Files
Stage NYC Neighborhood Data
Load NYC Neighborhood Data
Stage NYC Taxi Trip Data
Load NYC Taxi Trip Data
Stage NYC Taxi Zone Data
Load NYC Taxi Zone Data

Examples via SQL

Creating a Table and Inserting WKT Data

First, a points-of-interest table is created and loaded with sample WKT data.
Create POI Table
Then, data is inserted into the WKT table.
Populate POI Table

Scalar Functions

For the complete list of scalar functions, see both Scalar Functions and Enhanced Performance Scalar Functions.
GEODIST Example
ST_AREA Example

Aggregation Functions

For the complete list of aggregation functions, see Aggregation Functions.
ST_DISSOLVE Example
Below is a picture of the dissolved neighborhood boundaries: queens_neighborhoods.png

Joins

Many geospatial/geometry functions can be used to join data sets. For the complete list of join and other scalar functions, see both Scalar Functions and Enhanced Performance Scalar Functions.
Implicit Geospatial Containment Join
Explicit Geospatial Intersection Join
In some cases, it may be useful to aggregate on the geospatial column itself, applying standard aggregation functions to other joined columns.
Explicit Geospatial Intersection Join with Geospatial Aggregation

Equality

There are three ways of checking if two geometries are equal, which each have different thresholds:
  • ST_EQUALS()
  • ST_ALMOSTEQUALS()
  • ST_EQUALSEXACT()
For details on these functions see Scalar Functions. The data inserted in the first section includes two POINTs that vary slightly in precision, two POLYGONs that vary in the ordering of their boundary points, and two pairs of LINESTRINGs that vary in both precision and scale. Each of these geometry types is compared to see if each given pair is spatially equal as defined by the equality functions:
Equality Comparisons Between Two Points

Examples via the Python API

Creating a Table and Inserting WKT Data

First, a points-of-interest table is created and loaded with sample WKT data.
Create POI Table
Then, data is inserted into the WKT table, and the insertion is verified.
Populate POI Table

Scalar Functions

For the complete list of scalar functions, see both Scalar Functions and Enhanced Performance Scalar Functions.
GEODIST Example
ST_AREA Example

Aggregation Functions

For the complete list of aggregation functions, see Aggregation Functions.
ST_DISSOLVE Example
Below is a picture of the dissolved neighborhood boundaries: queens_neighborhoods.png

Joins

Many geospatial/geometry functions can be used to join data sets. For the complete list of join and other scalar functions, see both Scalar Functions and Enhanced Performance Scalar Functions.
Implicit Geospatial Containment Join
Implicit Geospatial Intersection Join
In some cases, it may be useful to aggregate on the geospatial column itself, applying standard aggregation functions to other joined columns.
Implicit Geospatial Intersection Join with Geospatial Aggregation

Equality

There are three ways of checking if two geometries are equal, which each have different thresholds:
  • ST_EQUALS()
  • ST_ALMOSTEQUALS()
  • ST_EQUALSEXACT()
For details on these functions see Scalar Functions. The data inserted in the first section includes two POINTs that vary slightly in precision, two POLYGONs that vary in the ordering of their boundary points, and two pairs of LINESTRINGs that vary in both precision and scale. Each of these geometry types is compared to see if each given pair is spatially equal as defined by the equality functions:
Equality Comparisons Between Two Points

Complete Samples

Included below are complete examples containing all the above requests and the output.