diff --git django/contrib/gis/db/backends/spatialite/operations.py django/contrib/gis/db/backends/spatialite/operations.py
index 449c527..e83ff8c 100644
|
|
class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
|
133 | 133 | gis_terms += self.geometry_functions.keys() |
134 | 134 | self.gis_terms = dict([(term, None) for term in gis_terms]) |
135 | 135 | |
| 136 | |
| 137 | if version >= (2, 4, 0): |
| 138 | # Spatialite 2.4.0-RC4 added AsGML and AsKML, however both |
| 139 | # RC2 (shipped in popular Debian/Ubuntu packages) and RC4 |
| 140 | # report version as '2.4.0', so we fall back to feature detection |
| 141 | try: |
| 142 | self._get_spatialite_func("AsGML(GeomFromText('POINT(1 1)'))") |
| 143 | self.gml = 'AsGML' |
| 144 | self.kml = 'AsKML' |
| 145 | except DatabaseError: |
| 146 | # we are using < 2.4.0-RC4 |
| 147 | pass |
| 148 | |
136 | 149 | def check_aggregate_support(self, aggregate): |
137 | 150 | """ |
138 | 151 | Checks if the given aggregate name is supported (that is, if it's |
diff --git django/contrib/gis/tests/geoapp/tests.py django/contrib/gis/tests/geoapp/tests.py
index b7ce3b7..b642bdd 100644
|
|
|
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) |
6 | 7 | from django.contrib.gis.tests.utils import ( |
7 | | no_mysql, no_oracle, no_spatialite, |
| 8 | no_mysql, no_oracle, no_postgis, no_spatialite, |
8 | 9 | mysql, oracle, postgis, spatialite) |
9 | 10 | from django.test import TestCase |
10 | 11 | |
… |
… |
class GeoModelTest(TestCase):
|
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 | |
… |
… |
class GeoModelTest(TestCase):
|
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 | |
… |
… |
class GeoModelTest(TestCase):
|
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()." |
… |
… |
class GeoModelTest(TestCase):
|
729 | 733 | self.assertEqual(ref_hash, h1.geohash) |
730 | 734 | self.assertEqual(ref_hash[:5], h2.geohash) |
731 | 735 | |
| 736 | @no_mysql |
| 737 | @no_oracle |
| 738 | @no_postgis |
| 739 | def test30_spatialite_gml_and_kml(self): |
| 740 | # ensure kml and gml exist for spatialite >= 2.4.0-RC4 |
| 741 | def supports_gml(): |
| 742 | try: |
| 743 | connection.ops. _get_spatialite_func("AsGML(GeomFromText('POINT(1 1)'))") |
| 744 | return True |
| 745 | except DatabaseError: |
| 746 | return False |
| 747 | |
| 748 | if connection.ops.spatial_version >= (2, 4, 0) and supports_gml(): |
| 749 | self.assertTrue(connection.ops.gml) |
| 750 | self.assertTrue(connection.ops.kml) |
| 751 | else: |
| 752 | self.assertFalse(connection.ops.gml) |
| 753 | self.assertFalse(connection.ops.kml) |
| 754 | |
| 755 | |
732 | 756 | from test_feeds import GeoFeedTest |
733 | 757 | from test_regress import GeoRegressionTests |
734 | 758 | from test_sitemaps import GeoSitemapTest |
diff --git docs/ref/contrib/gis/db-api.txt docs/ref/contrib/gis/db-api.txt
index fbced8e..871defe 100644
|
|
Method PostGIS Oracle SpatiaLite
|
311 | 311 | :meth:`GeoQuerySet.force_rhr` X |
312 | 312 | :meth:`GeoQuerySet.geohash` X |
313 | 313 | :meth:`GeoQuerySet.geojson` X |
314 | | :meth:`GeoQuerySet.gml` X X |
| 314 | :meth:`GeoQuerySet.gml` X X X |
315 | 315 | :meth:`GeoQuerySet.intersection` X X X |
316 | | :meth:`GeoQuerySet.kml` X |
| 316 | :meth:`GeoQuerySet.kml` X X |
317 | 317 | :meth:`GeoQuerySet.length` X X X |
318 | 318 | :meth:`GeoQuerySet.make_line` X |
319 | 319 | :meth:`GeoQuerySet.mem_size` X |