Author: jbronn
Date: 2011-09-10 17:52:08 -0700 (Sat, 10 Sep 2011)
New Revision: 16800

Modified:
   django/trunk/AUTHORS
   django/trunk/django/contrib/gis/db/backends/spatialite/operations.py
   django/trunk/django/contrib/gis/tests/geoapp/tests.py
   django/trunk/docs/ref/contrib/gis/db-api.txt
   django/trunk/docs/ref/contrib/gis/geoquerysets.txt
Log:
Fixed #16231 -- Added support for GML and KML on the SpatiaLite backend.  
Thanks, steko for the bug report and jpaulett for the patch.

Modified: django/trunk/AUTHORS
===================================================================
--- django/trunk/AUTHORS        2011-09-11 00:52:03 UTC (rev 16799)
+++ django/trunk/AUTHORS        2011-09-11 00:52:08 UTC (rev 16800)
@@ -393,6 +393,7 @@
     Jay Parlar <[email protected]>
     Claude Paroz <[email protected]>
     Carlos Eduardo de Paula <[email protected]>
+    John Paulett <[email protected]>
     pavithran s <[email protected]>
     Barry Pederson <[email protected]>
     Andreas Pelme <[email protected]>

Modified: django/trunk/django/contrib/gis/db/backends/spatialite/operations.py
===================================================================
--- django/trunk/django/contrib/gis/db/backends/spatialite/operations.py        
2011-09-11 00:52:03 UTC (rev 16799)
+++ django/trunk/django/contrib/gis/db/backends/spatialite/operations.py        
2011-09-11 00:52:08 UTC (rev 16800)
@@ -133,6 +133,18 @@
         gis_terms += self.geometry_functions.keys()
         self.gis_terms = dict([(term, None) for term in gis_terms])
 
+        if version >= (2, 4, 0):
+            # Spatialite 2.4.0-RC4 added AsGML and AsKML, however both
+            # RC2 (shipped in popular Debian/Ubuntu packages) and RC4
+            # report version as '2.4.0', so we fall back to feature detection
+            try:
+                self._get_spatialite_func("AsGML(GeomFromText('POINT(1 1)'))")
+                self.gml = 'AsGML'
+                self.kml = 'AsKML'
+            except DatabaseError:
+                # we are using < 2.4.0-RC4
+                pass
+
     def check_aggregate_support(self, aggregate):
         """
         Checks if the given aggregate name is supported (that is, if it's

Modified: django/trunk/django/contrib/gis/tests/geoapp/tests.py
===================================================================
--- django/trunk/django/contrib/gis/tests/geoapp/tests.py       2011-09-11 
00:52:03 UTC (rev 16799)
+++ django/trunk/django/contrib/gis/tests/geoapp/tests.py       2011-09-11 
00:52:08 UTC (rev 16800)
@@ -1,5 +1,6 @@
 import re
 from django.db import connection
+from django.db.utils import DatabaseError
 from django.contrib.gis import gdal
 from django.contrib.gis.geos import (fromstr, GEOSGeometry,
     Point, LineString, LinearRing, Polygon, GeometryCollection)
@@ -92,8 +93,8 @@
 
     def test03a_kml(self):
         "Testing KML output from the database using GeoQuerySet.kml()."
-        # Only PostGIS supports KML serialization
-        if not postgis:
+        # Only PostGIS and Spatialite (>=2.4.0-RC4) support KML serialization
+        if not (postgis or (spatialite and connection.ops.kml)):
             self.assertRaises(NotImplementedError, State.objects.all().kml, 
field_name='poly')
             return
 
@@ -117,7 +118,7 @@
 
     def test03b_gml(self):
         "Testing GML output from the database using GeoQuerySet.gml()."
-        if mysql or spatialite:
+        if mysql or (spatialite and not connection.ops.gml) :
             self.assertRaises(NotImplementedError, Country.objects.all().gml, 
field_name='mpoly')
             return
 
@@ -131,13 +132,16 @@
         if oracle:
             # No precision parameter for Oracle :-/
             gml_regex = re.compile(r'^<gml:Point srsName="SDO:4326" 
xmlns:gml="http://www.opengis.net/gml";><gml:coordinates decimal="\." cs="," 
ts=" ">-104.60925\d+,38.25500\d+ </gml:coordinates></gml:Point>')
-            for ptown in [ptown1, ptown2]:
-                self.assertTrue(gml_regex.match(ptown.gml))
+        elif spatialite:
+            # Spatialite has extra colon in SrsName
+            gml_regex = re.compile(r'^<gml:Point 
SrsName="EPSG::4326"><gml:coordinates decimal="\." cs="," ts=" 
">-104.609251\d+,38.255001</gml:coordinates></gml:Point>')
         else:
             gml_regex = re.compile(r'^<gml:Point 
srsName="EPSG:4326"><gml:coordinates>-104\.60925\d+,38\.255001</gml:coordinates></gml:Point>')
-            for ptown in [ptown1, ptown2]:
-                self.assertTrue(gml_regex.match(ptown.gml))
 
+        for ptown in [ptown1, ptown2]:
+            self.assertTrue(gml_regex.match(ptown.gml))
+
+
     def test03c_geojson(self):
         "Testing GeoJSON output from the database using GeoQuerySet.geojson()."
         # Only PostGIS 1.3.4+ supports GeoJSON.

Modified: django/trunk/docs/ref/contrib/gis/db-api.txt
===================================================================
--- django/trunk/docs/ref/contrib/gis/db-api.txt        2011-09-11 00:52:03 UTC 
(rev 16799)
+++ django/trunk/docs/ref/contrib/gis/db-api.txt        2011-09-11 00:52:08 UTC 
(rev 16800)
@@ -287,9 +287,9 @@
 :meth:`GeoQuerySet.force_rhr`         X
 :meth:`GeoQuerySet.geohash`           X
 :meth:`GeoQuerySet.geojson`           X
-:meth:`GeoQuerySet.gml`               X        X
+:meth:`GeoQuerySet.gml`               X        X       X
 :meth:`GeoQuerySet.intersection`      X        X       X
-:meth:`GeoQuerySet.kml`               X
+:meth:`GeoQuerySet.kml`               X                X
 :meth:`GeoQuerySet.length`            X        X       X
 :meth:`GeoQuerySet.make_line`         X
 :meth:`GeoQuerySet.mem_size`          X

Modified: django/trunk/docs/ref/contrib/gis/geoquerysets.txt
===================================================================
--- django/trunk/docs/ref/contrib/gis/geoquerysets.txt  2011-09-11 00:52:03 UTC 
(rev 16799)
+++ django/trunk/docs/ref/contrib/gis/geoquerysets.txt  2011-09-11 00:52:08 UTC 
(rev 16800)
@@ -982,7 +982,7 @@
 
 .. method:: GeoQuerySet.gml(**kwargs)
 
-*Availability*: PostGIS, Oracle
+*Availability*: PostGIS, Oracle, SpatiaLite
 
 Attaches a ``gml`` attribute to every model in the queryset that contains the
 `Geographic Markup Language (GML)`__ representation of the geometry.
@@ -1013,7 +1013,7 @@
 
 .. method:: GeoQuerySet.kml(**kwargs)
 
-*Availability*: PostGIS
+*Availability*: PostGIS, SpatiaLite
 
 Attaches a ``kml`` attribute to every model in the queryset that contains the
 `Keyhole Markup Language (KML)`__ representation of the geometry fields. It

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to