Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16231 -- Added support for GML and KML on the SpatiaLite backe…

…nd. Thanks, steko for the bug report and jpaulett for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16800 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 28cb5bf1622cd8fa6f324cc516974e3badc31a51 1 parent 83484cc
Justin Bronn authored September 11, 2011
1  AUTHORS
@@ -393,6 +393,7 @@ answer newbie questions, and generally made Django that much better:
393 393
     Jay Parlar <parlar@gmail.com>
394 394
     Claude Paroz <claude@2xlibre.net>
395 395
     Carlos Eduardo de Paula <carlosedp@gmail.com>
  396
+    John Paulett <john@paulett.org>
396 397
     pavithran s <pavithran.s@gmail.com>
397 398
     Barry Pederson <bp@barryp.org>
398 399
     Andreas Pelme <andreas@pelme.se>
12  django/contrib/gis/db/backends/spatialite/operations.py
@@ -133,6 +133,18 @@ def __init__(self, connection):
133 133
         gis_terms += self.geometry_functions.keys()
134 134
         self.gis_terms = dict([(term, None) for term in gis_terms])
135 135
 
  136
+        if version >= (2, 4, 0):
  137
+            # Spatialite 2.4.0-RC4 added AsGML and AsKML, however both
  138
+            # RC2 (shipped in popular Debian/Ubuntu packages) and RC4
  139
+            # report version as '2.4.0', so we fall back to feature detection
  140
+            try:
  141
+                self._get_spatialite_func("AsGML(GeomFromText('POINT(1 1)'))")
  142
+                self.gml = 'AsGML'
  143
+                self.kml = 'AsKML'
  144
+            except DatabaseError:
  145
+                # we are using < 2.4.0-RC4
  146
+                pass
  147
+
136 148
     def check_aggregate_support(self, aggregate):
137 149
         """
138 150
         Checks if the given aggregate name is supported (that is, if it's
18  django/contrib/gis/tests/geoapp/tests.py
... ...
@@ -1,5 +1,6 @@
1 1
 import re
2 2
 from django.db import connection
  3
+from django.db.utils import DatabaseError
3 4
 from django.contrib.gis import gdal
4 5
 from django.contrib.gis.geos import (fromstr, GEOSGeometry,
5 6
     Point, LineString, LinearRing, Polygon, GeometryCollection)
@@ -92,8 +93,8 @@ def test02_proxy(self):
92 93
 
93 94
     def test03a_kml(self):
94 95
         "Testing KML output from the database using GeoQuerySet.kml()."
95  
-        # Only PostGIS supports KML serialization
96  
-        if not postgis:
  96
+        # Only PostGIS and Spatialite (>=2.4.0-RC4) support KML serialization
  97
+        if not (postgis or (spatialite and connection.ops.kml)):
97 98
             self.assertRaises(NotImplementedError, State.objects.all().kml, field_name='poly')
98 99
             return
99 100
 
@@ -117,7 +118,7 @@ def test03a_kml(self):
117 118
 
118 119
     def test03b_gml(self):
119 120
         "Testing GML output from the database using GeoQuerySet.gml()."
120  
-        if mysql or spatialite:
  121
+        if mysql or (spatialite and not connection.ops.gml) :
121 122
             self.assertRaises(NotImplementedError, Country.objects.all().gml, field_name='mpoly')
122 123
             return
123 124
 
@@ -131,12 +132,15 @@ def test03b_gml(self):
131 132
         if oracle:
132 133
             # No precision parameter for Oracle :-/
133 134
             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>')
134  
-            for ptown in [ptown1, ptown2]:
135  
-                self.assertTrue(gml_regex.match(ptown.gml))
  135
+        elif spatialite:
  136
+            # Spatialite has extra colon in SrsName
  137
+            gml_regex = re.compile(r'^<gml:Point SrsName="EPSG::4326"><gml:coordinates decimal="\." cs="," ts=" ">-104.609251\d+,38.255001</gml:coordinates></gml:Point>')
136 138
         else:
137 139
             gml_regex = re.compile(r'^<gml:Point srsName="EPSG:4326"><gml:coordinates>-104\.60925\d+,38\.255001</gml:coordinates></gml:Point>')
138  
-            for ptown in [ptown1, ptown2]:
139  
-                self.assertTrue(gml_regex.match(ptown.gml))
  140
+
  141
+        for ptown in [ptown1, ptown2]:
  142
+            self.assertTrue(gml_regex.match(ptown.gml))
  143
+
140 144
 
141 145
     def test03c_geojson(self):
142 146
         "Testing GeoJSON output from the database using GeoQuerySet.geojson()."
4  docs/ref/contrib/gis/db-api.txt
@@ -287,9 +287,9 @@ Method                                PostGIS  Oracle  SpatiaLite
287 287
 :meth:`GeoQuerySet.force_rhr`         X
288 288
 :meth:`GeoQuerySet.geohash`           X
289 289
 :meth:`GeoQuerySet.geojson`           X
290  
-:meth:`GeoQuerySet.gml`               X        X
  290
+:meth:`GeoQuerySet.gml`               X        X       X
291 291
 :meth:`GeoQuerySet.intersection`      X        X       X
292  
-:meth:`GeoQuerySet.kml`               X
  292
+:meth:`GeoQuerySet.kml`               X                X
293 293
 :meth:`GeoQuerySet.length`            X        X       X
294 294
 :meth:`GeoQuerySet.make_line`         X
295 295
 :meth:`GeoQuerySet.mem_size`          X
4  docs/ref/contrib/gis/geoquerysets.txt
@@ -982,7 +982,7 @@ __ http://geojson.org/
982 982
 
983 983
 .. method:: GeoQuerySet.gml(**kwargs)
984 984
 
985  
-*Availability*: PostGIS, Oracle
  985
+*Availability*: PostGIS, Oracle, SpatiaLite
986 986
 
987 987
 Attaches a ``gml`` attribute to every model in the queryset that contains the
988 988
 `Geographic Markup Language (GML)`__ representation of the geometry.
@@ -1013,7 +1013,7 @@ __ http://en.wikipedia.org/wiki/Geography_Markup_Language
1013 1013
 
1014 1014
 .. method:: GeoQuerySet.kml(**kwargs)
1015 1015
 
1016  
-*Availability*: PostGIS
  1016
+*Availability*: PostGIS, SpatiaLite
1017 1017
 
1018 1018
 Attaches a ``kml`` attribute to every model in the queryset that contains the
1019 1019
 `Keyhole Markup Language (KML)`__ representation of the geometry fields. It

0 notes on commit 28cb5bf

Please sign in to comment.
Something went wrong with that request. Please try again.