geoquerysets.txt 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  1. =========================
  2. GeoQuerySet API Reference
  3. =========================
  4. .. currentmodule:: django.contrib.gis.db.models
  5. .. class:: GeoQuerySet(model=None)
  6. .. _spatial-lookups:
  7. Spatial Lookups
  8. ===============
  9. The spatial lookups in this section are available for :class:`GeometryField`
  10. and :class:`RasterField`.
  11. For an introduction, see the :ref:`spatial lookups introduction
  12. <spatial-lookups-intro>`. For an overview of what lookups are
  13. compatible with a particular spatial backend, refer to the
  14. :ref:`spatial lookup compatibility table <spatial-lookup-compatibility>`.
  15. .. versionchanged:: 1.10
  16. Spatial lookups now support raster input.
  17. Lookups with rasters
  18. --------------------
  19. All examples in the reference below are given for geometry fields and inputs,
  20. but the lookups can be used the same way with rasters on both sides. Whenever
  21. a lookup doesn't support raster input, the input is automatically
  22. converted to a geometry where necessary using the `ST_Polygon
  23. <http://postgis.net/docs/RT_ST_Polygon.html>`_ function. See also the
  24. :ref:`introduction to raster lookups <spatial-lookup-raster>`.
  25. The database operators used by the lookups can be divided into three categories:
  26. - Native raster support ``N``: the operator accepts rasters natively on both
  27. sides of the lookup, and raster input can be mixed with geometry inputs.
  28. - Bilateral raster support ``B``: the operator supports rasters only if both
  29. sides of the lookup receive raster inputs. Raster data is automatically
  30. converted to geometries for mixed lookups.
  31. - Geometry conversion support ``C``. The lookup does not have native raster
  32. support, all raster data is automatically converted to geometries.
  33. The examples below show the SQL equivalent for the lookups in the different
  34. types of raster support. The same pattern applies to all spatial lookups.
  35. ==== ============================== =======================================================
  36. Case Lookup SQL Equivalent
  37. ==== ============================== =======================================================
  38. N, B ``rast__contains=rst`` ``ST_Contains(rast, rst)``
  39. N, B ``rast__1__contains=(rst, 2)`` ``ST_Contains(rast, 1, rst, 2)``
  40. B, C ``rast__contains=geom`` ``ST_Contains(ST_Polygon(rast), geom)``
  41. B, C ``rast__1__contains=geom`` ``ST_Contains(ST_Polygon(rast, 1), geom)``
  42. B, C ``poly__contains=rst`` ``ST_Contains(poly, ST_Polygon(rst))``
  43. B, C ``poly__contains=(rst, 1)`` ``ST_Contains(poly, ST_Polygon(rst, 1))``
  44. C ``rast__crosses=rst`` ``ST_Crosses(ST_Polygon(rast), ST_Polygon(rst))``
  45. C ``rast__1__crosses=(rst, 2)`` ``ST_Crosses(ST_Polygon(rast, 1), ST_Polygon(rst, 2))``
  46. C ``rast__crosses=geom`` ``ST_Crosses(ST_Polygon(rast), geom)``
  47. C ``poly__crosses=rst`` ``ST_Crosses(poly, ST_Polygon(rst))``
  48. ==== ============================== =======================================================
  49. Spatial lookups with rasters are only supported for PostGIS backends
  50. (denominated as PGRaster in this section).
  51. .. fieldlookup:: bbcontains
  52. ``bbcontains``
  53. --------------
  54. *Availability*: PostGIS, MySQL, SpatiaLite, PGRaster (Native)
  55. Tests if the geometry or raster field's bounding box completely contains the
  56. lookup geometry's bounding box.
  57. Example::
  58. Zipcode.objects.filter(poly__bbcontains=geom)
  59. ========== ==========================
  60. Backend SQL Equivalent
  61. ========== ==========================
  62. PostGIS ``poly ~ geom``
  63. MySQL ``MBRContains(poly, geom)``
  64. SpatiaLite ``MbrContains(poly, geom)``
  65. ========== ==========================
  66. .. fieldlookup:: bboverlaps
  67. ``bboverlaps``
  68. --------------
  69. *Availability*: PostGIS, MySQL, SpatiaLite, PGRaster (Native)
  70. Tests if the geometry field's bounding box overlaps the lookup geometry's
  71. bounding box.
  72. Example::
  73. Zipcode.objects.filter(poly__bboverlaps=geom)
  74. ========== ==========================
  75. Backend SQL Equivalent
  76. ========== ==========================
  77. PostGIS ``poly && geom``
  78. MySQL ``MBROverlaps(poly, geom)``
  79. SpatiaLite ``MbrOverlaps(poly, geom)``
  80. ========== ==========================
  81. .. fieldlookup:: contained
  82. ``contained``
  83. -------------
  84. *Availability*: PostGIS, MySQL, SpatiaLite, PGRaster (Native)
  85. Tests if the geometry field's bounding box is completely contained by the
  86. lookup geometry's bounding box.
  87. Example::
  88. Zipcode.objects.filter(poly__contained=geom)
  89. ========== ==========================
  90. Backend SQL Equivalent
  91. ========== ==========================
  92. PostGIS ``poly @ geom``
  93. MySQL ``MBRWithin(poly, geom)``
  94. SpatiaLite ``MbrWithin(poly, geom)``
  95. ========== ==========================
  96. .. fieldlookup:: gis-contains
  97. ``contains``
  98. ------------
  99. *Availability*: PostGIS, Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
  100. Tests if the geometry field spatially contains the lookup geometry.
  101. Example::
  102. Zipcode.objects.filter(poly__contains=geom)
  103. ========== ============================
  104. Backend SQL Equivalent
  105. ========== ============================
  106. PostGIS ``ST_Contains(poly, geom)``
  107. Oracle ``SDO_CONTAINS(poly, geom)``
  108. MySQL ``MBRContains(poly, geom)``
  109. SpatiaLite ``Contains(poly, geom)``
  110. ========== ============================
  111. .. fieldlookup:: contains_properly
  112. ``contains_properly``
  113. ---------------------
  114. *Availability*: PostGIS, PGRaster (Bilateral)
  115. Returns true if the lookup geometry intersects the interior of the
  116. geometry field, but not the boundary (or exterior). [#fncontainsproperly]_
  117. Example::
  118. Zipcode.objects.filter(poly__contains_properly=geom)
  119. ========== ===================================
  120. Backend SQL Equivalent
  121. ========== ===================================
  122. PostGIS ``ST_ContainsProperly(poly, geom)``
  123. ========== ===================================
  124. .. fieldlookup:: coveredby
  125. ``coveredby``
  126. -------------
  127. *Availability*: PostGIS, Oracle, PGRaster (Bilateral)
  128. Tests if no point in the geometry field is outside the lookup geometry.
  129. [#fncovers]_
  130. Example::
  131. Zipcode.objects.filter(poly__coveredby=geom)
  132. ========== =============================
  133. Backend SQL Equivalent
  134. ========== =============================
  135. PostGIS ``ST_CoveredBy(poly, geom)``
  136. Oracle ``SDO_COVEREDBY(poly, geom)``
  137. ========== =============================
  138. .. fieldlookup:: covers
  139. ``covers``
  140. ----------
  141. *Availability*: PostGIS, Oracle, PGRaster (Bilateral)
  142. Tests if no point in the lookup geometry is outside the geometry field.
  143. [#fncovers]_
  144. Example::
  145. Zipcode.objects.filter(poly__covers=geom)
  146. ========== ==========================
  147. Backend SQL Equivalent
  148. ========== ==========================
  149. PostGIS ``ST_Covers(poly, geom)``
  150. Oracle ``SDO_COVERS(poly, geom)``
  151. ========== ==========================
  152. .. fieldlookup:: crosses
  153. ``crosses``
  154. -----------
  155. *Availability*: PostGIS, SpatiaLite, PGRaster (Conversion)
  156. Tests if the geometry field spatially crosses the lookup geometry.
  157. Example::
  158. Zipcode.objects.filter(poly__crosses=geom)
  159. ========== ==========================
  160. Backend SQL Equivalent
  161. ========== ==========================
  162. PostGIS ``ST_Crosses(poly, geom)``
  163. SpatiaLite ``Crosses(poly, geom)``
  164. ========== ==========================
  165. .. fieldlookup:: disjoint
  166. ``disjoint``
  167. ------------
  168. *Availability*: PostGIS, Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
  169. Tests if the geometry field is spatially disjoint from the lookup geometry.
  170. Example::
  171. Zipcode.objects.filter(poly__disjoint=geom)
  172. ========== =================================================
  173. Backend SQL Equivalent
  174. ========== =================================================
  175. PostGIS ``ST_Disjoint(poly, geom)``
  176. Oracle ``SDO_GEOM.RELATE(poly, 'DISJOINT', geom, 0.05)``
  177. MySQL ``MBRDisjoint(poly, geom)``
  178. SpatiaLite ``Disjoint(poly, geom)``
  179. ========== =================================================
  180. .. fieldlookup:: equals
  181. ``equals``
  182. ----------
  183. *Availability*: PostGIS, Oracle, MySQL, SpatiaLite, PGRaster (Conversion)
  184. .. fieldlookup:: exact
  185. .. fieldlookup:: same_as
  186. ``exact``, ``same_as``
  187. ----------------------
  188. *Availability*: PostGIS, Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
  189. .. fieldlookup:: intersects
  190. ``intersects``
  191. --------------
  192. *Availability*: PostGIS, Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
  193. Tests if the geometry field spatially intersects the lookup geometry.
  194. Example::
  195. Zipcode.objects.filter(poly__intersects=geom)
  196. ========== =================================================
  197. Backend SQL Equivalent
  198. ========== =================================================
  199. PostGIS ``ST_Intersects(poly, geom)``
  200. Oracle ``SDO_OVERLAPBDYINTERSECT(poly, geom)``
  201. MySQL ``MBRIntersects(poly, geom)``
  202. SpatiaLite ``Intersects(poly, geom)``
  203. ========== =================================================
  204. .. fieldlookup:: isvalid
  205. ``isvalid``
  206. -----------
  207. .. versionadded:: 1.10
  208. *Availability*: PostGIS
  209. Tests if the geometry is valid.
  210. Example::
  211. Zipcode.objects.filter(poly__isvalid=True)
  212. PostGIS equivalent::
  213. SELECT ... WHERE ST_IsValid(poly)
  214. .. fieldlookup:: overlaps
  215. ``overlaps``
  216. ------------
  217. *Availability*: PostGIS, Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
  218. .. fieldlookup:: relate
  219. ``relate``
  220. ----------
  221. *Availability*: PostGIS, Oracle, SpatiaLite, PGRaster (Conversion)
  222. Tests if the geometry field is spatially related to the lookup geometry by
  223. the values given in the given pattern. This lookup requires a tuple parameter,
  224. ``(geom, pattern)``; the form of ``pattern`` will depend on the spatial backend:
  225. PostGIS & SpatiaLite
  226. ~~~~~~~~~~~~~~~~~~~~
  227. On these spatial backends the intersection pattern is a string comprising
  228. nine characters, which define intersections between the interior, boundary,
  229. and exterior of the geometry field and the lookup geometry.
  230. The intersection pattern matrix may only use the following characters:
  231. ``1``, ``2``, ``T``, ``F``, or ``*``. This lookup type allows users to "fine tune"
  232. a specific geometric relationship consistent with the DE-9IM model. [#fnde9im]_
  233. Geometry example::
  234. # A tuple lookup parameter is used to specify the geometry and
  235. # the intersection pattern (the pattern here is for 'contains').
  236. Zipcode.objects.filter(poly__relate=(geom, 'T*T***FF*'))
  237. PostGIS SQL equivalent::
  238. SELECT ... WHERE ST_Relate(poly, geom, 'T*T***FF*')
  239. SpatiaLite SQL equivalent::
  240. SELECT ... WHERE Relate(poly, geom, 'T*T***FF*')
  241. Raster example::
  242. Zipcode.objects.filter(poly__relate=(rast, 1, 'T*T***FF*'))
  243. Zipcode.objects.filter(rast__2__relate=(rast, 1, 'T*T***FF*'))
  244. PostGIS SQL equivalent::
  245. SELECT ... WHERE ST_Relate(poly, ST_Polygon(rast, 1), 'T*T***FF*')
  246. SELECT ... WHERE ST_Relate(ST_Polygon(rast, 2), ST_Polygon(rast, 1), 'T*T***FF*')
  247. Oracle
  248. ~~~~~~
  249. Here the relation pattern is comprised of at least one of the nine relation
  250. strings: ``TOUCH``, ``OVERLAPBDYDISJOINT``, ``OVERLAPBDYINTERSECT``,
  251. ``EQUAL``, ``INSIDE``, ``COVEREDBY``, ``CONTAINS``, ``COVERS``, ``ON``, and
  252. ``ANYINTERACT``. Multiple strings may be combined with the logical Boolean
  253. operator OR, for example, ``'inside+touch'``. [#fnsdorelate]_ The relation
  254. strings are case-insensitive.
  255. Example::
  256. Zipcode.objects.filter(poly__relate=(geom, 'anyinteract'))
  257. Oracle SQL equivalent::
  258. SELECT ... WHERE SDO_RELATE(poly, geom, 'anyinteract')
  259. .. fieldlookup:: touches
  260. ``touches``
  261. -----------
  262. *Availability*: PostGIS, Oracle, MySQL, SpatiaLite
  263. Tests if the geometry field spatially touches the lookup geometry.
  264. Example::
  265. Zipcode.objects.filter(poly__touches=geom)
  266. ========== ==========================
  267. Backend SQL Equivalent
  268. ========== ==========================
  269. PostGIS ``ST_Touches(poly, geom)``
  270. MySQL ``MBRTouches(poly, geom)``
  271. Oracle ``SDO_TOUCH(poly, geom)``
  272. SpatiaLite ``Touches(poly, geom)``
  273. ========== ==========================
  274. .. fieldlookup:: within
  275. ``within``
  276. ----------
  277. *Availability*: PostGIS, Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
  278. Tests if the geometry field is spatially within the lookup geometry.
  279. Example::
  280. Zipcode.objects.filter(poly__within=geom)
  281. ========== ==========================
  282. Backend SQL Equivalent
  283. ========== ==========================
  284. PostGIS ``ST_Within(poly, geom)``
  285. MySQL ``MBRWithin(poly, geom)``
  286. Oracle ``SDO_INSIDE(poly, geom)``
  287. SpatiaLite ``Within(poly, geom)``
  288. ========== ==========================
  289. .. fieldlookup:: left
  290. ``left``
  291. --------
  292. *Availability*: PostGIS, PGRaster (Conversion)
  293. Tests if the geometry field's bounding box is strictly to the left of the
  294. lookup geometry's bounding box.
  295. Example::
  296. Zipcode.objects.filter(poly__left=geom)
  297. PostGIS equivalent::
  298. SELECT ... WHERE poly << geom
  299. .. fieldlookup:: right
  300. ``right``
  301. ---------
  302. *Availability*: PostGIS, PGRaster (Conversion)
  303. Tests if the geometry field's bounding box is strictly to the right of the
  304. lookup geometry's bounding box.
  305. Example::
  306. Zipcode.objects.filter(poly__right=geom)
  307. PostGIS equivalent::
  308. SELECT ... WHERE poly >> geom
  309. .. fieldlookup:: overlaps_left
  310. ``overlaps_left``
  311. -----------------
  312. *Availability*: PostGIS, PGRaster (Bilateral)
  313. Tests if the geometry field's bounding box overlaps or is to the left of the lookup
  314. geometry's bounding box.
  315. Example::
  316. Zipcode.objects.filter(poly__overlaps_left=geom)
  317. PostGIS equivalent::
  318. SELECT ... WHERE poly &< geom
  319. .. fieldlookup:: overlaps_right
  320. ``overlaps_right``
  321. ------------------
  322. *Availability*: PostGIS, PGRaster (Bilateral)
  323. Tests if the geometry field's bounding box overlaps or is to the right of the lookup
  324. geometry's bounding box.
  325. Example::
  326. Zipcode.objects.filter(poly__overlaps_right=geom)
  327. PostGIS equivalent::
  328. SELECT ... WHERE poly &> geom
  329. .. fieldlookup:: overlaps_above
  330. ``overlaps_above``
  331. ------------------
  332. *Availability*: PostGIS, PGRaster (Conversion)
  333. Tests if the geometry field's bounding box overlaps or is above the lookup
  334. geometry's bounding box.
  335. Example::
  336. Zipcode.objects.filter(poly__overlaps_above=geom)
  337. PostGIS equivalent::
  338. SELECT ... WHERE poly |&> geom
  339. .. fieldlookup:: overlaps_below
  340. ``overlaps_below``
  341. ------------------
  342. *Availability*: PostGIS, PGRaster (Conversion)
  343. Tests if the geometry field's bounding box overlaps or is below the lookup
  344. geometry's bounding box.
  345. Example::
  346. Zipcode.objects.filter(poly__overlaps_below=geom)
  347. PostGIS equivalent::
  348. SELECT ... WHERE poly &<| geom
  349. .. fieldlookup:: strictly_above
  350. ``strictly_above``
  351. ------------------
  352. *Availability*: PostGIS, PGRaster (Conversion)
  353. Tests if the geometry field's bounding box is strictly above the lookup
  354. geometry's bounding box.
  355. Example::
  356. Zipcode.objects.filter(poly__strictly_above=geom)
  357. PostGIS equivalent::
  358. SELECT ... WHERE poly |>> geom
  359. .. fieldlookup:: strictly_below
  360. ``strictly_below``
  361. ------------------
  362. *Availability*: PostGIS, PGRaster (Conversion)
  363. Tests if the geometry field's bounding box is strictly below the lookup
  364. geometry's bounding box.
  365. Example::
  366. Zipcode.objects.filter(poly__strictly_below=geom)
  367. PostGIS equivalent::
  368. SELECT ... WHERE poly <<| geom
  369. .. _distance-lookups:
  370. Distance Lookups
  371. ================
  372. *Availability*: PostGIS, Oracle, SpatiaLite, PGRaster (Native)
  373. For an overview on performing distance queries, please refer to
  374. the :ref:`distance queries introduction <distance-queries>`.
  375. Distance lookups take the following form::
  376. <field>__<distance lookup>=(<geometry/raster>, <distance value>[, 'spheroid'])
  377. <field>__<distance lookup>=(<raster>, <band_index>, <distance value>[, 'spheroid'])
  378. <field>__<band_index>__<distance lookup>=(<raster>, <band_index>, <distance value>[, 'spheroid'])
  379. The value passed into a distance lookup is a tuple; the first two
  380. values are mandatory, and are the geometry to calculate distances to,
  381. and a distance value (either a number in units of the field, a
  382. :class:`~django.contrib.gis.measure.Distance` object, or a `query expression
  383. <ref/models/expressions>`). To pass a band index to the lookup, use a 3-tuple
  384. where the second entry is the band index.
  385. With PostGIS, on every distance lookup but :lookup:`dwithin`, an optional
  386. element, ``'spheroid'``, may be included to tell GeoDjango to use the more
  387. accurate spheroid distance calculation functions on fields with a geodetic
  388. coordinate system (e.g., ``ST_Distance_Spheroid`` would be used instead of
  389. ``ST_Distance_Sphere``). The simpler ``ST_Distance`` function is used with
  390. projected coordinate systems. Rasters are converted to geometries for spheroid
  391. based lookups.
  392. .. versionadded:: 1.10
  393. The ability to pass an expression as the distance value was added.
  394. .. fieldlookup:: distance_gt
  395. ``distance_gt``
  396. ---------------
  397. Returns models where the distance to the geometry field from the lookup
  398. geometry is greater than the given distance value.
  399. Example::
  400. Zipcode.objects.filter(poly__distance_gt=(geom, D(m=5)))
  401. ========== ==================================================
  402. Backend SQL Equivalent
  403. ========== ==================================================
  404. PostGIS ``ST_Distance/ST_Distance_Sphere(poly, geom) > 5``
  405. Oracle ``SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) > 5``
  406. SpatiaLite ``Distance(poly, geom) > 5``
  407. ========== ==================================================
  408. .. fieldlookup:: distance_gte
  409. ``distance_gte``
  410. ----------------
  411. Returns models where the distance to the geometry field from the lookup
  412. geometry is greater than or equal to the given distance value.
  413. Example::
  414. Zipcode.objects.filter(poly__distance_gte=(geom, D(m=5)))
  415. ========== ===================================================
  416. Backend SQL Equivalent
  417. ========== ===================================================
  418. PostGIS ``ST_Distance/ST_Distance_Sphere(poly, geom) >= 5``
  419. Oracle ``SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) >= 5``
  420. SpatiaLite ``Distance(poly, geom) >= 5``
  421. ========== ===================================================
  422. .. fieldlookup:: distance_lt
  423. ``distance_lt``
  424. ---------------
  425. Returns models where the distance to the geometry field from the lookup
  426. geometry is less than the given distance value.
  427. Example::
  428. Zipcode.objects.filter(poly__distance_lt=(geom, D(m=5)))
  429. ========== ==================================================
  430. Backend SQL Equivalent
  431. ========== ==================================================
  432. PostGIS ``ST_Distance/ST_Distance_Sphere(poly, geom) < 5``
  433. Oracle ``SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) < 5``
  434. SpatiaLite ``Distance(poly, geom) < 5``
  435. ========== ==================================================
  436. .. fieldlookup:: distance_lte
  437. ``distance_lte``
  438. ----------------
  439. Returns models where the distance to the geometry field from the lookup
  440. geometry is less than or equal to the given distance value.
  441. Example::
  442. Zipcode.objects.filter(poly__distance_lte=(geom, D(m=5)))
  443. ========== ===================================================
  444. Backend SQL Equivalent
  445. ========== ===================================================
  446. PostGIS ``ST_Distance/ST_Distance_Sphere(poly, geom) <= 5``
  447. Oracle ``SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) <= 5``
  448. SpatiaLite ``Distance(poly, geom) <= 5``
  449. ========== ===================================================
  450. .. fieldlookup:: dwithin
  451. ``dwithin``
  452. -----------
  453. Returns models where the distance to the geometry field from the lookup
  454. geometry are within the given distance from one another. Note that you can only
  455. provide :class:`~django.contrib.gis.measure.Distance` objects if the targeted
  456. geometries are in a projected system. For geographic geometries, you should use
  457. units of the geometry field (e.g. degrees for ``WGS84``) .
  458. Example::
  459. Zipcode.objects.filter(poly__dwithin=(geom, D(m=5)))
  460. ========== ======================================
  461. Backend SQL Equivalent
  462. ========== ======================================
  463. PostGIS ``ST_DWithin(poly, geom, 5)``
  464. Oracle ``SDO_WITHIN_DISTANCE(poly, geom, 5)``
  465. SpatiaLite ``PtDistWithin(poly, geom, 5)``
  466. ========== ======================================
  467. .. versionchanged:: 1.11
  468. SpatiaLite support was added.
  469. .. _geoqueryset-methods:
  470. ``GeoQuerySet`` Methods
  471. =======================
  472. .. deprecated:: 1.9
  473. Using ``GeoQuerySet`` methods is now deprecated in favor of the new
  474. :doc:`functions`. Albeit a little more verbose, they are much more powerful
  475. in how it is possible to combine them to build more complex queries.
  476. ``GeoQuerySet`` methods specify that a spatial operation be performed
  477. on each spatial operation on each geographic
  478. field in the queryset and store its output in a new attribute on the model
  479. (which is generally the name of the ``GeoQuerySet`` method).
  480. There are also aggregate ``GeoQuerySet`` methods which return a single value
  481. instead of a queryset. This section will describe the API and availability
  482. of every ``GeoQuerySet`` method available in GeoDjango.
  483. .. note::
  484. What methods are available depend on your spatial backend. See
  485. the :ref:`compatibility table <database-functions-compatibility>`
  486. for more details.
  487. With a few exceptions, the following keyword arguments may be used with all
  488. ``GeoQuerySet`` methods:
  489. ===================== =====================================================
  490. Keyword Argument Description
  491. ===================== =====================================================
  492. ``field_name`` By default, ``GeoQuerySet`` methods use the first
  493. geographic field encountered in the model. This
  494. keyword should be used to specify another
  495. geographic field (e.g., ``field_name='point2'``)
  496. when there are multiple geographic fields in a model.
  497. On PostGIS, the ``field_name`` keyword may also be
  498. used on geometry fields in models that are related
  499. via a ``ForeignKey`` relation (e.g.,
  500. ``field_name='related__point'``).
  501. ``model_att`` By default, ``GeoQuerySet`` methods typically attach
  502. their output in an attribute with the same name as
  503. the ``GeoQuerySet`` method. Setting this keyword
  504. with the desired attribute name will override this
  505. default behavior. For example,
  506. ``qs = Zipcode.objects.centroid(model_att='c')`` will
  507. attach the centroid of the ``Zipcode`` geometry field
  508. in a ``c`` attribute on every model rather than in a
  509. ``centroid`` attribute.
  510. This keyword is required if
  511. a method name clashes with an existing
  512. ``GeoQuerySet`` method -- if you wanted to use the
  513. ``area()`` method on model with a ``PolygonField``
  514. named ``area``, for example.
  515. ===================== =====================================================
  516. Measurement
  517. -----------
  518. *Availability*: PostGIS, Oracle, SpatiaLite
  519. ``area``
  520. ~~~~~~~~
  521. .. method:: GeoQuerySet.area(**kwargs)
  522. .. deprecated:: 1.9
  523. Use the :class:`~django.contrib.gis.db.models.functions.Area` function
  524. instead.
  525. Returns the area of the geographic field in an ``area`` attribute on
  526. each element of this GeoQuerySet.
  527. ``distance``
  528. ~~~~~~~~~~~~
  529. .. method:: GeoQuerySet.distance(geom, **kwargs)
  530. .. deprecated:: 1.9
  531. Use the :class:`~django.contrib.gis.db.models.functions.Distance` function
  532. instead.
  533. This method takes a geometry as a parameter, and attaches a ``distance``
  534. attribute to every model in the returned queryset that contains the
  535. distance (as a :class:`~django.contrib.gis.measure.Distance` object) to the given geometry.
  536. In the following example (taken from the `GeoDjango distance tests`__),
  537. the distance from the `Tasmanian`__ city of Hobart to every other
  538. :class:`PointField` in the ``AustraliaCity`` queryset is calculated::
  539. >>> pnt = AustraliaCity.objects.get(name='Hobart').point
  540. >>> for city in AustraliaCity.objects.distance(pnt): print(city.name, city.distance)
  541. Wollongong 990071.220408 m
  542. Shellharbour 972804.613941 m
  543. Thirroul 1002334.36351 m
  544. Mittagong 975691.632637 m
  545. Batemans Bay 834342.185561 m
  546. Canberra 598140.268959 m
  547. Melbourne 575337.765042 m
  548. Sydney 1056978.87363 m
  549. Hobart 0.0 m
  550. Adelaide 1162031.83522 m
  551. Hillsdale 1049200.46122 m
  552. .. note::
  553. Because the ``distance`` attribute is a
  554. :class:`~django.contrib.gis.measure.Distance` object, you can easily express
  555. the value in the units of your choice. For example, ``city.distance.mi`` is
  556. the distance value in miles and ``city.distance.km`` is the distance value
  557. in kilometers. See :doc:`measure` for usage details and the list of
  558. :ref:`supported_units`.
  559. __ https://github.com/django/django/blob/master/tests/gis_tests/distapp/models.py
  560. __ https://en.wikipedia.org/wiki/Tasmania
  561. ``length``
  562. ~~~~~~~~~~
  563. .. method:: GeoQuerySet.length(**kwargs)
  564. .. deprecated:: 1.9
  565. Use the :class:`~django.contrib.gis.db.models.functions.Length` function
  566. instead.
  567. Returns the length of the geometry field in a ``length`` attribute
  568. (a :class:`~django.contrib.gis.measure.Distance` object) on each model in
  569. the queryset.
  570. ``perimeter``
  571. ~~~~~~~~~~~~~
  572. .. method:: GeoQuerySet.perimeter(**kwargs)
  573. .. deprecated:: 1.9
  574. Use the :class:`~django.contrib.gis.db.models.functions.Perimeter` function
  575. instead.
  576. Returns the perimeter of the geometry field in a ``perimeter`` attribute
  577. (a :class:`~django.contrib.gis.measure.Distance` object) on each model in
  578. the queryset.
  579. Geometry Relationships
  580. ----------------------
  581. The following methods take no arguments, and attach geometry objects
  582. each element of the :class:`GeoQuerySet` that is the result of relationship
  583. function evaluated on the geometry field.
  584. ``centroid``
  585. ~~~~~~~~~~~~
  586. .. method:: GeoQuerySet.centroid(**kwargs)
  587. .. deprecated:: 1.9
  588. Use the :class:`~django.contrib.gis.db.models.functions.Centroid` function
  589. instead.
  590. *Availability*: PostGIS, Oracle, SpatiaLite
  591. Returns the ``centroid`` value for the geographic field in a ``centroid``
  592. attribute on each element of the ``GeoQuerySet``.
  593. ``envelope``
  594. ~~~~~~~~~~~~
  595. .. method:: GeoQuerySet.envelope(**kwargs)
  596. .. deprecated:: 1.9
  597. Use the :class:`~django.contrib.gis.db.models.functions.Envelope` function
  598. instead.
  599. *Availability*: PostGIS, SpatiaLite
  600. Returns a geometry representing the bounding box of the geometry field in
  601. an ``envelope`` attribute on each element of the ``GeoQuerySet``.
  602. ``point_on_surface``
  603. ~~~~~~~~~~~~~~~~~~~~
  604. .. method:: GeoQuerySet.point_on_surface(**kwargs)
  605. .. deprecated:: 1.9
  606. Use the :class:`~django.contrib.gis.db.models.functions.PointOnSurface`
  607. function instead.
  608. *Availability*: PostGIS, Oracle, SpatiaLite
  609. Returns a Point geometry guaranteed to lie on the surface of the
  610. geometry field in a ``point_on_surface`` attribute on each element
  611. of the queryset; otherwise sets with None.
  612. Geometry Editors
  613. ----------------
  614. ``force_rhr``
  615. ~~~~~~~~~~~~~
  616. .. method:: GeoQuerySet.force_rhr(**kwargs)
  617. .. deprecated:: 1.9
  618. Use the :class:`~django.contrib.gis.db.models.functions.ForceRHR` function
  619. instead.
  620. *Availability*: PostGIS
  621. Returns a modified version of the polygon/multipolygon in which all
  622. of the vertices follow the Right-Hand-Rule, and attaches as a
  623. ``force_rhr`` attribute on each element of the queryset.
  624. ``reverse_geom``
  625. ~~~~~~~~~~~~~~~~
  626. .. method:: GeoQuerySet.reverse_geom(**kwargs)
  627. .. deprecated:: 1.9
  628. Use the :class:`~django.contrib.gis.db.models.functions.Reverse` function
  629. instead.
  630. *Availability*: PostGIS, Oracle
  631. Reverse the coordinate order of the geometry field, and attaches as a
  632. ``reverse`` attribute on each element of the queryset.
  633. ``scale``
  634. ~~~~~~~~~
  635. .. method:: GeoQuerySet.scale(x, y, z=0.0, **kwargs)
  636. .. deprecated:: 1.9
  637. Use the :class:`~django.contrib.gis.db.models.functions.Scale` function
  638. instead.
  639. *Availability*: PostGIS, SpatiaLite
  640. ``snap_to_grid``
  641. ~~~~~~~~~~~~~~~~
  642. .. method:: GeoQuerySet.snap_to_grid(*args, **kwargs)
  643. .. deprecated:: 1.9
  644. Use the :class:`~django.contrib.gis.db.models.functions.SnapToGrid` function
  645. instead.
  646. Snap all points of the input geometry to the grid. How the
  647. geometry is snapped to the grid depends on how many numeric
  648. (either float, integer, or long) arguments are given.
  649. =================== =====================================================
  650. Number of Arguments Description
  651. =================== =====================================================
  652. 1 A single size to snap bot the X and Y grids to.
  653. 2 X and Y sizes to snap the grid to.
  654. 4 X, Y sizes and the corresponding X, Y origins.
  655. =================== =====================================================
  656. ``transform``
  657. ~~~~~~~~~~~~~
  658. .. method:: GeoQuerySet.transform(srid=4326, **kwargs)
  659. .. deprecated:: 1.9
  660. Use the :class:`~django.contrib.gis.db.models.functions.Transform` function
  661. instead.
  662. *Availability*: PostGIS, Oracle, SpatiaLite
  663. The ``transform`` method transforms the geometry field of a model to the spatial
  664. reference system specified by the ``srid`` parameter. If no ``srid`` is given,
  665. then 4326 (WGS84) is used by default.
  666. .. note::
  667. Unlike other ``GeoQuerySet`` methods, ``transform`` stores its output
  668. "in-place". In other words, no new attribute for the transformed
  669. geometry is placed on the models.
  670. .. note::
  671. What spatial reference system an integer SRID corresponds to may depend on
  672. the spatial database used. In other words, the SRID numbers used for Oracle
  673. are not necessarily the same as those used by PostGIS.
  674. Example::
  675. >>> qs = Zipcode.objects.all().transform() # Transforms to WGS84
  676. >>> qs = Zipcode.objects.all().transform(32140) # Transforming to "NAD83 / Texas South Central"
  677. >>> print(qs[0].poly.srid)
  678. 32140
  679. >>> print(qs[0].poly)
  680. POLYGON ((234055.1698884720099159 4937796.9232223574072123 ...
  681. ``translate``
  682. ~~~~~~~~~~~~~
  683. .. method:: GeoQuerySet.translate(x, y, z=0.0, **kwargs)
  684. .. deprecated:: 1.9
  685. Use the :class:`~django.contrib.gis.db.models.functions.Translate` function
  686. instead.
  687. *Availability*: PostGIS, SpatiaLite
  688. Translates the geometry field to a new location using the given numeric
  689. parameters as offsets.
  690. Geometry Operations
  691. -------------------
  692. *Availability*: PostGIS, Oracle, SpatiaLite
  693. The following methods all take a geometry as a parameter and attach a geometry
  694. to each element of the ``GeoQuerySet`` that is the result of the operation.
  695. ``difference``
  696. ~~~~~~~~~~~~~~
  697. .. method:: GeoQuerySet.difference(geom)
  698. .. deprecated:: 1.9
  699. Use the :class:`~django.contrib.gis.db.models.functions.Difference` function
  700. instead.
  701. Returns the spatial difference of the geographic field with the given
  702. geometry in a ``difference`` attribute on each element of the
  703. ``GeoQuerySet``.
  704. ``intersection``
  705. ~~~~~~~~~~~~~~~~
  706. .. method:: GeoQuerySet.intersection(geom)
  707. .. deprecated:: 1.9
  708. Use the :class:`~django.contrib.gis.db.models.functions.Intersection`
  709. function instead.
  710. Returns the spatial intersection of the geographic field with the
  711. given geometry in an ``intersection`` attribute on each element of the
  712. ``GeoQuerySet``.
  713. ``sym_difference``
  714. ~~~~~~~~~~~~~~~~~~
  715. .. method:: GeoQuerySet.sym_difference(geom)
  716. .. deprecated:: 1.9
  717. Use the :class:`~django.contrib.gis.db.models.functions.SymDifference`
  718. function instead.
  719. Returns the symmetric difference of the geographic field with the
  720. given geometry in a ``sym_difference`` attribute on each element of the
  721. ``GeoQuerySet``.
  722. ``union``
  723. ~~~~~~~~~
  724. .. method:: GeoQuerySet.union(geom)
  725. .. deprecated:: 1.9
  726. Use the :class:`~django.contrib.gis.db.models.functions.Union` function
  727. instead.
  728. Returns the union of the geographic field with the given
  729. geometry in an ``union`` attribute on each element of the
  730. ``GeoQuerySet``.
  731. Geometry Output
  732. ---------------
  733. The following ``GeoQuerySet`` methods will return an attribute that has the value
  734. of the geometry field in each model converted to the requested output format.
  735. ``geohash``
  736. ~~~~~~~~~~~
  737. .. method:: GeoQuerySet.geohash(precision=20, **kwargs)
  738. .. deprecated:: 1.9
  739. Use the :class:`~django.contrib.gis.db.models.functions.GeoHash` function
  740. instead.
  741. Attaches a ``geohash`` attribute to every model the queryset
  742. containing the `GeoHash`__ representation of the geometry.
  743. __ http://geohash.org/
  744. ``geojson``
  745. ~~~~~~~~~~~
  746. .. method:: GeoQuerySet.geojson(**kwargs)
  747. .. deprecated:: 1.9
  748. Use the :class:`~django.contrib.gis.db.models.functions.AsGeoJSON` function
  749. instead.
  750. *Availability*: PostGIS, SpatiaLite
  751. Attaches a ``geojson`` attribute to every model in the queryset that contains the
  752. `GeoJSON`__ representation of the geometry.
  753. ===================== =====================================================
  754. Keyword Argument Description
  755. ===================== =====================================================
  756. ``precision`` It may be used to specify the number of significant
  757. digits for the coordinates in the GeoJSON
  758. representation -- the default value is 8.
  759. ``crs`` Set this to ``True`` if you want the coordinate
  760. reference system to be included in the returned
  761. GeoJSON.
  762. ``bbox`` Set this to ``True`` if you want the bounding box
  763. to be included in the returned GeoJSON.
  764. ===================== =====================================================
  765. __ http://geojson.org/
  766. ``gml``
  767. ~~~~~~~
  768. .. method:: GeoQuerySet.gml(**kwargs)
  769. .. deprecated:: 1.9
  770. Use the :class:`~django.contrib.gis.db.models.functions.AsGML` function
  771. instead.
  772. *Availability*: PostGIS, Oracle, SpatiaLite
  773. Attaches a ``gml`` attribute to every model in the queryset that contains the
  774. `Geographic Markup Language (GML)`__ representation of the geometry.
  775. Example::
  776. >>> qs = Zipcode.objects.all().gml()
  777. >>> print(qs[0].gml)
  778. <gml:Polygon srsName="EPSG:4326"><gml:OuterBoundaryIs>-147.78711,70.245363 ... -147.78711,70.245363</gml:OuterBoundaryIs></gml:Polygon>
  779. ===================== =====================================================
  780. Keyword Argument Description
  781. ===================== =====================================================
  782. ``precision`` This keyword is for PostGIS only. It may be used
  783. to specify the number of significant digits for the
  784. coordinates in the GML representation -- the default
  785. value is 8.
  786. ``version`` This keyword is for PostGIS only. It may be used to
  787. specify the GML version used, and may only be values
  788. of 2 or 3. The default value is 2.
  789. ===================== =====================================================
  790. __ https://en.wikipedia.org/wiki/Geography_Markup_Language
  791. ``kml``
  792. ~~~~~~~
  793. .. method:: GeoQuerySet.kml(**kwargs)
  794. .. deprecated:: 1.9
  795. Use the :class:`~django.contrib.gis.db.models.functions.AsKML` function
  796. instead.
  797. *Availability*: PostGIS, SpatiaLite
  798. Attaches a ``kml`` attribute to every model in the queryset that contains the
  799. `Keyhole Markup Language (KML)`__ representation of the geometry fields. It
  800. should be noted that the contents of the KML are transformed to WGS84 if
  801. necessary.
  802. Example::
  803. >>> qs = Zipcode.objects.all().kml()
  804. >>> print(qs[0].kml)
  805. <Polygon><outerBoundaryIs><LinearRing><coordinates>-103.04135,36.217596,0 ... -103.04135,36.217596,0</coordinates></LinearRing></outerBoundaryIs></Polygon>
  806. ===================== =====================================================
  807. Keyword Argument Description
  808. ===================== =====================================================
  809. ``precision`` This keyword may be used to specify the number of
  810. significant digits for the coordinates in the KML
  811. representation -- the default value is 8.
  812. ===================== =====================================================
  813. __ https://developers.google.com/kml/documentation/
  814. ``svg``
  815. ~~~~~~~
  816. .. method:: GeoQuerySet.svg(**kwargs)
  817. .. deprecated:: 1.9
  818. Use the :class:`~django.contrib.gis.db.models.functions.AsSVG` function
  819. instead.
  820. *Availability*: PostGIS, SpatiaLite
  821. Attaches a ``svg`` attribute to every model in the queryset that contains
  822. the `Scalable Vector Graphics (SVG)`__ path data of the geometry fields.
  823. ===================== =====================================================
  824. Keyword Argument Description
  825. ===================== =====================================================
  826. ``relative`` If set to ``True``, the path data will be implemented
  827. in terms of relative moves. Defaults to ``False``,
  828. meaning that absolute moves are used instead.
  829. ``precision`` This keyword may be used to specify the number of
  830. significant digits for the coordinates in the SVG
  831. representation -- the default value is 8.
  832. ===================== =====================================================
  833. __ http://www.w3.org/Graphics/SVG/
  834. Miscellaneous
  835. -------------
  836. ``mem_size``
  837. ~~~~~~~~~~~~
  838. .. method:: GeoQuerySet.mem_size(**kwargs)
  839. .. deprecated:: 1.9
  840. Use the :class:`~django.contrib.gis.db.models.functions.MemSize` function
  841. instead.
  842. *Availability*: PostGIS
  843. Returns the memory size (number of bytes) that the geometry field takes
  844. in a ``mem_size`` attribute on each element of the ``GeoQuerySet``.
  845. ``num_geom``
  846. ~~~~~~~~~~~~
  847. .. method:: GeoQuerySet.num_geom(**kwargs)
  848. .. deprecated:: 1.9
  849. Use the :class:`~django.contrib.gis.db.models.functions.NumGeometries`
  850. function instead.
  851. *Availability*: PostGIS, Oracle, SpatiaLite
  852. Returns the number of geometries in a ``num_geom`` attribute on
  853. each element of the ``GeoQuerySet`` if the geometry field is a
  854. collection (e.g., a ``GEOMETRYCOLLECTION`` or ``MULTI*`` field);
  855. otherwise sets with ``None``.
  856. ``num_points``
  857. ~~~~~~~~~~~~~~
  858. .. method:: GeoQuerySet.num_points(**kwargs)
  859. .. deprecated:: 1.9
  860. Use the :class:`~django.contrib.gis.db.models.functions.NumPoints` function
  861. instead.
  862. *Availability*: PostGIS, Oracle, SpatiaLite
  863. Returns the number of points in the first linestring in the
  864. geometry field in a ``num_points`` attribute on each element of
  865. the ``GeoQuerySet``; otherwise sets with ``None``.
  866. Aggregate Functions
  867. -------------------
  868. Django provides some GIS-specific aggregate functions. For details on how to
  869. use these aggregate functions, see :doc:`the topic guide on aggregation
  870. </topics/db/aggregation>`.
  871. ===================== =====================================================
  872. Keyword Argument Description
  873. ===================== =====================================================
  874. ``tolerance`` This keyword is for Oracle only. It is for the
  875. tolerance value used by the ``SDOAGGRTYPE``
  876. procedure; the `Oracle documentation`__ has more
  877. details.
  878. ===================== =====================================================
  879. __ https://docs.oracle.com/html/B14255_01/sdo_intro.htm#sthref150
  880. Example::
  881. >>> from django.contrib.gis.db.models import Extent, Union
  882. >>> WorldBorder.objects.aggregate(Extent('mpoly'), Union('mpoly'))
  883. ``Collect``
  884. ~~~~~~~~~~~
  885. .. class:: Collect(geo_field)
  886. *Availability*: PostGIS, SpatiaLite
  887. Returns a ``GEOMETRYCOLLECTION`` or a ``MULTI`` geometry object from the geometry
  888. column. This is analogous to a simplified version of the :class:`Union`
  889. aggregate, except it can be several orders of magnitude faster than performing
  890. a union because it simply rolls up geometries into a collection or multi object,
  891. not caring about dissolving boundaries.
  892. ``Extent``
  893. ~~~~~~~~~~
  894. .. class:: Extent(geo_field)
  895. *Availability*: PostGIS, Oracle, SpatiaLite
  896. Returns the extent of all ``geo_field`` in the ``QuerySet`` as a four-tuple,
  897. comprising the lower left coordinate and the upper right coordinate.
  898. Example::
  899. >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent('poly'))
  900. >>> print(qs['poly__extent'])
  901. (-96.8016128540039, 29.7633724212646, -95.3631439208984, 32.782058715820)
  902. ``Extent3D``
  903. ~~~~~~~~~~~~
  904. .. class:: Extent3D(geo_field)
  905. *Availability*: PostGIS
  906. Returns the 3D extent of all ``geo_field`` in the ``QuerySet`` as a six-tuple,
  907. comprising the lower left coordinate and upper right coordinate (each with x, y,
  908. and z coordinates).
  909. Example::
  910. >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent3D('poly'))
  911. >>> print(qs['poly__extent3d'])
  912. (-96.8016128540039, 29.7633724212646, 0, -95.3631439208984, 32.782058715820, 0)
  913. ``MakeLine``
  914. ~~~~~~~~~~~~
  915. .. class:: MakeLine(geo_field)
  916. *Availability*: PostGIS, SpatiaLite
  917. Returns a ``LineString`` constructed from the point field geometries in the
  918. ``QuerySet``. Currently, ordering the queryset has no effect.
  919. .. versionchanged:: 1.10
  920. SpatiaLite support was added.
  921. Example::
  922. >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(MakeLine('poly'))
  923. >>> print(qs['poly__makeline'])
  924. LINESTRING (-95.3631510000000020 29.7633739999999989, -96.8016109999999941 32.7820570000000018)
  925. ``Union``
  926. ~~~~~~~~~
  927. .. class:: Union(geo_field)
  928. *Availability*: PostGIS, Oracle, SpatiaLite
  929. This method returns a :class:`~django.contrib.gis.geos.GEOSGeometry` object
  930. comprising the union of every geometry in the queryset. Please note that use of
  931. ``Union`` is processor intensive and may take a significant amount of time on
  932. large querysets.
  933. .. note::
  934. If the computation time for using this method is too expensive, consider
  935. using :class:`Collect` instead.
  936. Example::
  937. >>> u = Zipcode.objects.aggregate(Union(poly)) # This may take a long time.
  938. >>> u = Zipcode.objects.filter(poly__within=bbox).aggregate(Union(poly)) # A more sensible approach.
  939. .. rubric:: Footnotes
  940. .. [#fnde9im] *See* `OpenGIS Simple Feature Specification For SQL <http://www.opengis.org/docs/99-049.pdf>`_, at Ch. 2.1.13.2, p. 2-13 (The Dimensionally Extended Nine-Intersection Model).
  941. .. [#fnsdorelate] *See* `SDO_RELATE documentation <https://docs.oracle.com/cd/B19306_01/appdev.102/b14255/sdo_operat.htm#sthref845>`_, from Ch. 11 of the Oracle Spatial User's Guide and Manual.
  942. .. [#fncovers] For an explanation of this routine, read `Quirks of the "Contains" Spatial Predicate <http://lin-ear-th-inking.blogspot.com/2007/06/subtleties-of-ogc-covers-spatial.html>`_ by Martin Davis (a PostGIS developer).
  943. .. [#fncontainsproperly] Refer to the PostGIS ``ST_ContainsProperly`` `documentation <http://postgis.net/docs/ST_ContainsProperly.html>`_ for more details.