geoquerysets.txt 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  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. ========== ======================================
  466. .. note::
  467. This lookup is not available on SpatiaLite.
  468. .. _geoqueryset-methods:
  469. ``GeoQuerySet`` Methods
  470. =======================
  471. .. deprecated:: 1.9
  472. Using ``GeoQuerySet`` methods is now deprecated in favor of the new
  473. :doc:`functions`. Albeit a little more verbose, they are much more powerful
  474. in how it is possible to combine them to build more complex queries.
  475. ``GeoQuerySet`` methods specify that a spatial operation be performed
  476. on each spatial operation on each geographic
  477. field in the queryset and store its output in a new attribute on the model
  478. (which is generally the name of the ``GeoQuerySet`` method).
  479. There are also aggregate ``GeoQuerySet`` methods which return a single value
  480. instead of a queryset. This section will describe the API and availability
  481. of every ``GeoQuerySet`` method available in GeoDjango.
  482. .. note::
  483. What methods are available depend on your spatial backend. See
  484. the :ref:`compatibility table <database-functions-compatibility>`
  485. for more details.
  486. With a few exceptions, the following keyword arguments may be used with all
  487. ``GeoQuerySet`` methods:
  488. ===================== =====================================================
  489. Keyword Argument Description
  490. ===================== =====================================================
  491. ``field_name`` By default, ``GeoQuerySet`` methods use the first
  492. geographic field encountered in the model. This
  493. keyword should be used to specify another
  494. geographic field (e.g., ``field_name='point2'``)
  495. when there are multiple geographic fields in a model.
  496. On PostGIS, the ``field_name`` keyword may also be
  497. used on geometry fields in models that are related
  498. via a ``ForeignKey`` relation (e.g.,
  499. ``field_name='related__point'``).
  500. ``model_att`` By default, ``GeoQuerySet`` methods typically attach
  501. their output in an attribute with the same name as
  502. the ``GeoQuerySet`` method. Setting this keyword
  503. with the desired attribute name will override this
  504. default behavior. For example,
  505. ``qs = Zipcode.objects.centroid(model_att='c')`` will
  506. attach the centroid of the ``Zipcode`` geometry field
  507. in a ``c`` attribute on every model rather than in a
  508. ``centroid`` attribute.
  509. This keyword is required if
  510. a method name clashes with an existing
  511. ``GeoQuerySet`` method -- if you wanted to use the
  512. ``area()`` method on model with a ``PolygonField``
  513. named ``area``, for example.
  514. ===================== =====================================================
  515. Measurement
  516. -----------
  517. *Availability*: PostGIS, Oracle, SpatiaLite
  518. ``area``
  519. ~~~~~~~~
  520. .. method:: GeoQuerySet.area(**kwargs)
  521. .. deprecated:: 1.9
  522. Use the :class:`~django.contrib.gis.db.models.functions.Area` function
  523. instead.
  524. Returns the area of the geographic field in an ``area`` attribute on
  525. each element of this GeoQuerySet.
  526. ``distance``
  527. ~~~~~~~~~~~~
  528. .. method:: GeoQuerySet.distance(geom, **kwargs)
  529. .. deprecated:: 1.9
  530. Use the :class:`~django.contrib.gis.db.models.functions.Distance` function
  531. instead.
  532. This method takes a geometry as a parameter, and attaches a ``distance``
  533. attribute to every model in the returned queryset that contains the
  534. distance (as a :class:`~django.contrib.gis.measure.Distance` object) to the given geometry.
  535. In the following example (taken from the `GeoDjango distance tests`__),
  536. the distance from the `Tasmanian`__ city of Hobart to every other
  537. :class:`PointField` in the ``AustraliaCity`` queryset is calculated::
  538. >>> pnt = AustraliaCity.objects.get(name='Hobart').point
  539. >>> for city in AustraliaCity.objects.distance(pnt): print(city.name, city.distance)
  540. Wollongong 990071.220408 m
  541. Shellharbour 972804.613941 m
  542. Thirroul 1002334.36351 m
  543. Mittagong 975691.632637 m
  544. Batemans Bay 834342.185561 m
  545. Canberra 598140.268959 m
  546. Melbourne 575337.765042 m
  547. Sydney 1056978.87363 m
  548. Hobart 0.0 m
  549. Adelaide 1162031.83522 m
  550. Hillsdale 1049200.46122 m
  551. .. note::
  552. Because the ``distance`` attribute is a
  553. :class:`~django.contrib.gis.measure.Distance` object, you can easily express
  554. the value in the units of your choice. For example, ``city.distance.mi`` is
  555. the distance value in miles and ``city.distance.km`` is the distance value
  556. in kilometers. See :doc:`measure` for usage details and the list of
  557. :ref:`supported_units`.
  558. __ https://github.com/django/django/blob/master/tests/gis_tests/distapp/models.py
  559. __ https://en.wikipedia.org/wiki/Tasmania
  560. ``length``
  561. ~~~~~~~~~~
  562. .. method:: GeoQuerySet.length(**kwargs)
  563. .. deprecated:: 1.9
  564. Use the :class:`~django.contrib.gis.db.models.functions.Length` function
  565. instead.
  566. Returns the length of the geometry field in a ``length`` attribute
  567. (a :class:`~django.contrib.gis.measure.Distance` object) on each model in
  568. the queryset.
  569. ``perimeter``
  570. ~~~~~~~~~~~~~
  571. .. method:: GeoQuerySet.perimeter(**kwargs)
  572. .. deprecated:: 1.9
  573. Use the :class:`~django.contrib.gis.db.models.functions.Perimeter` function
  574. instead.
  575. Returns the perimeter of the geometry field in a ``perimeter`` attribute
  576. (a :class:`~django.contrib.gis.measure.Distance` object) on each model in
  577. the queryset.
  578. Geometry Relationships
  579. ----------------------
  580. The following methods take no arguments, and attach geometry objects
  581. each element of the :class:`GeoQuerySet` that is the result of relationship
  582. function evaluated on the geometry field.
  583. ``centroid``
  584. ~~~~~~~~~~~~
  585. .. method:: GeoQuerySet.centroid(**kwargs)
  586. .. deprecated:: 1.9
  587. Use the :class:`~django.contrib.gis.db.models.functions.Centroid` function
  588. instead.
  589. *Availability*: PostGIS, Oracle, SpatiaLite
  590. Returns the ``centroid`` value for the geographic field in a ``centroid``
  591. attribute on each element of the ``GeoQuerySet``.
  592. ``envelope``
  593. ~~~~~~~~~~~~
  594. .. method:: GeoQuerySet.envelope(**kwargs)
  595. .. deprecated:: 1.9
  596. Use the :class:`~django.contrib.gis.db.models.functions.Envelope` function
  597. instead.
  598. *Availability*: PostGIS, SpatiaLite
  599. Returns a geometry representing the bounding box of the geometry field in
  600. an ``envelope`` attribute on each element of the ``GeoQuerySet``.
  601. ``point_on_surface``
  602. ~~~~~~~~~~~~~~~~~~~~
  603. .. method:: GeoQuerySet.point_on_surface(**kwargs)
  604. .. deprecated:: 1.9
  605. Use the :class:`~django.contrib.gis.db.models.functions.PointOnSurface`
  606. function instead.
  607. *Availability*: PostGIS, Oracle, SpatiaLite
  608. Returns a Point geometry guaranteed to lie on the surface of the
  609. geometry field in a ``point_on_surface`` attribute on each element
  610. of the queryset; otherwise sets with None.
  611. Geometry Editors
  612. ----------------
  613. ``force_rhr``
  614. ~~~~~~~~~~~~~
  615. .. method:: GeoQuerySet.force_rhr(**kwargs)
  616. .. deprecated:: 1.9
  617. Use the :class:`~django.contrib.gis.db.models.functions.ForceRHR` function
  618. instead.
  619. *Availability*: PostGIS
  620. Returns a modified version of the polygon/multipolygon in which all
  621. of the vertices follow the Right-Hand-Rule, and attaches as a
  622. ``force_rhr`` attribute on each element of the queryset.
  623. ``reverse_geom``
  624. ~~~~~~~~~~~~~~~~
  625. .. method:: GeoQuerySet.reverse_geom(**kwargs)
  626. .. deprecated:: 1.9
  627. Use the :class:`~django.contrib.gis.db.models.functions.Reverse` function
  628. instead.
  629. *Availability*: PostGIS, Oracle
  630. Reverse the coordinate order of the geometry field, and attaches as a
  631. ``reverse`` attribute on each element of the queryset.
  632. ``scale``
  633. ~~~~~~~~~
  634. .. method:: GeoQuerySet.scale(x, y, z=0.0, **kwargs)
  635. .. deprecated:: 1.9
  636. Use the :class:`~django.contrib.gis.db.models.functions.Scale` function
  637. instead.
  638. *Availability*: PostGIS, SpatiaLite
  639. ``snap_to_grid``
  640. ~~~~~~~~~~~~~~~~
  641. .. method:: GeoQuerySet.snap_to_grid(*args, **kwargs)
  642. .. deprecated:: 1.9
  643. Use the :class:`~django.contrib.gis.db.models.functions.SnapToGrid` function
  644. instead.
  645. Snap all points of the input geometry to the grid. How the
  646. geometry is snapped to the grid depends on how many numeric
  647. (either float, integer, or long) arguments are given.
  648. =================== =====================================================
  649. Number of Arguments Description
  650. =================== =====================================================
  651. 1 A single size to snap bot the X and Y grids to.
  652. 2 X and Y sizes to snap the grid to.
  653. 4 X, Y sizes and the corresponding X, Y origins.
  654. =================== =====================================================
  655. ``transform``
  656. ~~~~~~~~~~~~~
  657. .. method:: GeoQuerySet.transform(srid=4326, **kwargs)
  658. .. deprecated:: 1.9
  659. Use the :class:`~django.contrib.gis.db.models.functions.Transform` function
  660. instead.
  661. *Availability*: PostGIS, Oracle, SpatiaLite
  662. The ``transform`` method transforms the geometry field of a model to the spatial
  663. reference system specified by the ``srid`` parameter. If no ``srid`` is given,
  664. then 4326 (WGS84) is used by default.
  665. .. note::
  666. Unlike other ``GeoQuerySet`` methods, ``transform`` stores its output
  667. "in-place". In other words, no new attribute for the transformed
  668. geometry is placed on the models.
  669. .. note::
  670. What spatial reference system an integer SRID corresponds to may depend on
  671. the spatial database used. In other words, the SRID numbers used for Oracle
  672. are not necessarily the same as those used by PostGIS.
  673. Example::
  674. >>> qs = Zipcode.objects.all().transform() # Transforms to WGS84
  675. >>> qs = Zipcode.objects.all().transform(32140) # Transforming to "NAD83 / Texas South Central"
  676. >>> print(qs[0].poly.srid)
  677. 32140
  678. >>> print(qs[0].poly)
  679. POLYGON ((234055.1698884720099159 4937796.9232223574072123 ...
  680. ``translate``
  681. ~~~~~~~~~~~~~
  682. .. method:: GeoQuerySet.translate(x, y, z=0.0, **kwargs)
  683. .. deprecated:: 1.9
  684. Use the :class:`~django.contrib.gis.db.models.functions.Translate` function
  685. instead.
  686. *Availability*: PostGIS, SpatiaLite
  687. Translates the geometry field to a new location using the given numeric
  688. parameters as offsets.
  689. Geometry Operations
  690. -------------------
  691. *Availability*: PostGIS, Oracle, SpatiaLite
  692. The following methods all take a geometry as a parameter and attach a geometry
  693. to each element of the ``GeoQuerySet`` that is the result of the operation.
  694. ``difference``
  695. ~~~~~~~~~~~~~~
  696. .. method:: GeoQuerySet.difference(geom)
  697. .. deprecated:: 1.9
  698. Use the :class:`~django.contrib.gis.db.models.functions.Difference` function
  699. instead.
  700. Returns the spatial difference of the geographic field with the given
  701. geometry in a ``difference`` attribute on each element of the
  702. ``GeoQuerySet``.
  703. ``intersection``
  704. ~~~~~~~~~~~~~~~~
  705. .. method:: GeoQuerySet.intersection(geom)
  706. .. deprecated:: 1.9
  707. Use the :class:`~django.contrib.gis.db.models.functions.Intersection`
  708. function instead.
  709. Returns the spatial intersection of the geographic field with the
  710. given geometry in an ``intersection`` attribute on each element of the
  711. ``GeoQuerySet``.
  712. ``sym_difference``
  713. ~~~~~~~~~~~~~~~~~~
  714. .. method:: GeoQuerySet.sym_difference(geom)
  715. .. deprecated:: 1.9
  716. Use the :class:`~django.contrib.gis.db.models.functions.SymDifference`
  717. function instead.
  718. Returns the symmetric difference of the geographic field with the
  719. given geometry in a ``sym_difference`` attribute on each element of the
  720. ``GeoQuerySet``.
  721. ``union``
  722. ~~~~~~~~~
  723. .. method:: GeoQuerySet.union(geom)
  724. .. deprecated:: 1.9
  725. Use the :class:`~django.contrib.gis.db.models.functions.Union` function
  726. instead.
  727. Returns the union of the geographic field with the given
  728. geometry in an ``union`` attribute on each element of the
  729. ``GeoQuerySet``.
  730. Geometry Output
  731. ---------------
  732. The following ``GeoQuerySet`` methods will return an attribute that has the value
  733. of the geometry field in each model converted to the requested output format.
  734. ``geohash``
  735. ~~~~~~~~~~~
  736. .. method:: GeoQuerySet.geohash(precision=20, **kwargs)
  737. .. deprecated:: 1.9
  738. Use the :class:`~django.contrib.gis.db.models.functions.GeoHash` function
  739. instead.
  740. Attaches a ``geohash`` attribute to every model the queryset
  741. containing the `GeoHash`__ representation of the geometry.
  742. __ http://geohash.org/
  743. ``geojson``
  744. ~~~~~~~~~~~
  745. .. method:: GeoQuerySet.geojson(**kwargs)
  746. .. deprecated:: 1.9
  747. Use the :class:`~django.contrib.gis.db.models.functions.AsGeoJSON` function
  748. instead.
  749. *Availability*: PostGIS, SpatiaLite
  750. Attaches a ``geojson`` attribute to every model in the queryset that contains the
  751. `GeoJSON`__ representation of the geometry.
  752. ===================== =====================================================
  753. Keyword Argument Description
  754. ===================== =====================================================
  755. ``precision`` It may be used to specify the number of significant
  756. digits for the coordinates in the GeoJSON
  757. representation -- the default value is 8.
  758. ``crs`` Set this to ``True`` if you want the coordinate
  759. reference system to be included in the returned
  760. GeoJSON.
  761. ``bbox`` Set this to ``True`` if you want the bounding box
  762. to be included in the returned GeoJSON.
  763. ===================== =====================================================
  764. __ http://geojson.org/
  765. ``gml``
  766. ~~~~~~~
  767. .. method:: GeoQuerySet.gml(**kwargs)
  768. .. deprecated:: 1.9
  769. Use the :class:`~django.contrib.gis.db.models.functions.AsGML` function
  770. instead.
  771. *Availability*: PostGIS, Oracle, SpatiaLite
  772. Attaches a ``gml`` attribute to every model in the queryset that contains the
  773. `Geographic Markup Language (GML)`__ representation of the geometry.
  774. Example::
  775. >>> qs = Zipcode.objects.all().gml()
  776. >>> print(qs[0].gml)
  777. <gml:Polygon srsName="EPSG:4326"><gml:OuterBoundaryIs>-147.78711,70.245363 ... -147.78711,70.245363</gml:OuterBoundaryIs></gml:Polygon>
  778. ===================== =====================================================
  779. Keyword Argument Description
  780. ===================== =====================================================
  781. ``precision`` This keyword is for PostGIS only. It may be used
  782. to specify the number of significant digits for the
  783. coordinates in the GML representation -- the default
  784. value is 8.
  785. ``version`` This keyword is for PostGIS only. It may be used to
  786. specify the GML version used, and may only be values
  787. of 2 or 3. The default value is 2.
  788. ===================== =====================================================
  789. __ https://en.wikipedia.org/wiki/Geography_Markup_Language
  790. ``kml``
  791. ~~~~~~~
  792. .. method:: GeoQuerySet.kml(**kwargs)
  793. .. deprecated:: 1.9
  794. Use the :class:`~django.contrib.gis.db.models.functions.AsKML` function
  795. instead.
  796. *Availability*: PostGIS, SpatiaLite
  797. Attaches a ``kml`` attribute to every model in the queryset that contains the
  798. `Keyhole Markup Language (KML)`__ representation of the geometry fields. It
  799. should be noted that the contents of the KML are transformed to WGS84 if
  800. necessary.
  801. Example::
  802. >>> qs = Zipcode.objects.all().kml()
  803. >>> print(qs[0].kml)
  804. <Polygon><outerBoundaryIs><LinearRing><coordinates>-103.04135,36.217596,0 ... -103.04135,36.217596,0</coordinates></LinearRing></outerBoundaryIs></Polygon>
  805. ===================== =====================================================
  806. Keyword Argument Description
  807. ===================== =====================================================
  808. ``precision`` This keyword may be used to specify the number of
  809. significant digits for the coordinates in the KML
  810. representation -- the default value is 8.
  811. ===================== =====================================================
  812. __ https://developers.google.com/kml/documentation/
  813. ``svg``
  814. ~~~~~~~
  815. .. method:: GeoQuerySet.svg(**kwargs)
  816. .. deprecated:: 1.9
  817. Use the :class:`~django.contrib.gis.db.models.functions.AsSVG` function
  818. instead.
  819. *Availability*: PostGIS, SpatiaLite
  820. Attaches a ``svg`` attribute to every model in the queryset that contains
  821. the `Scalable Vector Graphics (SVG)`__ path data of the geometry fields.
  822. ===================== =====================================================
  823. Keyword Argument Description
  824. ===================== =====================================================
  825. ``relative`` If set to ``True``, the path data will be implemented
  826. in terms of relative moves. Defaults to ``False``,
  827. meaning that absolute moves are used instead.
  828. ``precision`` This keyword may be used to specify the number of
  829. significant digits for the coordinates in the SVG
  830. representation -- the default value is 8.
  831. ===================== =====================================================
  832. __ http://www.w3.org/Graphics/SVG/
  833. Miscellaneous
  834. -------------
  835. ``mem_size``
  836. ~~~~~~~~~~~~
  837. .. method:: GeoQuerySet.mem_size(**kwargs)
  838. .. deprecated:: 1.9
  839. Use the :class:`~django.contrib.gis.db.models.functions.MemSize` function
  840. instead.
  841. *Availability*: PostGIS
  842. Returns the memory size (number of bytes) that the geometry field takes
  843. in a ``mem_size`` attribute on each element of the ``GeoQuerySet``.
  844. ``num_geom``
  845. ~~~~~~~~~~~~
  846. .. method:: GeoQuerySet.num_geom(**kwargs)
  847. .. deprecated:: 1.9
  848. Use the :class:`~django.contrib.gis.db.models.functions.NumGeometries`
  849. function instead.
  850. *Availability*: PostGIS, Oracle, SpatiaLite
  851. Returns the number of geometries in a ``num_geom`` attribute on
  852. each element of the ``GeoQuerySet`` if the geometry field is a
  853. collection (e.g., a ``GEOMETRYCOLLECTION`` or ``MULTI*`` field);
  854. otherwise sets with ``None``.
  855. ``num_points``
  856. ~~~~~~~~~~~~~~
  857. .. method:: GeoQuerySet.num_points(**kwargs)
  858. .. deprecated:: 1.9
  859. Use the :class:`~django.contrib.gis.db.models.functions.NumPoints` function
  860. instead.
  861. *Availability*: PostGIS, Oracle, SpatiaLite
  862. Returns the number of points in the first linestring in the
  863. geometry field in a ``num_points`` attribute on each element of
  864. the ``GeoQuerySet``; otherwise sets with ``None``.
  865. Aggregate Functions
  866. -------------------
  867. Django provides some GIS-specific aggregate functions. For details on how to
  868. use these aggregate functions, see :doc:`the topic guide on aggregation
  869. </topics/db/aggregation>`.
  870. ===================== =====================================================
  871. Keyword Argument Description
  872. ===================== =====================================================
  873. ``tolerance`` This keyword is for Oracle only. It is for the
  874. tolerance value used by the ``SDOAGGRTYPE``
  875. procedure; the `Oracle documentation`__ has more
  876. details.
  877. ===================== =====================================================
  878. __ https://docs.oracle.com/html/B14255_01/sdo_intro.htm#sthref150
  879. Example::
  880. >>> from django.contrib.gis.db.models import Extent, Union
  881. >>> WorldBorder.objects.aggregate(Extent('mpoly'), Union('mpoly'))
  882. ``Collect``
  883. ~~~~~~~~~~~
  884. .. class:: Collect(geo_field)
  885. *Availability*: PostGIS, SpatiaLite
  886. Returns a ``GEOMETRYCOLLECTION`` or a ``MULTI`` geometry object from the geometry
  887. column. This is analogous to a simplified version of the :class:`Union`
  888. aggregate, except it can be several orders of magnitude faster than performing
  889. a union because it simply rolls up geometries into a collection or multi object,
  890. not caring about dissolving boundaries.
  891. ``Extent``
  892. ~~~~~~~~~~
  893. .. class:: Extent(geo_field)
  894. *Availability*: PostGIS, Oracle, SpatiaLite
  895. Returns the extent of all ``geo_field`` in the ``QuerySet`` as a four-tuple,
  896. comprising the lower left coordinate and the upper right coordinate.
  897. Example::
  898. >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent('poly'))
  899. >>> print(qs['poly__extent'])
  900. (-96.8016128540039, 29.7633724212646, -95.3631439208984, 32.782058715820)
  901. ``Extent3D``
  902. ~~~~~~~~~~~~
  903. .. class:: Extent3D(geo_field)
  904. *Availability*: PostGIS
  905. Returns the 3D extent of all ``geo_field`` in the ``QuerySet`` as a six-tuple,
  906. comprising the lower left coordinate and upper right coordinate (each with x, y,
  907. and z coordinates).
  908. Example::
  909. >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent3D('poly'))
  910. >>> print(qs['poly__extent3d'])
  911. (-96.8016128540039, 29.7633724212646, 0, -95.3631439208984, 32.782058715820, 0)
  912. ``MakeLine``
  913. ~~~~~~~~~~~~
  914. .. class:: MakeLine(geo_field)
  915. *Availability*: PostGIS, SpatiaLite
  916. Returns a ``LineString`` constructed from the point field geometries in the
  917. ``QuerySet``. Currently, ordering the queryset has no effect.
  918. .. versionchanged:: 1.10
  919. SpatiaLite support was added.
  920. Example::
  921. >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(MakeLine('poly'))
  922. >>> print(qs['poly__makeline'])
  923. LINESTRING (-95.3631510000000020 29.7633739999999989, -96.8016109999999941 32.7820570000000018)
  924. ``Union``
  925. ~~~~~~~~~
  926. .. class:: Union(geo_field)
  927. *Availability*: PostGIS, Oracle, SpatiaLite
  928. This method returns a :class:`~django.contrib.gis.geos.GEOSGeometry` object
  929. comprising the union of every geometry in the queryset. Please note that use of
  930. ``Union`` is processor intensive and may take a significant amount of time on
  931. large querysets.
  932. .. note::
  933. If the computation time for using this method is too expensive, consider
  934. using :class:`Collect` instead.
  935. Example::
  936. >>> u = Zipcode.objects.aggregate(Union(poly)) # This may take a long time.
  937. >>> u = Zipcode.objects.filter(poly__within=bbox).aggregate(Union(poly)) # A more sensible approach.
  938. .. rubric:: Footnotes
  939. .. [#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).
  940. .. [#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.
  941. .. [#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).
  942. .. [#fncontainsproperly] Refer to the PostGIS ``ST_ContainsProperly`` `documentation <http://postgis.net/docs/manual-1.5/ST_ContainsProperly.html>`_ for more details.