Ticket #16231: spatialite-kml-gml.4.diff

File spatialite-kml-gml.4.diff, 5.5 KB (added by jpaulett, 4 years ago)

Feature detection of AsGML to detect 2.4.0 RC2 vs RC4

  • django/contrib/gis/db/backends/spatialite/operations.py

    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): 
    133133        gis_terms += self.geometry_functions.keys()
    134134        self.gis_terms = dict([(term, None) for term in gis_terms])
    135135
     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
    136149    def check_aggregate_support(self, aggregate):
    137150        """
    138151        Checks if the given aggregate name is supported (that is, if it's
  • django/contrib/gis/tests/geoapp/tests.py

    diff --git django/contrib/gis/tests/geoapp/tests.py django/contrib/gis/tests/geoapp/tests.py
    index b7ce3b7..b642bdd 100644
     
    11import re
    22from django.db import connection
     3from django.db.utils import DatabaseError
    34from django.contrib.gis import gdal
    45from django.contrib.gis.geos import (fromstr, GEOSGeometry,
    56    Point, LineString, LinearRing, Polygon, GeometryCollection)
    67from django.contrib.gis.tests.utils import (
    7     no_mysql, no_oracle, no_spatialite,
     8    no_mysql, no_oracle, no_postgis, no_spatialite,
    89    mysql, oracle, postgis, spatialite)
    910from django.test import TestCase
    1011
    class GeoModelTest(TestCase): 
    9293
    9394    def test03a_kml(self):
    9495        "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)):
    9798            self.assertRaises(NotImplementedError, State.objects.all().kml, field_name='poly')
    9899            return
    99100
    class GeoModelTest(TestCase): 
    117118
    118119    def test03b_gml(self):
    119120        "Testing GML output from the database using GeoQuerySet.gml()."
    120         if mysql or spatialite:
     121        if mysql or (spatialite and not connection.ops.gml) :
    121122            self.assertRaises(NotImplementedError, Country.objects.all().gml, field_name='mpoly')
    122123            return
    123124
    class GeoModelTest(TestCase): 
    131132        if oracle:
    132133            # No precision parameter for Oracle :-/
    133134            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>')
    136138        else:
    137139            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
    140144
    141145    def test03c_geojson(self):
    142146        "Testing GeoJSON output from the database using GeoQuerySet.geojson()."
    class GeoModelTest(TestCase): 
    729733        self.assertEqual(ref_hash, h1.geohash)
    730734        self.assertEqual(ref_hash[:5], h2.geohash)
    731735
     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
    732756from test_feeds import GeoFeedTest
    733757from test_regress import GeoRegressionTests
    734758from test_sitemaps import GeoSitemapTest
  • docs/ref/contrib/gis/db-api.txt

    diff --git docs/ref/contrib/gis/db-api.txt docs/ref/contrib/gis/db-api.txt
    index fbced8e..871defe 100644
    Method PostGIS Oracle SpatiaLite 
    311311:meth:`GeoQuerySet.force_rhr`         X
    312312:meth:`GeoQuerySet.geohash`           X
    313313:meth:`GeoQuerySet.geojson`           X
    314 :meth:`GeoQuerySet.gml`               X        X
     314:meth:`GeoQuerySet.gml`               X        X       X
    315315:meth:`GeoQuerySet.intersection`      X        X       X
    316 :meth:`GeoQuerySet.kml`               X
     316:meth:`GeoQuerySet.kml`               X                X
    317317:meth:`GeoQuerySet.length`            X        X       X
    318318:meth:`GeoQuerySet.make_line`         X
    319319:meth:`GeoQuerySet.mem_size`          X
Back to Top