mirror of
https://github.com/django/django.git
synced 2025-05-29 18:26:29 +00:00
Fixed #34266 -- Added ClosestPoint GIS database functions.
This commit is contained in:
parent
4b066bde69
commit
79c298c9ce
@ -42,6 +42,7 @@ class BaseSpatialOperations:
|
|||||||
"Azimuth",
|
"Azimuth",
|
||||||
"BoundingCircle",
|
"BoundingCircle",
|
||||||
"Centroid",
|
"Centroid",
|
||||||
|
"ClosestPoint",
|
||||||
"Difference",
|
"Difference",
|
||||||
"Distance",
|
"Distance",
|
||||||
"Envelope",
|
"Envelope",
|
||||||
|
@ -75,6 +75,7 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
|
|||||||
"AsSVG",
|
"AsSVG",
|
||||||
"Azimuth",
|
"Azimuth",
|
||||||
"BoundingCircle",
|
"BoundingCircle",
|
||||||
|
"ClosestPoint",
|
||||||
"ForcePolygonCW",
|
"ForcePolygonCW",
|
||||||
"GeometryDistance",
|
"GeometryDistance",
|
||||||
"IsEmpty",
|
"IsEmpty",
|
||||||
|
@ -121,6 +121,7 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations):
|
|||||||
"AsKML",
|
"AsKML",
|
||||||
"AsSVG",
|
"AsSVG",
|
||||||
"Azimuth",
|
"Azimuth",
|
||||||
|
"ClosestPoint",
|
||||||
"ForcePolygonCW",
|
"ForcePolygonCW",
|
||||||
"GeoHash",
|
"GeoHash",
|
||||||
"GeometryDistance",
|
"GeometryDistance",
|
||||||
|
@ -280,6 +280,11 @@ class Centroid(OracleToleranceMixin, GeomOutputGeoFunc):
|
|||||||
arity = 1
|
arity = 1
|
||||||
|
|
||||||
|
|
||||||
|
class ClosestPoint(GeomOutputGeoFunc):
|
||||||
|
arity = 2
|
||||||
|
geom_param_pos = (0, 1)
|
||||||
|
|
||||||
|
|
||||||
class Difference(OracleToleranceMixin, GeomOutputGeoFunc):
|
class Difference(OracleToleranceMixin, GeomOutputGeoFunc):
|
||||||
arity = 2
|
arity = 2
|
||||||
geom_param_pos = (0, 1)
|
geom_param_pos = (0, 1)
|
||||||
|
@ -356,6 +356,7 @@ Function PostGIS Oracle MariaDB MySQL
|
|||||||
:class:`Azimuth` X X (LWGEOM/RTTOPO)
|
:class:`Azimuth` X X (LWGEOM/RTTOPO)
|
||||||
:class:`BoundingCircle` X X
|
:class:`BoundingCircle` X X
|
||||||
:class:`Centroid` X X X X X
|
:class:`Centroid` X X X X X
|
||||||
|
:class:`ClosestPoint` X X
|
||||||
:class:`Difference` X X X X X
|
:class:`Difference` X X X X X
|
||||||
:class:`Distance` X X X X X
|
:class:`Distance` X X X X X
|
||||||
:class:`Envelope` X X X X X
|
:class:`Envelope` X X X X X
|
||||||
|
@ -26,10 +26,10 @@ Measurement Relationships Operations Edi
|
|||||||
:class:`Area` :class:`Azimuth` :class:`Difference` :class:`ForcePolygonCW` :class:`AsGeoJSON` :class:`IsEmpty`
|
:class:`Area` :class:`Azimuth` :class:`Difference` :class:`ForcePolygonCW` :class:`AsGeoJSON` :class:`IsEmpty`
|
||||||
:class:`Distance` :class:`BoundingCircle` :class:`Intersection` :class:`MakeValid` :class:`AsGML` :class:`IsValid`
|
:class:`Distance` :class:`BoundingCircle` :class:`Intersection` :class:`MakeValid` :class:`AsGML` :class:`IsValid`
|
||||||
:class:`GeometryDistance` :class:`Centroid` :class:`SymDifference` :class:`Reverse` :class:`AsKML` :class:`MemSize`
|
:class:`GeometryDistance` :class:`Centroid` :class:`SymDifference` :class:`Reverse` :class:`AsKML` :class:`MemSize`
|
||||||
:class:`Length` :class:`Envelope` :class:`Union` :class:`Scale` :class:`AsSVG` :class:`NumGeometries`
|
:class:`Length` :class:`ClosestPoint` :class:`Union` :class:`Scale` :class:`AsSVG` :class:`NumGeometries`
|
||||||
:class:`Perimeter` :class:`LineLocatePoint` :class:`SnapToGrid` :class:`FromWKB` :class:`AsWKB` :class:`NumPoints`
|
:class:`Perimeter` :class:`Envelope` :class:`SnapToGrid` :class:`FromWKB` :class:`AsWKB` :class:`NumPoints`
|
||||||
:class:`PointOnSurface` :class:`Transform` :class:`FromWKT` :class:`AsWKT`
|
:class:`LineLocatePoint` :class:`Transform` :class:`FromWKT` :class:`AsWKT`
|
||||||
:class:`Translate` :class:`GeoHash`
|
:class:`PointOnSurface` :class:`Translate` :class:`GeoHash`
|
||||||
========================= ======================== ====================== ======================= ================== ================== ======================
|
========================= ======================== ====================== ======================= ================== ================== ======================
|
||||||
|
|
||||||
``Area``
|
``Area``
|
||||||
@ -237,6 +237,19 @@ The ``num_seg`` parameter is used only on PostGIS.
|
|||||||
Accepts a single geographic field or expression and returns the ``centroid``
|
Accepts a single geographic field or expression and returns the ``centroid``
|
||||||
value of the geometry.
|
value of the geometry.
|
||||||
|
|
||||||
|
``ClosestPoint``
|
||||||
|
================
|
||||||
|
|
||||||
|
.. versionadded:: 5.0
|
||||||
|
|
||||||
|
.. class:: ClosestPoint(expr1, expr2, **extra)
|
||||||
|
|
||||||
|
*Availability*: `PostGIS <https://postgis.net/docs/ST_ClosestPoint.html>`__,
|
||||||
|
SpatiaLite
|
||||||
|
|
||||||
|
Accepts two geographic fields or expressions and returns the 2-dimensional
|
||||||
|
point on geometry A that is closest to geometry B.
|
||||||
|
|
||||||
``Difference``
|
``Difference``
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
@ -64,7 +64,10 @@ Minor features
|
|||||||
:mod:`django.contrib.gis`
|
:mod:`django.contrib.gis`
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
* ...
|
* The new
|
||||||
|
:class:`ClosestPoint() <django.contrib.gis.db.models.functions.ClosestPoint>`
|
||||||
|
function returns a 2-dimensional point on the geometry that is closest to
|
||||||
|
another geometry.
|
||||||
|
|
||||||
:mod:`django.contrib.messages`
|
:mod:`django.contrib.messages`
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -456,6 +456,18 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
|||||||
):
|
):
|
||||||
qs.get(area__lt=500000)
|
qs.get(area__lt=500000)
|
||||||
|
|
||||||
|
@skipUnlessDBFeature("has_ClosestPoint_function")
|
||||||
|
def test_closest_point(self):
|
||||||
|
qs = Country.objects.annotate(
|
||||||
|
closest_point=functions.ClosestPoint("mpoly", functions.Centroid("mpoly"))
|
||||||
|
)
|
||||||
|
for country in qs:
|
||||||
|
self.assertIsInstance(country.closest_point, Point)
|
||||||
|
self.assertEqual(
|
||||||
|
country.mpoly.intersection(country.closest_point),
|
||||||
|
country.closest_point,
|
||||||
|
)
|
||||||
|
|
||||||
@skipUnlessDBFeature("has_LineLocatePoint_function")
|
@skipUnlessDBFeature("has_LineLocatePoint_function")
|
||||||
def test_line_locate_point(self):
|
def test_line_locate_point(self):
|
||||||
pos_expr = functions.LineLocatePoint(
|
pos_expr = functions.LineLocatePoint(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user