geo.asciidoc 4.7 KB

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