summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAhmed Ibrahim <ahmeddark369@gmail.com>2025-07-17 09:50:39 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2025-07-20 11:18:38 +0200
commita5b0a618c3ff16f9f52a9abdc89c05899ef112b4 (patch)
tree08c83f12bfe69d585b3c40fecb215dceaa52a4b3 /tests
parent6aa05fd23205fce523924e307f78ce8d614af7f1 (diff)
Fixed #28696 -- Added GeometryType GIS database function and __geom_type lookup.
Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/gis_tests/geoapp/test_functions.py66
1 files changed, 64 insertions, 2 deletions
diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py
index 9844905200..989f6069cd 100644
--- a/tests/gis_tests/geoapp/test_functions.py
+++ b/tests/gis_tests/geoapp/test_functions.py
@@ -4,14 +4,31 @@ import re
from decimal import Decimal
from django.contrib.gis.db.models import GeometryField, PolygonField, functions
-from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon, fromstr
+from django.contrib.gis.geos import (
+ GEOSGeometry,
+ LineString,
+ MultiLineString,
+ MultiPoint,
+ MultiPolygon,
+ Point,
+ Polygon,
+ fromstr,
+)
from django.contrib.gis.measure import Area
from django.db import NotSupportedError, connection
from django.db.models import IntegerField, Sum, Value
from django.test import TestCase, skipUnlessDBFeature
from ..utils import FuncTestMixin
-from .models import City, Country, CountryWebMercator, ManyPointModel, State, Track
+from .models import (
+ City,
+ Country,
+ CountryWebMercator,
+ Feature,
+ ManyPointModel,
+ State,
+ Track,
+)
class GISFunctionsTests(FuncTestMixin, TestCase):
@@ -880,3 +897,48 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
City.objects.annotate(union=functions.GeoFunc(1, "point")).get(
name="Dallas"
)
+
+ @skipUnlessDBFeature("has_GeometryType_function")
+ def test_geometry_type(self):
+ Feature.objects.bulk_create(
+ [
+ Feature(name="Point", geom=Point(0, 0)),
+ Feature(name="LineString", geom=LineString((0, 0), (1, 1))),
+ Feature(name="Polygon", geom=Polygon(((0, 0), (1, 0), (1, 1), (0, 0)))),
+ Feature(name="MultiPoint", geom=MultiPoint(Point(0, 0), Point(1, 1))),
+ Feature(
+ name="MultiLineString",
+ geom=MultiLineString(
+ LineString((0, 0), (1, 1)), LineString((1, 1), (2, 2))
+ ),
+ ),
+ Feature(
+ name="MultiPolygon",
+ geom=MultiPolygon(
+ Polygon(((0, 0), (1, 0), (1, 1), (0, 0))),
+ Polygon(((1, 1), (2, 1), (2, 2), (1, 1))),
+ ),
+ ),
+ ]
+ )
+
+ expected_results = {
+ ("POINT", Point),
+ ("LINESTRING", LineString),
+ ("POLYGON", Polygon),
+ ("MULTIPOINT", MultiPoint),
+ ("MULTILINESTRING", MultiLineString),
+ ("MULTIPOLYGON", MultiPolygon),
+ }
+
+ for geom_type, geom_class in expected_results:
+ with self.subTest(geom_type=geom_type):
+ obj = (
+ Feature.objects.annotate(
+ geometry_type=functions.GeometryType("geom")
+ )
+ .filter(geom__geom_type=geom_type)
+ .get()
+ )
+ self.assertIsInstance(obj.geom, geom_class)
+ self.assertEqual(obj.geometry_type, geom_type)