1. =============================
    
  2. Geographic Database Functions
    
  3. =============================
    
  4. 
    
  5. .. module:: django.contrib.gis.db.models.functions
    
  6.     :synopsis: Geographic Database Functions
    
  7. 
    
  8. The functions documented on this page allow users to access geographic database
    
  9. functions to be used in annotations, aggregations, or filters in Django.
    
  10. 
    
  11. Example::
    
  12. 
    
  13.     >>> from django.contrib.gis.db.models.functions import Length
    
  14.     >>> Track.objects.annotate(length=Length('line')).filter(length__gt=100)
    
  15. 
    
  16. Not all backends support all functions, so refer to the documentation of each
    
  17. function to see if your database backend supports the function you want to use.
    
  18. If you call a geographic function on a backend that doesn't support it, you'll
    
  19. get a ``NotImplementedError`` exception.
    
  20. 
    
  21. Function's summary:
    
  22. 
    
  23. =========================  ========================  ======================  =======================  ==================  =====================
    
  24. Measurement                Relationships             Operations              Editors                  Output format       Miscellaneous
    
  25. =========================  ========================  ======================  =======================  ==================  =====================
    
  26. :class:`Area`              :class:`Azimuth`          :class:`Difference`     :class:`ForcePolygonCW`  :class:`AsGeoJSON`  :class:`IsValid`
    
  27. :class:`Distance`          :class:`BoundingCircle`   :class:`Intersection`   :class:`MakeValid`       :class:`AsGML`      :class:`MemSize`
    
  28. :class:`GeometryDistance`  :class:`Centroid`         :class:`SymDifference`  :class:`Reverse`         :class:`AsKML`      :class:`NumGeometries`
    
  29. :class:`Length`            :class:`Envelope`         :class:`Union`          :class:`Scale`           :class:`AsSVG`      :class:`NumPoints`
    
  30. :class:`Perimeter`         :class:`LineLocatePoint`                          :class:`SnapToGrid`      :class:`AsWKB`
    
  31. ..                         :class:`PointOnSurface`                           :class:`Transform`       :class:`AsWKT`
    
  32. ..                                                                           :class:`Translate`       :class:`GeoHash`
    
  33. =========================  ========================  ======================  =======================  ==================  =====================
    
  34. 
    
  35. ``Area``
    
  36. ========
    
  37. 
    
  38. .. class:: Area(expression, **extra)
    
  39. 
    
  40. *Availability*: MariaDB, `MySQL
    
  41. <https://dev.mysql.com/doc/refman/en/gis-polygon-property-functions.html#function_st-area>`_,
    
  42. Oracle, `PostGIS <https://postgis.net/docs/ST_Area.html>`__, SpatiaLite
    
  43. 
    
  44. Accepts a single geographic field or expression and returns the area of the
    
  45. field as an :class:`~django.contrib.gis.measure.Area` measure.
    
  46. 
    
  47. MySQL and SpatiaLite without LWGEOM/RTTOPO don't support area calculations on
    
  48. geographic SRSes.
    
  49. 
    
  50. ``AsGeoJSON``
    
  51. =============
    
  52. 
    
  53. .. class:: AsGeoJSON(expression, bbox=False, crs=False, precision=8, **extra)
    
  54. 
    
  55. *Availability*: MariaDB, `MySQL
    
  56. <https://dev.mysql.com/doc/refman/en/spatial-geojson-functions.html#function_st-asgeojson>`__ (≥ 5.7.5),
    
  57. Oracle, `PostGIS <https://postgis.net/docs/ST_AsGeoJSON.html>`__, SpatiaLite
    
  58. 
    
  59. Accepts a single geographic field or expression and returns a `GeoJSON
    
  60. <https://geojson.org/>`_ representation of the geometry. Note that the result
    
  61. is not a complete GeoJSON structure but only the ``geometry`` key content of a
    
  62. GeoJSON structure. See also :doc:`/ref/contrib/gis/serializers`.
    
  63. 
    
  64. Example::
    
  65. 
    
  66.     >>> City.objects.annotate(json=AsGeoJSON('point')).get(name='Chicago').json
    
  67.     {"type":"Point","coordinates":[-87.65018,41.85039]}
    
  68. 
    
  69. =====================  =====================================================
    
  70. Keyword Argument       Description
    
  71. =====================  =====================================================
    
  72. ``bbox``               Set this to ``True`` if you want the bounding box
    
  73.                        to be included in the returned GeoJSON. Ignored on
    
  74.                        Oracle.
    
  75. 
    
  76. ``crs``                Set this to ``True`` if you want the coordinate
    
  77.                        reference system to be included in the returned
    
  78.                        GeoJSON. Ignored on MySQL and Oracle.
    
  79. 
    
  80. ``precision``          It may be used to specify the number of significant
    
  81.                        digits for the coordinates in the GeoJSON
    
  82.                        representation -- the default value is 8. Ignored on
    
  83.                        Oracle.
    
  84. =====================  =====================================================
    
  85. 
    
  86. ``AsGML``
    
  87. =========
    
  88. 
    
  89. .. class:: AsGML(expression, version=2, precision=8, **extra)
    
  90. 
    
  91. *Availability*: Oracle, `PostGIS <https://postgis.net/docs/ST_AsGML.html>`__,
    
  92. SpatiaLite
    
  93. 
    
  94. Accepts a single geographic field or expression and returns a `Geographic Markup
    
  95. Language (GML)`__ representation of the geometry.
    
  96. 
    
  97. Example::
    
  98. 
    
  99.     >>> qs = Zipcode.objects.annotate(gml=AsGML('poly'))
    
  100.     >>> print(qs[0].gml)
    
  101.     <gml:Polygon srsName="EPSG:4326"><gml:OuterBoundaryIs>-147.78711,70.245363 ...
    
  102.     -147.78711,70.245363</gml:OuterBoundaryIs></gml:Polygon>
    
  103. 
    
  104. =====================  =====================================================
    
  105. Keyword Argument       Description
    
  106. =====================  =====================================================
    
  107. ``precision``          Specifies the number of significant digits for the
    
  108.                        coordinates in the GML representation -- the default
    
  109.                        value is 8. Ignored on Oracle.
    
  110. 
    
  111. ``version``            Specifies the GML version to use: 2 (default) or 3.
    
  112. =====================  =====================================================
    
  113. 
    
  114. __ https://en.wikipedia.org/wiki/Geography_Markup_Language
    
  115. 
    
  116. ``AsKML``
    
  117. =========
    
  118. 
    
  119. .. class:: AsKML(expression, precision=8, **extra)
    
  120. 
    
  121. *Availability*: `PostGIS <https://postgis.net/docs/ST_AsKML.html>`__, SpatiaLite
    
  122. 
    
  123. Accepts a single geographic field or expression and returns a `Keyhole Markup
    
  124. Language (KML)`__ representation of the geometry.
    
  125. 
    
  126. Example::
    
  127. 
    
  128.     >>> qs = Zipcode.objects.annotate(kml=AsKML('poly'))
    
  129.     >>> print(qs[0].kml)
    
  130.     <Polygon><outerBoundaryIs><LinearRing><coordinates>-103.04135,36.217596,0 ...
    
  131.     -103.04135,36.217596,0</coordinates></LinearRing></outerBoundaryIs></Polygon>
    
  132. 
    
  133. =====================  =====================================================
    
  134. Keyword Argument       Description
    
  135. =====================  =====================================================
    
  136. ``precision``          This keyword may be used to specify the number of
    
  137.                        significant digits for the coordinates in the KML
    
  138.                        representation -- the default value is 8.
    
  139. =====================  =====================================================
    
  140. 
    
  141. __ https://developers.google.com/kml/documentation/
    
  142. 
    
  143. ``AsSVG``
    
  144. =========
    
  145. 
    
  146. .. class:: AsSVG(expression, relative=False, precision=8, **extra)
    
  147. 
    
  148. *Availability*: `PostGIS <https://postgis.net/docs/ST_AsSVG.html>`__, SpatiaLite
    
  149. 
    
  150. Accepts a single geographic field or expression and returns a `Scalable Vector
    
  151. Graphics (SVG)`__ representation of the geometry.
    
  152. 
    
  153. =====================  =====================================================
    
  154. Keyword Argument       Description
    
  155. =====================  =====================================================
    
  156. ``relative``           If set to ``True``, the path data will be implemented
    
  157.                        in terms of relative moves. Defaults to ``False``,
    
  158.                        meaning that absolute moves are used instead.
    
  159. 
    
  160. ``precision``          This keyword may be used to specify the number of
    
  161.                        significant digits for the coordinates in the SVG
    
  162.                        representation -- the default value is 8.
    
  163. =====================  =====================================================
    
  164. 
    
  165. __ https://www.w3.org/Graphics/SVG/
    
  166. 
    
  167. ``AsWKB``
    
  168. =========
    
  169. 
    
  170. .. class:: AsWKB(expression, **extra)
    
  171. 
    
  172. *Availability*: MariaDB, `MySQL
    
  173. <https://dev.mysql.com/doc/refman/en/gis-format-conversion-functions.html#function_st-asbinary>`__,
    
  174. Oracle, `PostGIS <https://postgis.net/docs/ST_AsBinary.html>`__, SpatiaLite
    
  175. 
    
  176. Accepts a single geographic field or expression and returns a `Well-known
    
  177. binary (WKB)`__ representation of the geometry.
    
  178. 
    
  179. Example::
    
  180. 
    
  181.     >>> bytes(City.objects.annotate(wkb=AsWKB('point')).get(name='Chelyabinsk').wkb)
    
  182.     b'\x01\x01\x00\x00\x00]3\xf9f\x9b\x91K@\x00X\x1d9\xd2\xb9N@'
    
  183. 
    
  184. __ https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
    
  185. 
    
  186. ``AsWKT``
    
  187. =========
    
  188. 
    
  189. .. class:: AsWKT(expression, **extra)
    
  190. 
    
  191. *Availability*: MariaDB, `MySQL
    
  192. <https://dev.mysql.com/doc/refman/en/gis-format-conversion-functions.html#function_st-astext>`__,
    
  193. Oracle, `PostGIS <https://postgis.net/docs/ST_AsText.html>`__, SpatiaLite
    
  194. 
    
  195. Accepts a single geographic field or expression and returns a `Well-known text
    
  196. (WKT)`__ representation of the geometry.
    
  197. 
    
  198. Example::
    
  199. 
    
  200.     >>> City.objects.annotate(wkt=AsWKT('point')).get(name='Chelyabinsk').wkt
    
  201.     'POINT (55.137555 61.451728)'
    
  202. 
    
  203. __ https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry
    
  204. 
    
  205. ``Azimuth``
    
  206. ===========
    
  207. 
    
  208. .. class:: Azimuth(point_a, point_b, **extra)
    
  209. 
    
  210. *Availability*: `PostGIS <https://postgis.net/docs/ST_Azimuth.html>`__,
    
  211. SpatiaLite (LWGEOM/RTTOPO)
    
  212. 
    
  213. Returns the azimuth in radians of the segment defined by the given point
    
  214. geometries, or ``None`` if the two points are coincident. The azimuth is angle
    
  215. referenced from north and is positive clockwise: north = ``0``; east = ``π/2``;
    
  216. south = ``π``; west = ``3π/2``.
    
  217. 
    
  218. ``BoundingCircle``
    
  219. ==================
    
  220. 
    
  221. .. class:: BoundingCircle(expression, num_seg=48, **extra)
    
  222. 
    
  223. *Availability*: `PostGIS <https://postgis.net/docs/ST_MinimumBoundingCircle.html>`__,
    
  224. `Oracle <https://docs.oracle.com/en/database/oracle/oracle-database/21/spatl/
    
  225. SDO_GEOM-reference.html#GUID-82A61626-BB64-4793-B53D-A0DBEC91831A>`_
    
  226. 
    
  227. Accepts a single geographic field or expression and returns the smallest circle
    
  228. polygon that can fully contain the geometry.
    
  229. 
    
  230. The ``num_seg`` parameter is used only on PostGIS.
    
  231. 
    
  232. ``Centroid``
    
  233. ============
    
  234. 
    
  235. .. class:: Centroid(expression, **extra)
    
  236. 
    
  237. *Availability*: MariaDB, `MySQL
    
  238. <https://dev.mysql.com/doc/refman/en/gis-polygon-property-functions.html#function_st-centroid>`__,
    
  239. `PostGIS <https://postgis.net/docs/ST_Centroid.html>`__, Oracle, SpatiaLite
    
  240. 
    
  241. Accepts a single geographic field or expression and returns the ``centroid``
    
  242. value of the geometry.
    
  243. 
    
  244. ``Difference``
    
  245. ==============
    
  246. 
    
  247. .. class:: Difference(expr1, expr2, **extra)
    
  248. 
    
  249. *Availability*: MariaDB, `MySQL
    
  250. <https://dev.mysql.com/doc/refman/en/spatial-operator-functions.html#function_st-difference>`__,
    
  251. `PostGIS <https://postgis.net/docs/ST_Difference.html>`__, Oracle, SpatiaLite
    
  252. 
    
  253. Accepts two geographic fields or expressions and returns the geometric
    
  254. difference, that is the part of geometry A that does not intersect with
    
  255. geometry B.
    
  256. 
    
  257. ``Distance``
    
  258. ============
    
  259. 
    
  260. .. class:: Distance(expr1, expr2, spheroid=None, **extra)
    
  261. 
    
  262. *Availability*: MariaDB, `MySQL
    
  263. <https://dev.mysql.com/doc/refman/en/spatial-relation-functions-object-shapes.html#function_st-distance>`__,
    
  264. `PostGIS <https://postgis.net/docs/ST_Distance.html>`__, Oracle, SpatiaLite
    
  265. 
    
  266. Accepts two geographic fields or expressions and returns the distance between
    
  267. them, as a :class:`~django.contrib.gis.measure.Distance` object. On MySQL, a raw
    
  268. float value is returned when the coordinates are geodetic.
    
  269. 
    
  270. On backends that support distance calculation on geodetic coordinates, the
    
  271. proper backend function is automatically chosen depending on the SRID value of
    
  272. the geometries (e.g. `ST_DistanceSphere
    
  273. <https://postgis.net/docs/ST_DistanceSphere.html>`__ on PostGIS).
    
  274. 
    
  275. When distances are calculated with geodetic (angular) coordinates, as is the
    
  276. case with the default WGS84 (4326) SRID, you can set the ``spheroid`` keyword
    
  277. argument to decide if the calculation should be based on a simple sphere (less
    
  278. accurate, less resource-intensive) or on a spheroid (more accurate, more
    
  279. resource-intensive).
    
  280. 
    
  281. In the following example, the distance from the city of Hobart to every other
    
  282. :class:`~django.contrib.gis.db.models.PointField` in the ``AustraliaCity``
    
  283. queryset is calculated::
    
  284. 
    
  285.     >>> from django.contrib.gis.db.models.functions import Distance
    
  286.     >>> pnt = AustraliaCity.objects.get(name='Hobart').point
    
  287.     >>> for city in AustraliaCity.objects.annotate(distance=Distance('point', pnt)):
    
  288.     ...     print(city.name, city.distance)
    
  289.     Wollongong 990071.220408 m
    
  290.     Shellharbour 972804.613941 m
    
  291.     Thirroul 1002334.36351 m
    
  292.     ...
    
  293. 
    
  294. .. note::
    
  295. 
    
  296.     Because the ``distance`` attribute is a
    
  297.     :class:`~django.contrib.gis.measure.Distance` object, you can easily express
    
  298.     the value in the units of your choice. For example, ``city.distance.mi`` is
    
  299.     the distance value in miles and ``city.distance.km`` is the distance value
    
  300.     in kilometers. See :doc:`measure` for usage details and the list of
    
  301.     :ref:`supported_units`.
    
  302. 
    
  303. ``Envelope``
    
  304. ============
    
  305. 
    
  306. .. class:: Envelope(expression, **extra)
    
  307. 
    
  308. *Availability*: MariaDB, `MySQL
    
  309. <https://dev.mysql.com/doc/refman/en/gis-general-property-functions.html#function_st-envelope>`__,
    
  310. `Oracle <https://docs.oracle.com/en/database/oracle/oracle-database/21/spatl/
    
  311. spatial-operators-reference.html#GUID-ACED800F-3435-44AA-9606-D40934A23ED0>`__,
    
  312. `PostGIS <https://postgis.net/docs/ST_Envelope.html>`__, SpatiaLite
    
  313. 
    
  314. Accepts a single geographic field or expression and returns the geometry
    
  315. representing the bounding box of the geometry.
    
  316. 
    
  317. ``ForcePolygonCW``
    
  318. ==================
    
  319. 
    
  320. .. class:: ForcePolygonCW(expression, **extra)
    
  321. 
    
  322. *Availability*: `PostGIS <https://postgis.net/docs/ST_ForcePolygonCW.html>`__,
    
  323. SpatiaLite
    
  324. 
    
  325. Accepts a single geographic field or expression and returns a modified version
    
  326. of the polygon/multipolygon in which all exterior rings are oriented clockwise
    
  327. and all interior rings are oriented counterclockwise. Non-polygonal geometries
    
  328. are returned unchanged.
    
  329. 
    
  330. ``GeoHash``
    
  331. ===========
    
  332. 
    
  333. .. class:: GeoHash(expression, precision=None, **extra)
    
  334. 
    
  335. *Availability*: `MySQL
    
  336. <https://dev.mysql.com/doc/refman/en/spatial-geohash-functions.html#function_st-geohash>`__ (≥ 5.7.5),
    
  337. `PostGIS <https://postgis.net/docs/ST_GeoHash.html>`__, SpatiaLite
    
  338. (LWGEOM/RTTOPO)
    
  339. 
    
  340. Accepts a single geographic field or expression and returns a `GeoHash`__
    
  341. representation of the geometry.
    
  342. 
    
  343. The ``precision`` keyword argument controls the number of characters in the
    
  344. result.
    
  345. 
    
  346. __ https://en.wikipedia.org/wiki/Geohash
    
  347. 
    
  348. ``GeometryDistance``
    
  349. ====================
    
  350. 
    
  351. .. class:: GeometryDistance(expr1, expr2, **extra)
    
  352. 
    
  353. *Availability*: `PostGIS <https://postgis.net/docs/geometry_distance_knn.html>`__
    
  354. 
    
  355. Accepts two geographic fields or expressions and returns the distance between
    
  356. them. When used in an :meth:`~django.db.models.query.QuerySet.order_by` clause,
    
  357. it provides index-assisted nearest-neighbor result sets.
    
  358. 
    
  359. ``Intersection``
    
  360. ================
    
  361. 
    
  362. .. class:: Intersection(expr1, expr2, **extra)
    
  363. 
    
  364. *Availability*: MariaDB, `MySQL
    
  365. <https://dev.mysql.com/doc/refman/en/spatial-operator-functions.html#function_st-intersection>`__,
    
  366. `PostGIS <https://postgis.net/docs/ST_Intersection.html>`__, Oracle, SpatiaLite
    
  367. 
    
  368. Accepts two geographic fields or expressions and returns the geometric
    
  369. intersection between them.
    
  370. 
    
  371. ``IsValid``
    
  372. ===========
    
  373. 
    
  374. .. class:: IsValid(expr)
    
  375. 
    
  376. *Availability*: `MySQL
    
  377. <https://dev.mysql.com/doc/refman/en/spatial-convenience-functions.html#function_st-isvalid>`__ (≥ 5.7.5),
    
  378. `PostGIS <https://postgis.net/docs/ST_IsValid.html>`__, Oracle, SpatiaLite
    
  379. 
    
  380. Accepts a geographic field or expression and tests if the value is well formed.
    
  381. Returns ``True`` if its value is a valid geometry and ``False`` otherwise.
    
  382. 
    
  383. ``Length``
    
  384. ==========
    
  385. 
    
  386. .. class:: Length(expression, spheroid=True, **extra)
    
  387. 
    
  388. *Availability*: MariaDB, `MySQL
    
  389. <https://dev.mysql.com/doc/refman/en/gis-linestring-property-functions.html#function_st-length>`__,
    
  390. Oracle, `PostGIS <https://postgis.net/docs/ST_Length.html>`__, SpatiaLite
    
  391. 
    
  392. Accepts a single geographic linestring or multilinestring field or expression
    
  393. and returns its length as a :class:`~django.contrib.gis.measure.Distance`
    
  394. measure.
    
  395. 
    
  396. On PostGIS and SpatiaLite, when the coordinates are geodetic (angular), you can
    
  397. specify if the calculation should be based on a simple sphere (less
    
  398. accurate, less resource-intensive) or on a spheroid (more accurate, more
    
  399. resource-intensive) with the ``spheroid`` keyword argument.
    
  400. 
    
  401. MySQL doesn't support length calculations on geographic SRSes.
    
  402. 
    
  403. ``LineLocatePoint``
    
  404. ===================
    
  405. 
    
  406. .. class:: LineLocatePoint(linestring, point, **extra)
    
  407. 
    
  408. *Availability*: `PostGIS <https://postgis.net/docs/ST_LineLocatePoint.html>`__,
    
  409. SpatiaLite
    
  410. 
    
  411. Returns a float between 0 and 1 representing the location of the closest point on
    
  412. ``linestring`` to the given ``point``, as a fraction of the 2D line length.
    
  413. 
    
  414. ``MakeValid``
    
  415. =============
    
  416. 
    
  417. .. class:: MakeValid(expr)
    
  418. 
    
  419. *Availability*: `PostGIS <https://postgis.net/docs/ST_MakeValid.html>`__,
    
  420. SpatiaLite (LWGEOM/RTTOPO)
    
  421. 
    
  422. Accepts a geographic field or expression and attempts to convert the value into
    
  423. a valid geometry without losing any of the input vertices. Geometries that are
    
  424. already valid are returned without changes. Simple polygons might become a
    
  425. multipolygon and the result might be of lower dimension than the input.
    
  426. 
    
  427. ``MemSize``
    
  428. ===========
    
  429. 
    
  430. .. class:: MemSize(expression, **extra)
    
  431. 
    
  432. *Availability*: `PostGIS <https://postgis.net/docs/ST_MemSize.html>`__
    
  433. 
    
  434. Accepts a single geographic field or expression and returns the memory size
    
  435. (number of bytes) that the geometry field takes.
    
  436. 
    
  437. ``NumGeometries``
    
  438. =================
    
  439. 
    
  440. .. class:: NumGeometries(expression, **extra)
    
  441. 
    
  442. *Availability*: MariaDB, `MySQL
    
  443. <https://dev.mysql.com/doc/refman/en/gis-geometrycollection-property-functions.html#function_st-numgeometries>`__,
    
  444. `PostGIS <https://postgis.net/docs/ST_NumGeometries.html>`__, Oracle,
    
  445. SpatiaLite
    
  446. 
    
  447. Accepts a single geographic field or expression and returns the number of
    
  448. geometries if the geometry field is a collection (e.g., a ``GEOMETRYCOLLECTION``
    
  449. or ``MULTI*`` field). Returns 1 for single geometries.
    
  450. 
    
  451. On MySQL, returns ``None`` for single geometries.
    
  452. 
    
  453. ``NumPoints``
    
  454. =============
    
  455. 
    
  456. .. class:: NumPoints(expression, **extra)
    
  457. 
    
  458. *Availability*: MariaDB, `MySQL
    
  459. <https://dev.mysql.com/doc/refman/en/gis-linestring-property-functions.html#function_st-numpoints>`__,
    
  460. `PostGIS <https://postgis.net/docs/ST_NPoints.html>`__, Oracle, SpatiaLite
    
  461. 
    
  462. Accepts a single geographic field or expression and returns the number of points
    
  463. in a geometry.
    
  464. 
    
  465. On MySQL, returns ``None`` for any non-``LINESTRING`` geometry.
    
  466. 
    
  467. ``Perimeter``
    
  468. =============
    
  469. 
    
  470. .. class:: Perimeter(expression, **extra)
    
  471. 
    
  472. *Availability*: `PostGIS <https://postgis.net/docs/ST_Perimeter.html>`__,
    
  473. Oracle, SpatiaLite
    
  474. 
    
  475. Accepts a single geographic field or expression and returns the perimeter of the
    
  476. geometry field as a :class:`~django.contrib.gis.measure.Distance` object.
    
  477. 
    
  478. ``PointOnSurface``
    
  479. ==================
    
  480. 
    
  481. .. class:: PointOnSurface(expression, **extra)
    
  482. 
    
  483. *Availability*: `PostGIS <https://postgis.net/docs/ST_PointOnSurface.html>`__,
    
  484. MariaDB, Oracle, SpatiaLite
    
  485. 
    
  486. Accepts a single geographic field or expression and returns a ``Point`` geometry
    
  487. guaranteed to lie on the surface of the field; otherwise returns ``None``.
    
  488. 
    
  489. ``Reverse``
    
  490. ===========
    
  491. 
    
  492. .. class:: Reverse(expression, **extra)
    
  493. 
    
  494. *Availability*: `PostGIS <https://postgis.net/docs/ST_Reverse.html>`__, Oracle,
    
  495. SpatiaLite
    
  496. 
    
  497. Accepts a single geographic field or expression and returns a geometry with
    
  498. reversed coordinates.
    
  499. 
    
  500. ``Scale``
    
  501. =========
    
  502. 
    
  503. .. class:: Scale(expression, x, y, z=0.0, **extra)
    
  504. 
    
  505. *Availability*: `PostGIS <https://postgis.net/docs/ST_Scale.html>`__, SpatiaLite
    
  506. 
    
  507. Accepts a single geographic field or expression and returns a geometry with
    
  508. scaled coordinates by multiplying them with the ``x``, ``y``, and optionally
    
  509. ``z`` parameters.
    
  510. 
    
  511. ``SnapToGrid``
    
  512. ==============
    
  513. 
    
  514. .. class:: SnapToGrid(expression, *args, **extra)
    
  515. 
    
  516. *Availability*: `PostGIS <https://postgis.net/docs/ST_SnapToGrid.html>`__,
    
  517. SpatiaLite
    
  518. 
    
  519. Accepts a single geographic field or expression and returns a geometry with all
    
  520. points snapped to the given grid.  How the geometry is snapped to the grid
    
  521. depends on how many numeric (either float, integer, or long) arguments are
    
  522. given.
    
  523. 
    
  524. ===================  =====================================================
    
  525. Number of Arguments  Description
    
  526. ===================  =====================================================
    
  527. 1                    A single size to snap both the X and Y grids to.
    
  528. 2                    X and Y sizes to snap the grid to.
    
  529. 4                    X, Y sizes and the corresponding X, Y origins.
    
  530. ===================  =====================================================
    
  531. 
    
  532. ``SymDifference``
    
  533. =================
    
  534. 
    
  535. .. class:: SymDifference(expr1, expr2, **extra)
    
  536. 
    
  537. *Availability*: MariaDB, `MySQL
    
  538. <https://dev.mysql.com/doc/refman/en/spatial-operator-functions.html#function_st-symdifference>`__,
    
  539. `PostGIS <https://postgis.net/docs/ST_SymDifference.html>`__, Oracle,
    
  540. SpatiaLite
    
  541. 
    
  542. Accepts two geographic fields or expressions and returns the geometric
    
  543. symmetric difference (union without the intersection) between the given
    
  544. parameters.
    
  545. 
    
  546. ``Transform``
    
  547. =============
    
  548. 
    
  549. .. class:: Transform(expression, srid, **extra)
    
  550. 
    
  551. *Availability*: `PostGIS <https://postgis.net/docs/ST_Transform.html>`__,
    
  552. Oracle, SpatiaLite
    
  553. 
    
  554. Accepts a geographic field or expression and a SRID integer code, and returns
    
  555. the transformed geometry to the spatial reference system specified by the
    
  556. ``srid`` parameter.
    
  557. 
    
  558. .. note::
    
  559. 
    
  560.     What spatial reference system an integer SRID corresponds to may depend on
    
  561.     the spatial database used.  In other words, the SRID numbers used for Oracle
    
  562.     are not necessarily the same as those used by PostGIS.
    
  563. 
    
  564. ``Translate``
    
  565. =============
    
  566. 
    
  567. .. class:: Translate(expression, x, y, z=0.0, **extra)
    
  568. 
    
  569. *Availability*: `PostGIS <https://postgis.net/docs/ST_Translate.html>`__,
    
  570. SpatiaLite
    
  571. 
    
  572. Accepts a single geographic field or expression and returns a geometry with
    
  573. its coordinates offset by the ``x``, ``y``, and optionally ``z`` numeric
    
  574. parameters.
    
  575. 
    
  576. ``Union``
    
  577. =========
    
  578. 
    
  579. .. class:: Union(expr1, expr2, **extra)
    
  580. 
    
  581. *Availability*: MariaDB, `MySQL
    
  582. <https://dev.mysql.com/doc/refman/en/spatial-operator-functions.html#function_st-union>`__,
    
  583. `PostGIS <https://postgis.net/docs/ST_Union.html>`__, Oracle, SpatiaLite
    
  584. 
    
  585. Accepts two geographic fields or expressions and returns the union of both
    
  586. geometries.