summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2016-12-16 01:00:08 +0600
committerTim Graham <timograham@gmail.com>2016-12-15 14:00:08 -0500
commit5a23cc00f535a045db6d9c04c3c14594ee23fbec (patch)
treec46bf08855a9d039ed316a21ae774661fbd49c54
parentd2a26c1a90e837777dabdf3d67ceec4d2a70fb86 (diff)
Fixed #27607 -- Added Oracle support for AsGML GIS function.
-rw-r--r--django/contrib/gis/db/backends/oracle/operations.py3
-rw-r--r--django/contrib/gis/db/models/functions.py12
-rw-r--r--docs/ref/contrib/gis/db-api.txt2
-rw-r--r--docs/ref/contrib/gis/functions.txt8
-rw-r--r--docs/releases/1.11.txt3
-rw-r--r--tests/gis_tests/geoapp/test_functions.py15
6 files changed, 26 insertions, 17 deletions
diff --git a/django/contrib/gis/db/backends/oracle/operations.py b/django/contrib/gis/db/backends/oracle/operations.py
index b4b04622c6..0680a8d0af 100644
--- a/django/contrib/gis/db/backends/oracle/operations.py
+++ b/django/contrib/gis/db/backends/oracle/operations.py
@@ -132,8 +132,7 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations):
truncate_params = {'relate': None}
unsupported_functions = {
- 'AsGeoJSON', 'AsGML', 'AsKML', 'AsSVG',
- 'BoundingCircle', 'Envelope',
+ 'AsGeoJSON', 'AsKML', 'AsSVG', 'BoundingCircle', 'Envelope',
'ForceRHR', 'GeoHash', 'MakeValid', 'MemSize', 'Scale',
'SnapToGrid', 'Translate',
}
diff --git a/django/contrib/gis/db/models/functions.py b/django/contrib/gis/db/models/functions.py
index 2301a50230..b404397f95 100644
--- a/django/contrib/gis/db/models/functions.py
+++ b/django/contrib/gis/db/models/functions.py
@@ -38,12 +38,12 @@ class GeoFunc(Func):
except (AttributeError, FieldError):
return None
- def as_sql(self, compiler, connection):
+ def as_sql(self, compiler, connection, **extra_context):
if self.function is None:
self.function = connection.ops.spatial_function_name(self.name)
if any(isinstance(field, RasterField) for field in self.get_source_fields()):
raise TypeError("Geometry functions not supported for raster fields.")
- return super(GeoFunc, self).as_sql(compiler, connection)
+ return super(GeoFunc, self).as_sql(compiler, connection, **extra_context)
def resolve_expression(self, *args, **kwargs):
res = super(GeoFunc, self).resolve_expression(*args, **kwargs)
@@ -172,6 +172,14 @@ class AsGML(GeoFunc):
expressions.append(self._handle_param(precision, 'precision', six.integer_types))
super(AsGML, self).__init__(*expressions, **extra)
+ def as_oracle(self, compiler, connection, **extra_context):
+ source_expressions = self.get_source_expressions()
+ version = source_expressions[0]
+ clone = self.copy()
+ clone.set_source_expressions([source_expressions[1]])
+ extra_context['function'] = 'SDO_UTIL.TO_GML311GEOMETRY' if version.value == 3 else 'SDO_UTIL.TO_GMLGEOMETRY'
+ return super(AsGML, clone).as_sql(compiler, connection, **extra_context)
+
class AsKML(AsGML):
def as_sqlite(self, compiler, connection):
diff --git a/docs/ref/contrib/gis/db-api.txt b/docs/ref/contrib/gis/db-api.txt
index ad375dca46..670b23cd78 100644
--- a/docs/ref/contrib/gis/db-api.txt
+++ b/docs/ref/contrib/gis/db-api.txt
@@ -379,7 +379,7 @@ Function PostGIS Oracle MySQL SpatiaLite
==================================== ======= ====== =========== ==========
:class:`Area` X X X X
:class:`AsGeoJSON` X X
-:class:`AsGML` X X
+:class:`AsGML` X X X
:class:`AsKML` X X
:class:`AsSVG` X X
:class:`BoundingCircle` X
diff --git a/docs/ref/contrib/gis/functions.txt b/docs/ref/contrib/gis/functions.txt
index 456ffb83e7..3a731c96f9 100644
--- a/docs/ref/contrib/gis/functions.txt
+++ b/docs/ref/contrib/gis/functions.txt
@@ -81,7 +81,7 @@ Keyword Argument Description
.. class:: AsGML(expression, version=2, precision=8, **extra)
-*Availability*: PostGIS, SpatiaLite
+*Availability*: Oracle, PostGIS, SpatiaLite
Accepts a single geographic field or expression and returns a `Geographic Markup
Language (GML)`__ representation of the geometry.
@@ -98,13 +98,17 @@ Keyword Argument Description
===================== =====================================================
``precision`` Specifies the number of significant digits for the
coordinates in the GML representation -- the default
- value is 8.
+ value is 8. Ignored on Oracle.
``version`` Specifies the GML version to use: 2 (default) or 3.
===================== =====================================================
__ https://en.wikipedia.org/wiki/Geography_Markup_Language
+.. versionchanged:: 1.11
+
+ Oracle support was added.
+
``AsKML``
=========
diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt
index a46edbdfb9..40467eca88 100644
--- a/docs/releases/1.11.txt
+++ b/docs/releases/1.11.txt
@@ -164,7 +164,8 @@ Minor features
:lookup:`isvalid` lookup.
* Added Oracle support for the
- :class:`~django.contrib.gis.db.models.functions.IsValid` function and
+ :class:`~django.contrib.gis.db.models.functions.AsGML` function,
+ :class:`~django.contrib.gis.db.models.functions.IsValid` function, and
:lookup:`isvalid` lookup.
:mod:`django.contrib.messages`
diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py
index 3ce72b9d21..7b6281a4b9 100644
--- a/tests/gis_tests/geoapp/test_functions.py
+++ b/tests/gis_tests/geoapp/test_functions.py
@@ -11,7 +11,7 @@ from django.db.models import Sum
from django.test import TestCase, skipUnlessDBFeature
from django.utils import six
-from ..utils import mysql, oracle, postgis, spatialite
+from ..utils import mysql, oracle, spatialite
from .models import City, Country, CountryWebMercator, State, Track
@@ -104,7 +104,7 @@ class GISFunctionsTests(TestCase):
if oracle:
# No precision parameter for Oracle :-/
gml_regex = re.compile(
- r'^<gml:Point srsName="SDO:4326" xmlns:gml="http://www.opengis.net/gml">'
+ r'^<gml:Point srsName="EPSG:4326" xmlns:gml="http://www.opengis.net/gml">'
r'<gml:coordinates decimal="\." cs="," ts=" ">-104.60925\d+,38.25500\d+ '
r'</gml:coordinates></gml:Point>'
)
@@ -113,14 +113,11 @@ class GISFunctionsTests(TestCase):
r'^<gml:Point srsName="EPSG:4326"><gml:coordinates>'
r'-104\.60925\d+,38\.255001</gml:coordinates></gml:Point>'
)
-
self.assertTrue(gml_regex.match(ptown.gml))
-
- if postgis:
- self.assertIn(
- '<gml:pos srsDimension="2">',
- City.objects.annotate(gml=functions.AsGML('point', version=3)).get(name='Pueblo').gml
- )
+ self.assertIn(
+ '<gml:pos srsDimension="2">',
+ City.objects.annotate(gml=functions.AsGML('point', version=3)).get(name='Pueblo').gml
+ )
@skipUnlessDBFeature("has_AsKML_function")
def test_askml(self):