blob: 66aef9bd3022c5cbfe6ee95c048fefb2ab761180 [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.8.1 from src/site/markdown/geo/functions.md at 2022-05-12
| Rendered using Apache Maven Fluido Skin 1.7
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="Date-Revision-yyyymmdd" content="20220512" />
<meta http-equiv="Content-Language" content="en" />
<title>AsterixDB &#x2013; Support the standard GIS objects (DRAFT)</title>
<link rel="stylesheet" href="../css/apache-maven-fluido-1.7.min.css" />
<link rel="stylesheet" href="../css/site.css" />
<link rel="stylesheet" href="../css/print.css" media="print" />
<script type="text/javascript" src="../js/apache-maven-fluido-1.7.min.js"></script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left"><a href=".././" id="bannerLeft"><img src="../images/asterixlogo.png" alt="AsterixDB"/></a></div>
<div class="pull-right"></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2022-05-12</li>
<li id="projectVersion" class="pull-right">Version: 0.9.8</li>
<li class="pull-right"><a href="../index.html" title="Documentation Home">Documentation Home</a></li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span2">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Get Started - Installation</li>
<li><a href="../ncservice.html" title="Option 1: using NCService"><span class="none"></span>Option 1: using NCService</a></li>
<li><a href="../ansible.html" title="Option 2: using Ansible"><span class="none"></span>Option 2: using Ansible</a></li>
<li><a href="../aws.html" title="Option 3: using Amazon Web Services"><span class="none"></span>Option 3: using Amazon Web Services</a></li>
<li class="nav-header">AsterixDB Primer</li>
<li><a href="../sqlpp/primer-sqlpp.html" title="Using SQL++"><span class="none"></span>Using SQL++</a></li>
<li class="nav-header">Data Model</li>
<li><a href="../datamodel.html" title="The Asterix Data Model"><span class="none"></span>The Asterix Data Model</a></li>
<li class="nav-header">Queries</li>
<li><a href="../sqlpp/manual.html" title="The SQL++ Query Language"><span class="none"></span>The SQL++ Query Language</a></li>
<li><a href="../SQLPP.html" title="Raw SQL++ Grammar"><span class="none"></span>Raw SQL++ Grammar</a></li>
<li><a href="../sqlpp/builtins.html" title="Builtin Functions"><span class="none"></span>Builtin Functions</a></li>
<li class="nav-header">API/SDK</li>
<li><a href="../api.html" title="HTTP API"><span class="none"></span>HTTP API</a></li>
<li><a href="../csv.html" title="CSV Output"><span class="none"></span>CSV Output</a></li>
<li class="nav-header">Advanced Features</li>
<li><a href="../aql/externaldata.html" title="Accessing External Data"><span class="none"></span>Accessing External Data</a></li>
<li><a href="../feeds.html" title="Data Ingestion with Feeds"><span class="none"></span>Data Ingestion with Feeds</a></li>
<li><a href="../udf.html" title="User Defined Functions"><span class="none"></span>User Defined Functions</a></li>
<li><a href="../sqlpp/filters.html" title="Filter-Based LSM Index Acceleration"><span class="none"></span>Filter-Based LSM Index Acceleration</a></li>
<li><a href="../sqlpp/fulltext.html" title="Support of Full-text Queries"><span class="none"></span>Support of Full-text Queries</a></li>
<li><a href="../sqlpp/similarity.html" title="Support of Similarity Queries"><span class="none"></span>Support of Similarity Queries</a></li>
<li><a href="../geo/quickstart.html" title="GIS Support Overview"><span class="none"></span>GIS Support Overview</a></li>
<li class="active"><a href="#"><span class="none"></span>GIS Functions</a></li>
<li><a href="../interval_join.html" title="Support of Interval Joins"><span class="none"></span>Support of Interval Joins</a></li>
<li><a href="../spatial_join.html" title="Support of Spatial Joins"><span class="none"></span>Support of Spatial Joins</a></li>
<li><a href="../sqlpp/arrayindex.html" title="Support of Array Indexes"><span class="none"></span>Support of Array Indexes</a></li>
<li class="nav-header">Deprecated</li>
<li><a href="../aql/primer.html" title="AsterixDB Primer: Using AQL"><span class="none"></span>AsterixDB Primer: Using AQL</a></li>
<li><a href="../aql/manual.html" title="Queries: The Asterix Query Language (AQL)"><span class="none"></span>Queries: The Asterix Query Language (AQL)</a></li>
<li><a href="../aql/builtins.html" title="Queries: Builtin Functions (AQL)"><span class="none"></span>Queries: Builtin Functions (AQL)</a></li>
</ul>
<hr />
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href=".././" title="AsterixDB" class="builtBy"><img class="builtBy" alt="AsterixDB" src="../images/asterixlogo.png" /></a>
</div>
</div>
</div>
<div id="bodyColumn" class="span10" >
<!--
! Licensed to the Apache Software Foundation (ASF) under one
! or more contributor license agreements. See the NOTICE file
! distributed with this work for additional information
! regarding copyright ownership. The ASF licenses this file
! to you under the Apache License, Version 2.0 (the
! "License"); you may not use this file except in compliance
! with the License. You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing,
! software distributed under the License is distributed on an
! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
! KIND, either express or implied. See the License for the
! specific language governing permissions and limitations
! under the License.
!-->
<h1>Support the standard GIS objects (DRAFT)</h1>
<div class="section">
<h2><a name="Table_of_Contents"></a><a name="toc" id="toc">Table of Contents</a></h2>
<ul>
<li><a href="#Introduction">Introduction</a></li>
<li><a href="#construction">Construction functions</a></li>
<li><a href="#primitive">Primitive functions</a></li>
<li><a href="#predicate">Spatial Predicate</a></li>
<li><a href="#analysis">Spatial Analysis</a></li>
<li><a href="#aggregate">Spatial Aggregates</a></li>
</ul></div>
<div class="section">
<h2><a name="Introduction" id="Introduction">Introduction</a></h2>
<p>To support standard GIS objects in AsterixDB, you need to use the <tt>geometry</tt> data type as follows.</p>
<div>
<div>
<pre class="source">DROP dataverse GeoJSON if exists;
CREATE dataverse GeoJSON;
USE GeoJSON;
CREATE TYPE GeometryType AS{
id : int,
myGeometry : geometry
};
CREATE DATASET Geometries (GeometryType) PRIMARY KEY id;
</pre></div></div>
<p>Please note that even though the <a class="externalLink" href="http://desktop.arcgis.com/en/arcmap/10.3/manage-data/using-sql-with-gdbs/what-is-an-srid.htm">SRID</a> input is supported for certain functions and is represented internally in the correct manner the serialized result (printed in the output) displays the SRID as 4326 always because of the limitations in Esri API.</p></div>
<div class="section">
<h2><a name="Construction_functions"></a><a name="construction" id="construction">Construction functions</a></h2>
<p>The Geometry datatype can be created by the constructor functions.</p>
<div class="section">
<h3><a name="st_make_point"></a>st_make_point</h3>
<ul>
<li>
<p>Creates a 2D,3DZ or 4D point geometry.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Create a 2D point at coordinates (x,y) = (-71, 42)</li>
<li>Command:
<div>
<div>
<pre class="source">st_make_point(-71, 42);
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[-71,42],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
<li>Example:</li>
<li>Create a 3D point at coordinates (x,y,z) = (1,2,1.59)</li>
<li>Command:
<div>
<div>
<pre class="source">st_make_point(1,2,1.59);
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[1,2,1.59],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_geom_from_text"></a>st_geom_from_text</h3>
<ul>
<li>
<p>Return a specified ST_Geometry value from Well-Known Text representation (WKT).</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Create a LineString geometry from the WKT format.</li>
<li>Command:
<div>
<div>
<pre class="source">st_geom_from_text(&quot;LINESTRING(1 2,3 4,5 6)&quot;);
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;LineString&quot;,&quot;coordinates&quot;:[[1,2],[3,4],[5,6]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
<li>Example:</li>
<li>Create a MultiLineString geometry from the WKT format.</li>
<li>Command:
<div>
<div>
<pre class="source">st_geom_from_text('MULTILINESTRING((1 2,3 4,5 6),(7 8,9 10))');
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;MultiLineString&quot;,&quot;coordinates&quot;:[[[1,2],[3,4],[5,6]],[[7,8],[9,10]]],&quot;crs&quot;:null}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_geom_from_wkb"></a>st_geom_from_wkb</h3>
<ul>
<li>
<p>Creates a geometry instance from a Well-Known Binary geometry representation (WKB) and optional SRID.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_geom_from_wkb(hex(&quot;010100000000000000000000400000000000001440&quot;));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[2,5],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_geom_from_geojson"></a>st_geom_from_geojson</h3>
<ul>
<li>
<p>Creates a geometry instance from its GeoJSON representation</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_geom_from_geojson({&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[2,5],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}});
</pre></div></div>
</li>
<li>
<p>Result:</p>
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[2,5],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_make_envelope"></a>st_make_envelope</h3>
<ul>
<li>
<p>Creates a rectangular Polygon formed from the given minimums and maximums. Input values must be in SRS specified by the SRID.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_make_envelope(10, 10, 11, 11, 4326);
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Polygon&quot;,&quot;coordinates&quot;:[[[10,10],[11,10],[11,11],[10,11],[10,10]]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div></div>
<div class="section">
<h2><a name="Primitive_functions"></a><a name="primitive" id="primitive">Primitive functions</a></h2>
<p>There are primitive functions that take as input geometry/es and return a primitive type.</p>
<div class="section">
<h3><a name="st_area"></a>st_area</h3>
<ul>
<li>
<p>Return the area of the surface if it is a Polygon or MultiPolygon. For geometry, a 2D Cartesian area is determined with units specified by the SRID. For geography, area is determined on a curved surface with units in square meters.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_area(st_geom_from_text('POLYGON((7 2,4 9,3 6,2.6 7,8 16))'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">26.500000000000007
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_coord_dim"></a>st_coord_dim</h3>
<ul>
<li>
<p>Return the coordinate dimension of the Geometry value.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_coord_dim(st_make_point(1,2));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">2
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_dimension"></a>st_dimension</h3>
<ul>
<li>
<p>Return the inherent dimension of this Geometry object, which must be less than or equal to the coordinate dimension.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_dimension(st_geom_from_text('GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0))'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">1
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="geometry_type"></a>geometry_type</h3>
<ul>
<li>
<p>Return the type of the geometry as a string. Eg: &#x2018;LINESTRING&#x2019;, &#x2018;POLYGON&#x2019;, &#x2018;MULTIPOINT&#x2019;, etc.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">geometry_type(st_geom_from_text('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">&quot;LineString&quot;
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_m"></a>st_m</h3>
<ul>
<li>
<p>Return the M coordinate of the point, or NULL if not available. Input must be a point.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_m(st_make_point(1, 2, 3, 4));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">4.0
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_n_points"></a>st_n_points</h3>
<ul>
<li>
<p>Return the number of points (vertexes) in a geometry.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_n_points(st_geom_from_text('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">4
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_n_rings"></a>st_n_rings</h3>
<ul>
<li>
<p>If the geometry is a polygon or multi-polygon return the number of rings.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_n_rings(st_geom_from_text('POLYGON((10.689 -25.092, 34.595 -20.170, 38.814 -35.639, 13.502 -39.155, 10.689 -25.092))'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">1
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_num_geometries"></a>st_num_geometries</h3>
<ul>
<li>
<p>If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the number of geometries, for single geometries will return 1, otherwise return NULL.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_num_geometries(st_geom_from_text('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">1
</pre></div></div>
</li>
<li>Example:</li>
<li>Command:
<div>
<div>
<pre class="source">st_num_geometries(st_geom_from_text('GEOMETRYCOLLECTION(MULTIPOINT(-2 3 , -2 2), LINESTRING(5 5 ,10 10), POLYGON((-7 4.2,-7.1 5,-7.1 4.3,-7 4.2)))'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">3
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_num_interiorRings"></a>st_num_interiorRings</h3>
<ul>
<li>
<p>Return the number of interior rings of a polygon geometry.</p>
</li>
<li>
<p>Example:</p>
</li>
</ul>
<p><img src="../images/linestring.png" alt="Image of interiorRings" /> * Command:</p>
<div>
<div>
<pre class="source"> st_num_interior_rings(st_geom_from_text(&quot;POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))&quot;));
</pre></div></div>
<ul>
<li>Result:
<div>
<div>
<pre class="source">1
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_x"></a>st_x</h3>
<ul>
<li>
<p>Return the X coordinate of the point, or NULL if not available. Input must be a point.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_x(st_make_point(1, 2, 3, 4));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">1.0
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_y"></a>st_y</h3>
<ul>
<li>
<p>Return the Y coordinate of the point, or NULL if not available. Input must be a point.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_y(st_make_point(1, 2, 3, 4));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">1.0
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_x_max"></a>st_x_max</h3>
<ul>
<li>
<p>Return X maximum of a bounding box 2d or 3d or a geometry.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_x_max(st_geom_from_text('POLYGON((10.689 -25.092, 34.595 -20.170, 38.814 -35.639, 13.502 -39.155, 10.689 -25.092))'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">38.814
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_x_min"></a>st_x_min</h3>
<ul>
<li>Return X minimum of a bounding box 2d or 3d or a geometry.</li>
</ul></div>
<div class="section">
<h3><a name="st_y_max"></a>st_y_max</h3>
<ul>
<li>Return Y maximum of a bounding box 2d or 3d or a geometry.</li>
</ul></div>
<div class="section">
<h3><a name="st_y_min"></a>st_y_min</h3>
<ul>
<li>Return Y minimum of a bounding box 2d or 3d or a geometry.</li>
</ul></div>
<div class="section">
<h3><a name="st_z"></a>st_z</h3>
<ul>
<li>Return the Z coordinate of the point, or NULL if not available. Input must be a point.</li>
</ul></div>
<div class="section">
<h3><a name="st_z_max"></a>st_z_max</h3>
<ul>
<li>Return Z maximum of a bounding box 2d or 3d or a geometry.</li>
</ul></div>
<div class="section">
<h3><a name="st_z_min"></a>st_z_min</h3>
<ul>
<li>Return Z minimum of a bounding box 2d or 3d or a geometry.</li>
</ul></div>
<div class="section">
<h3><a name="st_as_binary"></a>st_as_binary</h3>
<ul>
<li>
<p>Return the Well-Known Binary (WKB) representation of the geometry/geography without SRID meta data.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_as_binary(st_geom_from_geojson({&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[2,5],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">&quot;010100000000000000000000400000000000001440&quot;
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_as_geojson"></a>st_as_geojson</h3>
<ul>
<li>
<p>Return the geometry as a GeoJSON element.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_as_geojson(st_geom_from_text('POLYGON((10.689 -25.092, 34.595 -20.170, 38.814 -35.639, 13.502 -39.155, 10.689 -25.092))'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">&quot;{\&quot;type\&quot;:\&quot;Polygon\&quot;,\&quot;coordinates\&quot;:[[[10.689,-25.092],[13.502,-39.155],[38.814,-35.639],[34.595,-20.17],[10.689,-25.092]]],\&quot;crs\&quot;:{\&quot;type\&quot;:\&quot;name\&quot;,\&quot;properties\&quot;:{\&quot;name\&quot;:\&quot;EPSG:4326\&quot;}}}&quot;
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_distance"></a>st_distance</h3>
<ul>
<li>
<p>For geometry type Return the 2D Cartesian distance between two geometries in projected units (based on spatial ref). For geography type defaults to return minimum geodesic distance between two geographies in meters.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_distance(st_geom_from_text('POINT(-72.1235 42.3521)'),st_geom_from_text('LINESTRING(-72.1260 42.45, -72.123 42.1546)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">0.0015056772638282166
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_length"></a>st_length</h3>
<ul>
<li>
<p>Return the 2D length of the geometry if it is a LineString or MultiLineString. geometry are in units of spatial reference and geography are in meters (default spheroid).</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_length(st_geom_from_text('LINESTRING(-72.1260 42.45, -72.1240 42.45666, -72.123 42.1546)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">0.30901547439030225
</pre></div></div>
</li>
</ul></div></div>
<div class="section">
<h2><a name="Spatial_Predicate"></a><a name="predicate" id="predicate">Spatial Predicate</a></h2>
<p>Spatial predicate functions test for a relationship between two geometries and return a Boolean value (true/false).</p>
<div class="section">
<h3><a name="st_intersects"></a>st_intersects</h3>
<ul>
<li>
<p>Return TRUE if the Geometries/Geography &#x201c;spatially intersect in 2D&#x201d;.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_intersects(st_geom_from_text('POINT(0 0)'), st_geom_from_text('LINESTRING ( 0 0, 0 2 )'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_isclosed"></a>st_isclosed</h3>
<ul>
<li>
<p>Return TRUE if the LINESTRING&#x2019;s start and end points are coincident.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_is_closed(st_geom_from_text('LINESTRING(0 0, 0 1, 1 1, 0 0)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_iscollection"></a>st_iscollection</h3>
<ul>
<li>
<p>Return TRUE if the argument is a collection (MULTI*, GEOMETRYCOLLECTION, &#x2026;)</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_is_collection(st_geom_from_text('MULTIPOINT EMPTY'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_is_empty"></a>st_is_empty</h3>
<ul>
<li>
<p>Return true if this Geometry is an empty geometrycollection, polygon, point etc.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_is_empty(st_geom_from_text('POLYGON EMPTY'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_is_ring"></a>st_is_ring</h3>
<ul>
<li>
<p>Return TRUE if this LINESTRING is both closed and simple.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_is_ring(st_geom_from_text('LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_is_simple"></a>st_is_simple</h3>
<ul>
<li>
<p>Return (TRUE) if this Geometry has no anomalous geometric points, such as self intersection or self tangency.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_is_simple(st_geom_from_text('LINESTRING(1 1,2 2,2 3.5,1 3,1 2,2 1)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">false
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_contains"></a>st_contains</h3>
<ul>
<li>
<p>Return 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.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_contains(st_geom_from_text('LINESTRING(1 1,-1 -1,2 3.5,1 3,1 2,2 1)'), st_make_point(-1, -1));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_crosses"></a>st_crosses</h3>
<ul>
<li>
<p>Return TRUE if the supplied geometries have some, but not all, interior points in common.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_crosses(st_geom_from_text('LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)'), st_geom_from_text('LINESTRING(0 2,1 2,2 2,3 2,4 2,5 2)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_disjoint"></a>st_disjoint</h3>
<ul>
<li>
<p>Return TRUE if the Geometries do not &#x201c;spatially intersect&#x201d; - if they do not share any space together.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_disjoint(st_geom_from_text('LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)'), st_geom_from_text('POINT(0 0)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_equals"></a>st_equals</h3>
<ul>
<li>
<p>Return true if the given geometries represent the same geometry. Directionality is ignored.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_equals(st_geom_from_text('LINESTRING(0 0, 10 10)'), st_geom_from_text('LINESTRING(0 0, 5 5, 10 10)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_overlaps"></a>st_overlaps</h3>
<ul>
<li>
<p>Return TRUE if the Geometries share space, are of the same dimension, but are not completely contained by each other.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_overlaps(st_geom_from_text('LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)'), st_geom_from_text('LINESTRING(0 2,1 2,2 2,3 3,4 2,5 2)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_relate"></a>st_relate</h3>
<ul>
<li>
<p>Return true if this Geometry is spatially related to anotherGeometry, by testing for intersections between the Interior, Boundary and Exterior of the two geometries as specified by the values in the intersectionMatrixPattern.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_relate(st_geom_from_text('LINESTRING(1 2, 3 4)'), st_geom_from_text('LINESTRING(5 6, 7 8)'), &quot;FF1FF0102&quot;);
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_touches"></a>st_touches</h3>
<ul>
<li>
<p>Return TRUE if the geometries have at least one point in common, but their interiors do not intersect.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_touches(st_geom_from_text('LINESTRING(0 0, 1 1, 0 2)'), st_geom_from_text('POINT(0 2)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">true
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_within"></a>st_within</h3>
<ul>
<li>Return true if the geometry A is completely inside geometry B.</li>
</ul></div></div>
<div class="section">
<h2><a name="Spatial_Analysis"></a><a name="analysis" id="analysis">Spatial Analysis</a></h2>
<p>Spatial analysis functions take as input one or more geometries and return a geometry as output.</p>
<div class="section">
<h3><a name="st_union"></a>st_union</h3>
<ul>
<li>
<p>Return a geometry that represents the point set union of the Geometries.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_union(st_geom_from_text('LINESTRING(0 0, 1 1, 0 2)'), st_geom_from_text('POINT(0 2)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;LineString&quot;,&quot;coordinates&quot;:[[0,0],[1,1],[0,2]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_boundary"></a>st_boundary</h3>
<ul>
<li>
<p>Return the closure of the combinatorial boundary of this Geometry.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_boundary(st_geom_from_text('POLYGON((1 1,0 0, -1 1, 1 1))'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;MultiLineString&quot;,&quot;coordinates&quot;:[[[1,1],[-1,1],[0,0],[1,1]]],&quot;crs&quot;:null}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_end_point"></a>st_end_point</h3>
<ul>
<li>
<p>Return the last point of a LINESTRING or CIRCULARLINESTRING geometry as a POINT.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_end_point(st_geom_from_text('LINESTRING(1 1, 2 2, 3 3)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[3,3],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_envelope"></a>st_envelope</h3>
<ul>
<li>
<p>Return a geometry representing the double precision (float8) bounding box of the supplied geometry.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_envelope(st_geom_from_text('LINESTRING(1 1, 2 2, 3 3)'));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Polygon&quot;,&quot;coordinates&quot;:[[[1,1],[3,1],[3,3],[1,3],[1,1]]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_exterior_ring"></a>st_exterior_ring</h3>
<ul>
<li>
<p>Return a line string representing the exterior ring of the POLYGON geometry. Return NULL if the geometry is not a polygon. Will not work with MULTIPOLYGON.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_exterior_ring(st_geom_from_text(&quot;POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))&quot;));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;LineString&quot;,&quot;coordinates&quot;:[[35,10],[45,45],[15,40],[10,20],[35,10]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_geometry_n"></a>st_geometry_n</h3>
<ul>
<li>
<p>Return the 1-based Nth geometry if the geometry is a GEOMETRYCOLLECTION, (MULTI)POINT, (MULTI)LINESTRING, MULTICURVE or (MULTI)POLYGON, POLYHEDRALSURFACE. Otherwise, return NULL.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_geometry_n(st_geom_from_text('GEOMETRYCOLLECTION(MULTIPOINT(-2 3 , -2 2),LINESTRING(5 5 ,10 10),POLYGON((-7 4.2,-7.1 5,-7.1 4.3,-7 4.2)))'),2);
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Polygon&quot;,&quot;coordinates&quot;:[[[-7,4.2],[-7.1,5],[-7.1,4.3],[-7,4.2]]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_interior_ring_n"></a>st_interior_ring_n</h3>
<ul>
<li>
<p>Return the Nth interior linestring ring of the polygon geometry. Return NULL if the geometry is not a polygon or the given N is out of range.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_interior_ring_n(st_geom_from_text(&quot;POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))&quot;), 0);
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;LineString&quot;,&quot;coordinates&quot;:[[20,30],[35,35],[30,20],[20,30]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_point_n"></a>st_point_n</h3>
<ul>
<li>
<p>Return the Nth point in the first LineString or circular LineString in the geometry. Negative values are counted backwards from the end of the LineString. Return NULL if there is no linestring in the geometry.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_point_n(st_geom_from_text(&quot;LINESTRING(1 1, 2 2, 3 3)&quot;), 1);
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[2,2],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_start_point"></a>st_start_point</h3>
<ul>
<li>
<p>Return the first point of a LINESTRING geometry as a POINT.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_start_point(st_geom_from_text(&quot;LINESTRING(1 1, 2 2, 3 3)&quot;));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;Point&quot;,&quot;coordinates&quot;:[1,1],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_difference"></a>st_difference</h3>
<ul>
<li>
<p>Return a geometry that represents that part of geometry A that does not intersect with geometry B.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_difference(st_geom_from_text(&quot;LINESTRING(1 1, 2 2, 3 3)&quot;), st_geom_from_text(&quot;POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))&quot;));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;LineString&quot;,&quot;coordinates&quot;:[[1,1],[2,2],[3,3]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_intersection"></a>st_intersection</h3>
<ul>
<li>
<p>Return a geometry that represents the shared portion of geomA and geomB.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_intersection(st_geom_from_text(&quot;LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)&quot;), st_geom_from_text(&quot;LINESTRING(0 2,1 2,2 2,3 3,4 2,5 2)&quot;));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;LineString&quot;,&quot;coordinates&quot;:[[2,2],[3,3]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_sym_difference"></a>st_sym_difference</h3>
<ul>
<li>
<p>Return a geometry that represents the portions of A and B that do not intersect. It is called a symmetric difference because ST_SymDifference(A,B) = ST_SymDifference(B,A).</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_sym_difference(st_geom_from_text(&quot;LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)&quot;), st_geom_from_text(&quot;LINESTRING(0 2,1 2,2 2,3 3,4 2,5 2)&quot;));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;MultiLineString&quot;,&quot;coordinates&quot;:[[[0,2],[1,2],[2,2],[1,1]],[[5,2],[4,2],[3,3],[4,4],[5,5],[6,6]]],&quot;crs&quot;:null}
</pre></div></div>
</li>
</ul></div>
<div class="section">
<h3><a name="st_polygonize"></a>st_polygonize</h3>
<ul>
<li>
<p>Aggregate. Creates a GeometryCollection containing possible polygons formed from the constituent linework of a set of geometries.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_polygonize([st_geom_from_text(&quot;LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)&quot;), st_geom_from_text(&quot;LINESTRING(0 2,1 2,2 2,3 3,4 2,5 2)&quot;)]);
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;GeometryCollection&quot;,&quot;geometries&quot;:[{&quot;type&quot;:&quot;LineString&quot;,&quot;coordinates&quot;:[[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]]},{&quot;type&quot;:&quot;LineString&quot;,&quot;coordinates&quot;:[[0,2],[1,2],[2,2],[3,3],[4,2],[5,2]]}],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div></div>
<div class="section">
<h2><a name="Spatial_Aggregates"></a><a name="aggregate" id="aggregate">Spatial Aggregates</a></h2>
<p>spatial aggregate function which takes as input a set of geometries and return one geometry as the result.</p>
<div class="section">
<h3><a name="st_union"></a>st_union</h3>
<ul>
<li>
<p>Returns a geometry that represents the point set union of the Geometries.</p>
</li>
<li>
<p>Example:</p>
</li>
<li>Command:
<div>
<div>
<pre class="source">st_union((SELECT VALUE gbu FROM [st_make_point(1.0,1.0),st_make_point(1.0,2.0)] as gbu));
</pre></div></div>
</li>
<li>Result:
<div>
<div>
<pre class="source">{&quot;type&quot;:&quot;MultiPoint&quot;,&quot;coordinates&quot;:[[1,1],[1,2]],&quot;crs&quot;:{&quot;type&quot;:&quot;name&quot;,&quot;properties&quot;:{&quot;name&quot;:&quot;EPSG:4326&quot;}}}
</pre></div></div>
</li>
</ul></div></div>
</div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<div class="row-fluid">Apache AsterixDB, AsterixDB, Apache, the Apache
feather logo, and the Apache AsterixDB project logo are either
registered trademarks or trademarks of The Apache Software
Foundation in the United States and other countries.
All other marks mentioned may be trademarks or registered
trademarks of their respective owners.
</div>
</div>
</div>
</footer>
</body>
</html>