geo.asciidoc 4.7 KB

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