|
| 1 | +[role="xpack"] |
| 2 | +[testenv="basic"] |
| 3 | +[[sql-functions-geo]] |
| 4 | +=== Geo Functions |
| 5 | + |
| 6 | +The geo functions work with geometries stored in `geo_point` and `geo_shape` fields, or returned by other geo functions. |
| 7 | + |
| 8 | +==== Limitations |
| 9 | + |
| 10 | +Both <<geo-point, `geo_point`>> and <<geo-shape, `geo_shape`>> types are represented in SQL as geometry and can be used |
| 11 | +interchangeably with the following exceptions: |
| 12 | + |
| 13 | +* `geo_shape` fields don't have doc values, therefore these fields cannot be used for filtering, grouping or sorting. |
| 14 | + |
| 15 | +* `geo_points` fields are indexed and have doc values by default, however only latitude and longitude are stored and |
| 16 | + indexed with some loss of precision from the original values (4.190951585769653E-8 for the latitude and |
| 17 | + 8.381903171539307E-8 for longitude). The altitude component is accepted but not stored in doc values nor indexed. |
| 18 | + Therefore calling `ST_Z` function in the filtering, grouping or sorting will return `null`. |
| 19 | + |
| 20 | +==== Geometry Conversion |
| 21 | + |
| 22 | +[[sql-functions-geo-st-as-wkt]] |
| 23 | +===== `ST_AsWKT` |
| 24 | + |
| 25 | +.Synopsis: |
| 26 | +[source, sql] |
| 27 | +-------------------------------------------------- |
| 28 | +ST_AsWKT(geometry<1>) |
| 29 | +-------------------------------------------------- |
| 30 | + |
| 31 | +*Input*: |
| 32 | + |
| 33 | +<1> geometry |
| 34 | + |
| 35 | +*Output*: string |
| 36 | + |
| 37 | +.Description: |
| 38 | + |
| 39 | +Returns the WKT representation of the `geometry`. |
| 40 | + |
| 41 | +["source","sql",subs="attributes,macros"] |
| 42 | +-------------------------------------------------- |
| 43 | +include-tagged::{sql-specs}/docs/geo.csv-spec[aswkt] |
| 44 | +-------------------------------------------------- |
| 45 | + |
| 46 | + |
| 47 | +[[sql-functions-geo-st-wkt-to-sql]] |
| 48 | +===== `ST_WKTToSQL` |
| 49 | + |
| 50 | +.Synopsis: |
| 51 | +[source, sql] |
| 52 | +-------------------------------------------------- |
| 53 | +ST_WKTToSQL(string<1>) |
| 54 | +-------------------------------------------------- |
| 55 | + |
| 56 | +*Input*: |
| 57 | + |
| 58 | +<1> string WKT representation of geometry |
| 59 | + |
| 60 | +*Output*: geometry |
| 61 | + |
| 62 | +.Description: |
| 63 | + |
| 64 | +Returns the geometry from WKT representation. |
| 65 | + |
| 66 | +["source","sql",subs="attributes,macros"] |
| 67 | +-------------------------------------------------- |
| 68 | +include-tagged::{sql-specs}/docs/geo.csv-spec[aswkt] |
| 69 | +-------------------------------------------------- |
| 70 | + |
| 71 | +==== Geometry Properties |
| 72 | + |
| 73 | +[[sql-functions-geo-st-geometrytype]] |
| 74 | +===== `ST_GeometryType` |
| 75 | + |
| 76 | +.Synopsis: |
| 77 | +[source, sql] |
| 78 | +-------------------------------------------------- |
| 79 | +ST_GeometryType(geometry<1>) |
| 80 | +-------------------------------------------------- |
| 81 | + |
| 82 | +*Input*: |
| 83 | + |
| 84 | +<1> geometry |
| 85 | + |
| 86 | +*Output*: string |
| 87 | + |
| 88 | +.Description: |
| 89 | + |
| 90 | +Returns the type of the `geometry` such as POINT, MULTIPOINT, LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON, GEOMETRYCOLLECTION, ENVELOPE or CIRCLE. |
| 91 | + |
| 92 | +["source","sql",subs="attributes,macros"] |
| 93 | +-------------------------------------------------- |
| 94 | +include-tagged::{sql-specs}/docs/geo.csv-spec[geometrytype] |
| 95 | +-------------------------------------------------- |
| 96 | + |
| 97 | +[[sql-functions-geo-st-x]] |
| 98 | +===== `ST_X` |
| 99 | + |
| 100 | +.Synopsis: |
| 101 | +[source, sql] |
| 102 | +-------------------------------------------------- |
| 103 | +ST_X(geometry<1>) |
| 104 | +-------------------------------------------------- |
| 105 | + |
| 106 | +*Input*: |
| 107 | + |
| 108 | +<1> geometry |
| 109 | + |
| 110 | +*Output*: double |
| 111 | + |
| 112 | +.Description: |
| 113 | + |
| 114 | +Returns the longitude of the first point in the geometry. |
| 115 | + |
| 116 | +["source","sql",subs="attributes,macros"] |
| 117 | +-------------------------------------------------- |
| 118 | +include-tagged::{sql-specs}/docs/geo.csv-spec[x] |
| 119 | +-------------------------------------------------- |
| 120 | + |
| 121 | +[[sql-functions-geo-st-y]] |
| 122 | +===== `ST_Y` |
| 123 | + |
| 124 | +.Synopsis: |
| 125 | +[source, sql] |
| 126 | +-------------------------------------------------- |
| 127 | +ST_Y(geometry<1>) |
| 128 | +-------------------------------------------------- |
| 129 | + |
| 130 | +*Input*: |
| 131 | + |
| 132 | +<1> geometry |
| 133 | + |
| 134 | +*Output*: double |
| 135 | + |
| 136 | +.Description: |
| 137 | + |
| 138 | +Returns the the latitude of the first point in the geometry. |
| 139 | + |
| 140 | +["source","sql",subs="attributes,macros"] |
| 141 | +-------------------------------------------------- |
| 142 | +include-tagged::{sql-specs}/docs/geo.csv-spec[y] |
| 143 | +-------------------------------------------------- |
| 144 | + |
| 145 | +[[sql-functions-geo-st-z]] |
| 146 | +===== `ST_Z` |
| 147 | + |
| 148 | +.Synopsis: |
| 149 | +[source, sql] |
| 150 | +-------------------------------------------------- |
| 151 | +ST_Z(geometry<1>) |
| 152 | +-------------------------------------------------- |
| 153 | + |
| 154 | +*Input*: |
| 155 | + |
| 156 | +<1> geometry |
| 157 | + |
| 158 | +*Output*: double |
| 159 | + |
| 160 | +.Description: |
| 161 | + |
| 162 | +Returns the altitude of the first point in the geometry. |
| 163 | + |
| 164 | +["source","sql",subs="attributes,macros"] |
| 165 | +-------------------------------------------------- |
| 166 | +include-tagged::{sql-specs}/docs/geo.csv-spec[z] |
| 167 | +-------------------------------------------------- |
| 168 | + |
| 169 | +[[sql-functions-geo-st-distance]] |
| 170 | +===== `ST_Distance` |
| 171 | + |
| 172 | +.Synopsis: |
| 173 | +[source, sql] |
| 174 | +-------------------------------------------------- |
| 175 | +ST_Distance(geometry<1>, geometry<2>) |
| 176 | +-------------------------------------------------- |
| 177 | + |
| 178 | +*Input*: |
| 179 | + |
| 180 | +<1> source geometry |
| 181 | +<2> target geometry |
| 182 | + |
| 183 | +*Output*: Double |
| 184 | + |
| 185 | +.Description: |
| 186 | + |
| 187 | +Returns the distance between geometries in meters. Both geometries have to be points. |
| 188 | + |
| 189 | +["source","sql",subs="attributes,macros"] |
| 190 | +-------------------------------------------------- |
| 191 | +include-tagged::{sql-specs}/docs/geo.csv-spec[distance] |
| 192 | +-------------------------------------------------- |
0 commit comments