geo.asciidoc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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(geometry<1>)
  22. --------------------------------------------------
  23. *Input*:
  24. <1> geometry
  25. *Output*: string
  26. .Description:
  27. Returns the WKT representation of the `geometry`.
  28. ["source","sql",subs="attributes,macros"]
  29. --------------------------------------------------
  30. include-tagged::{sql-specs}/docs/geo.csv-spec[aswkt]
  31. --------------------------------------------------
  32. [[sql-functions-geo-st-wkt-to-sql]]
  33. ===== `ST_WKTToSQL`
  34. .Synopsis:
  35. [source, sql]
  36. --------------------------------------------------
  37. ST_WKTToSQL(string<1>)
  38. --------------------------------------------------
  39. *Input*:
  40. <1> string WKT representation of geometry
  41. *Output*: geometry
  42. .Description:
  43. Returns the geometry from WKT representation.
  44. ["source","sql",subs="attributes,macros"]
  45. --------------------------------------------------
  46. include-tagged::{sql-specs}/docs/geo.csv-spec[aswkt]
  47. --------------------------------------------------
  48. ==== Geometry Properties
  49. [[sql-functions-geo-st-geometrytype]]
  50. ===== `ST_GeometryType`
  51. .Synopsis:
  52. [source, sql]
  53. --------------------------------------------------
  54. ST_GeometryType(geometry<1>)
  55. --------------------------------------------------
  56. *Input*:
  57. <1> geometry
  58. *Output*: string
  59. .Description:
  60. Returns the type of the `geometry` such as POINT, MULTIPOINT, LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON, GEOMETRYCOLLECTION, ENVELOPE or CIRCLE.
  61. ["source","sql",subs="attributes,macros"]
  62. --------------------------------------------------
  63. include-tagged::{sql-specs}/docs/geo.csv-spec[geometrytype]
  64. --------------------------------------------------
  65. [[sql-functions-geo-st-x]]
  66. ===== `ST_X`
  67. .Synopsis:
  68. [source, sql]
  69. --------------------------------------------------
  70. ST_X(geometry<1>)
  71. --------------------------------------------------
  72. *Input*:
  73. <1> geometry
  74. *Output*: double
  75. .Description:
  76. Returns the longitude of the first point in the geometry.
  77. ["source","sql",subs="attributes,macros"]
  78. --------------------------------------------------
  79. include-tagged::{sql-specs}/docs/geo.csv-spec[x]
  80. --------------------------------------------------
  81. [[sql-functions-geo-st-y]]
  82. ===== `ST_Y`
  83. .Synopsis:
  84. [source, sql]
  85. --------------------------------------------------
  86. ST_Y(geometry<1>)
  87. --------------------------------------------------
  88. *Input*:
  89. <1> geometry
  90. *Output*: double
  91. .Description:
  92. Returns the the latitude of the first point in the geometry.
  93. ["source","sql",subs="attributes,macros"]
  94. --------------------------------------------------
  95. include-tagged::{sql-specs}/docs/geo.csv-spec[y]
  96. --------------------------------------------------
  97. [[sql-functions-geo-st-z]]
  98. ===== `ST_Z`
  99. .Synopsis:
  100. [source, sql]
  101. --------------------------------------------------
  102. ST_Z(geometry<1>)
  103. --------------------------------------------------
  104. *Input*:
  105. <1> geometry
  106. *Output*: double
  107. .Description:
  108. Returns the altitude of the first point in the geometry.
  109. ["source","sql",subs="attributes,macros"]
  110. --------------------------------------------------
  111. include-tagged::{sql-specs}/docs/geo.csv-spec[z]
  112. --------------------------------------------------
  113. [[sql-functions-geo-st-distance]]
  114. ===== `ST_Distance`
  115. .Synopsis:
  116. [source, sql]
  117. --------------------------------------------------
  118. ST_Distance(geometry<1>, geometry<2>)
  119. --------------------------------------------------
  120. *Input*:
  121. <1> source geometry
  122. <2> target geometry
  123. *Output*: Double
  124. .Description:
  125. Returns the distance between geometries in meters. Both geometries have to be points.
  126. ["source","sql",subs="attributes,macros"]
  127. --------------------------------------------------
  128. include-tagged::{sql-specs}/docs/geo.csv-spec[distance]
  129. --------------------------------------------------