geo.asciidoc 4.7 KB

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