geo.asciidoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. If `null`, the function returns `null`.
  28. *Output*: string
  29. *Description*: 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. If `null`, the function returns
  45. `null`.
  46. *Output*: geometry
  47. *Description*: Returns the geometry from WKT representation.
  48. ["source","sql",subs="attributes,macros"]
  49. --------------------------------------------------
  50. include-tagged::{sql-specs}/docs/geo.csv-spec[wkttosql]
  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. If `null`, the function returns `null`.
  64. *Output*: string
  65. *Description*: Returns the type of the `geometry` such as POINT, MULTIPOINT, LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON, GEOMETRYCOLLECTION, ENVELOPE or CIRCLE.
  66. ["source","sql",subs="attributes,macros"]
  67. --------------------------------------------------
  68. include-tagged::{sql-specs}/docs/geo.csv-spec[geometrytype]
  69. --------------------------------------------------
  70. [[sql-functions-geo-st-x]]
  71. ===== `ST_X`
  72. .Synopsis:
  73. [source, sql]
  74. --------------------------------------------------
  75. ST_X(
  76. geometry <1>
  77. )
  78. --------------------------------------------------
  79. *Input*:
  80. <1> geometry. If `null`, the function returns `null`.
  81. *Output*: double
  82. *Description*: Returns the longitude of the first point in the geometry.
  83. ["source","sql",subs="attributes,macros"]
  84. --------------------------------------------------
  85. include-tagged::{sql-specs}/docs/geo.csv-spec[x]
  86. --------------------------------------------------
  87. [[sql-functions-geo-st-y]]
  88. ===== `ST_Y`
  89. .Synopsis:
  90. [source, sql]
  91. --------------------------------------------------
  92. ST_Y(
  93. geometry <1>
  94. )
  95. --------------------------------------------------
  96. *Input*:
  97. <1> geometry. If `null`, the function returns `null`.
  98. *Output*: double
  99. *Description*: Returns the latitude of the first point in the geometry.
  100. ["source","sql",subs="attributes,macros"]
  101. --------------------------------------------------
  102. include-tagged::{sql-specs}/docs/geo.csv-spec[y]
  103. --------------------------------------------------
  104. [[sql-functions-geo-st-z]]
  105. ===== `ST_Z`
  106. .Synopsis:
  107. [source, sql]
  108. --------------------------------------------------
  109. ST_Z(
  110. geometry <1>
  111. )
  112. --------------------------------------------------
  113. *Input*:
  114. <1> geometry. If `null`, the function returns `null`.
  115. *Output*: double
  116. *Description*: Returns the altitude of the first point in the geometry.
  117. ["source","sql",subs="attributes,macros"]
  118. --------------------------------------------------
  119. include-tagged::{sql-specs}/docs/geo.csv-spec[z]
  120. --------------------------------------------------
  121. [[sql-functions-geo-st-distance]]
  122. ===== `ST_Distance`
  123. .Synopsis:
  124. [source, sql]
  125. --------------------------------------------------
  126. ST_Distance(
  127. geometry, <1>
  128. geometry <2>
  129. )
  130. --------------------------------------------------
  131. *Input*:
  132. <1> source geometry. If `null`, the function returns `null`.
  133. <2> target geometry. If `null`, the function returns `null`.
  134. *Output*: Double
  135. *Description*: Returns the distance between geometries in meters. Both geometries have to be points.
  136. ["source","sql",subs="attributes,macros"]
  137. --------------------------------------------------
  138. include-tagged::{sql-specs}/docs/geo.csv-spec[distance]
  139. --------------------------------------------------