geo.asciidoc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. [role="xpack"]
  2. [[sql-functions-geo]]
  3. === Geo Functions
  4. beta[]
  5. The geo functions work with geometries stored in `geo_point`, `geo_shape` and `shape` fields, or returned by other geo functions.
  6. ==== Limitations
  7. <<geo-point, `geo_point`>>, <<geo-shape, `geo_shape`>> and <<shape, `shape`>> and types are represented in SQL as
  8. geometry and can be used interchangeably with the following exceptions:
  9. * `geo_shape` and `shape` fields don't have doc values, therefore these fields cannot be used for filtering, grouping
  10. 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. If `null`, the function returns `null`.
  27. *Output*: string
  28. *Description*: Returns the WKT representation of the `geometry`.
  29. ["source","sql",subs="attributes,macros"]
  30. --------------------------------------------------
  31. include-tagged::{sql-specs}/docs/geo.csv-spec[aswkt]
  32. --------------------------------------------------
  33. [[sql-functions-geo-st-wkt-to-sql]]
  34. ===== `ST_WKTToSQL`
  35. .Synopsis:
  36. [source, sql]
  37. --------------------------------------------------
  38. ST_WKTToSQL(
  39. string <1>
  40. )
  41. --------------------------------------------------
  42. *Input*:
  43. <1> string WKT representation of geometry. If `null`, the function returns
  44. `null`.
  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. If `null`, the function returns `null`.
  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. If `null`, the function returns `null`.
  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. If `null`, the function returns `null`.
  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. If `null`, the function returns `null`.
  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. If `null`, the function returns `null`.
  132. <2> target geometry. If `null`, the function returns `null`.
  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. --------------------------------------------------