<s> from __future__ import unicode_literals <EOL> import re <EOL> from decimal import Decimal <EOL> from django . contrib . gis . db . models import functions <EOL> from django . contrib . gis . geos import LineString , Point , Polygon , fromstr <EOL> from django . contrib . gis . measure import Area <EOL> from django . db import connection <EOL> from django . db . models import Sum <EOL> from django . test import TestCase , skipUnlessDBFeature <EOL> from django . utils import six <EOL> from . . utils import mysql , oracle , postgis , spatialite <EOL> from . models import City , Country , CountryWebMercator , State , Track <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> class GISFunctionsTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_asgeojson ( self ) : <EOL> if not connection . ops . geojson : <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> list ( Country . objects . annotate ( json = functions . AsGeoJSON ( '<STR_LIT>' ) ) ) <EOL> return <EOL> pueblo_json = '<STR_LIT>' <EOL> houston_json = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> victoria_json = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> chicago_json = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> if spatialite : <EOL> victoria_json = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> with self . assertRaises ( TypeError ) : <EOL> City . objects . annotate ( geojson = functions . AsGeoJSON ( '<STR_LIT>' , precision = '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( <EOL> pueblo_json , <EOL> City . objects . annotate ( geojson = functions . AsGeoJSON ( '<STR_LIT>' ) ) . get ( name = '<STR_LIT>' ) . geojson <EOL> ) <EOL> self . assertEqual ( <EOL> houston_json , <EOL> City . objects . annotate ( json = functions . AsGeoJSON ( '<STR_LIT>' , crs = True ) ) . get ( name = '<STR_LIT>' ) . json <EOL> ) <EOL> self . assertEqual ( <EOL> victoria_json , <EOL> City . objects . annotate ( <EOL> geojson = functions . AsGeoJSON ( '<STR_LIT>' , bbox = True ) <EOL> ) . get ( name = '<STR_LIT>' ) . geojson <EOL> ) <EOL> self . assertEqual ( <EOL> chicago_json , <EOL> City . objects . annotate ( <EOL> geojson = functions . AsGeoJSON ( '<STR_LIT>' , bbox = True , crs = True , precision = <NUM_LIT:5> ) <EOL> ) . get ( name = '<STR_LIT>' ) . geojson <EOL> ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_asgml ( self ) : <EOL> qs = City . objects . all ( ) <EOL> with self . assertRaises ( TypeError ) : <EOL> qs . annotate ( gml = functions . AsGML ( '<STR_LIT:name>' ) ) <EOL> ptown = City . objects . annotate ( gml = functions . AsGML ( '<STR_LIT>' , precision = <NUM_LIT:9> ) ) . get ( name = '<STR_LIT>' ) <EOL> if oracle : <EOL> gml_regex = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> ) <EOL> else : <EOL> gml_regex = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> ) <EOL> self . assertTrue ( gml_regex . match ( ptown . gml ) ) <EOL> if postgis : <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> City . objects . annotate ( gml = functions . AsGML ( '<STR_LIT>' , version = <NUM_LIT:3> ) ) . get ( name = '<STR_LIT>' ) . gml <EOL> ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_askml ( self ) : <EOL> with self . assertRaises ( TypeError ) : <EOL> City . objects . annotate ( kml = functions . AsKML ( '<STR_LIT:name>' ) ) <EOL> ptown = City . objects . annotate ( kml = functions . AsKML ( '<STR_LIT>' , precision = <NUM_LIT:9> ) ) . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ptown . kml ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_assvg ( self ) : <EOL> with self . assertRaises ( TypeError ) : <EOL> City . objects . annotate ( svg = functions . AsSVG ( '<STR_LIT>' , precision = '<STR_LIT:foo>' ) ) <EOL> svg1 = '<STR_LIT>' <EOL> svg2 = svg1 . replace ( '<STR_LIT:c>' , '<STR_LIT>' ) <EOL> self . assertEqual ( svg1 , City . objects . annotate ( svg = functions . AsSVG ( '<STR_LIT>' ) ) . get ( name = '<STR_LIT>' ) . svg ) <EOL> self . assertEqual ( svg2 , City . objects . annotate ( svg = functions . AsSVG ( '<STR_LIT>' , relative = <NUM_LIT:5> ) ) . get ( name = '<STR_LIT>' ) . svg ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_bounding_circle ( self ) : <EOL> qs = Country . objects . annotate ( circle = functions . BoundingCircle ( '<STR_LIT>' ) ) . order_by ( '<STR_LIT:name>' ) <EOL> self . assertAlmostEqual ( qs [ <NUM_LIT:0> ] . circle . area , <NUM_LIT> , <NUM_LIT:2> ) <EOL> self . assertAlmostEqual ( qs [ <NUM_LIT:1> ] . circle . area , <NUM_LIT> , <NUM_LIT:2> ) <EOL> qs = Country . objects . annotate ( circle = functions . BoundingCircle ( '<STR_LIT>' , num_seg = <NUM_LIT:12> ) ) . order_by ( '<STR_LIT:name>' ) <EOL> self . assertAlmostEqual ( qs [ <NUM_LIT:0> ] . circle . area , <NUM_LIT> , <NUM_LIT:2> ) <EOL> self . assertAlmostEqual ( qs [ <NUM_LIT:1> ] . circle . area , <NUM_LIT> , <NUM_LIT:2> ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_centroid ( self ) : <EOL> qs = State . objects . exclude ( poly__isnull = True ) . annotate ( centroid = functions . Centroid ( '<STR_LIT>' ) ) <EOL> tol = <NUM_LIT> if mysql else ( <NUM_LIT:0.1> if oracle else <NUM_LIT> ) <EOL> for state in qs : <EOL> self . assertTrue ( state . poly . centroid . equals_exact ( state . centroid , tol ) ) <EOL> with self . assertRaisesMessage ( TypeError , "<STR_LIT>" ) : <EOL> State . objects . annotate ( centroid = functions . Centroid ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_difference ( self ) : <EOL> geom = Point ( <NUM_LIT:5> , <NUM_LIT> , srid = <NUM_LIT> ) <EOL> qs = Country . objects . annotate ( diff = functions . Difference ( '<STR_LIT>' , geom ) ) <EOL> if spatialite or oracle : <EOL> qs = qs . exclude ( name = '<STR_LIT>' ) <EOL> for c in qs : <EOL> self . assertTrue ( c . mpoly . difference ( geom ) . equals ( c . diff ) ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_difference_mixed_srid ( self ) : <EOL> """<STR_LIT>""" <EOL> geom = Point ( <NUM_LIT> , <NUM_LIT> , srid = <NUM_LIT> ) <EOL> qs = Country . objects . annotate ( difference = functions . Difference ( '<STR_LIT>' , geom ) ) <EOL> if spatialite or oracle : <EOL> qs = qs . exclude ( name = '<STR_LIT>' ) <EOL> for c in qs : <EOL> self . assertTrue ( c . mpoly . difference ( geom ) . equals ( c . difference ) ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_envelope ( self ) : <EOL> countries = Country . objects . annotate ( envelope = functions . Envelope ( '<STR_LIT>' ) ) <EOL> for country in countries : <EOL> self . assertIsInstance ( country . envelope , Polygon ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_force_rhr ( self ) : <EOL> rings = ( <EOL> ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) , <EOL> ( ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:3> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) , <EOL> ) <EOL> rhr_rings = ( <EOL> ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) , <EOL> ( ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:3> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) , <EOL> ) <EOL> State . objects . create ( name = '<STR_LIT>' , poly = Polygon ( * rings ) ) <EOL> st = State . objects . annotate ( force_rhr = functions . ForceRHR ( '<STR_LIT>' ) ) . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( rhr_rings , st . force_rhr . coords ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_geohash ( self ) : <EOL> ref_hash = '<STR_LIT>' <EOL> h1 = City . objects . annotate ( geohash = functions . GeoHash ( '<STR_LIT>' ) ) . get ( name = '<STR_LIT>' ) <EOL> h2 = City . objects . annotate ( geohash = functions . GeoHash ( '<STR_LIT>' , precision = <NUM_LIT:5> ) ) . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( ref_hash , h1 . geohash ) <EOL> self . assertEqual ( ref_hash [ : <NUM_LIT:5> ] , h2 . geohash ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_intersection ( self ) : <EOL> geom = Point ( <NUM_LIT:5> , <NUM_LIT> , srid = <NUM_LIT> ) <EOL> qs = Country . objects . annotate ( inter = functions . Intersection ( '<STR_LIT>' , geom ) ) <EOL> for c in qs : <EOL> if spatialite or mysql : <EOL> expected = None <EOL> elif oracle : <EOL> expected = '<STR_LIT>' <EOL> else : <EOL> expected = c . mpoly . intersection ( geom ) <EOL> self . assertEqual ( c . inter , expected ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_isvalid ( self ) : <EOL> valid_geom = fromstr ( '<STR_LIT>' ) <EOL> invalid_geom = fromstr ( '<STR_LIT>' ) <EOL> State . objects . create ( name = '<STR_LIT>' , poly = valid_geom ) <EOL> State . objects . create ( name = '<STR_LIT>' , poly = invalid_geom ) <EOL> valid = State . objects . filter ( name = '<STR_LIT>' ) . annotate ( isvalid = functions . IsValid ( '<STR_LIT>' ) ) . first ( ) <EOL> invalid = State . objects . filter ( name = '<STR_LIT>' ) . annotate ( isvalid = functions . IsValid ( '<STR_LIT>' ) ) . first ( ) <EOL> self . assertEqual ( valid . isvalid , True ) <EOL> self . assertEqual ( invalid . isvalid , False ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_area_with_regular_aggregate ( self ) : <EOL> for c in Country . objects . all ( ) : <EOL> CountryWebMercator . objects . create ( name = c . name , mpoly = c . mpoly ) <EOL> qs = CountryWebMercator . objects . annotate ( area_sum = Sum ( functions . Area ( '<STR_LIT>' ) ) ) <EOL> for c in qs . defer ( '<STR_LIT>' ) : <EOL> result = c . area_sum <EOL> if isinstance ( result , Area ) : <EOL> result = result . sq_m <EOL> self . assertAlmostEqual ( ( result - c . mpoly . area ) / c . mpoly . area , <NUM_LIT:0> ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_make_valid ( self ) : <EOL> invalid_geom = fromstr ( '<STR_LIT>' ) <EOL> State . objects . create ( name = '<STR_LIT>' , poly = invalid_geom ) <EOL> invalid = State . objects . filter ( name = '<STR_LIT>' ) . annotate ( repaired = functions . MakeValid ( '<STR_LIT>' ) ) . first ( ) <EOL> self . assertEqual ( invalid . repaired . valid , True ) <EOL> self . assertEqual ( invalid . repaired , fromstr ( '<STR_LIT>' ) ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_memsize ( self ) : <EOL> ptown = City . objects . annotate ( size = functions . MemSize ( '<STR_LIT>' ) ) . get ( name = '<STR_LIT>' ) <EOL> self . assertTrue ( <NUM_LIT:20> <= ptown . size <= <NUM_LIT> ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_num_geom ( self ) : <EOL> for c in Country . objects . annotate ( num_geom = functions . NumGeometries ( '<STR_LIT>' ) ) : <EOL> self . assertEqual ( <NUM_LIT:2> , c . num_geom ) <EOL> qs = City . objects . filter ( point__isnull = False ) . annotate ( num_geom = functions . NumGeometries ( '<STR_LIT>' ) ) <EOL> for city in qs : <EOL> if mysql : <EOL> self . assertIsNone ( city . num_geom ) <EOL> else : <EOL> self . assertEqual ( <NUM_LIT:1> , city . num_geom ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_num_points ( self ) : <EOL> coords = [ ( - <NUM_LIT> , <NUM_LIT> ) , ( - <NUM_LIT> , <NUM_LIT> ) ] <EOL> Track . objects . create ( name = '<STR_LIT>' , line = LineString ( coords ) ) <EOL> qs = Track . objects . annotate ( num_points = functions . NumPoints ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( qs . first ( ) . num_points , <NUM_LIT:2> ) <EOL> if spatialite or mysql : <EOL> return <EOL> for c in Country . objects . annotate ( num_points = functions . NumPoints ( '<STR_LIT>' ) ) : <EOL> self . assertEqual ( c . mpoly . num_points , c . num_points ) <EOL> if not oracle : <EOL> for c in City . objects . annotate ( num_points = functions . NumPoints ( '<STR_LIT>' ) ) : <EOL> self . assertEqual ( <NUM_LIT:1> , c . num_points ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_point_on_surface ( self ) : <EOL> if oracle : <EOL> ref = { '<STR_LIT>' : fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) , <EOL> '<STR_LIT>' : fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) , <EOL> } <EOL> else : <EOL> ref = { '<STR_LIT>' : Country . objects . get ( name = '<STR_LIT>' ) . mpoly . point_on_surface , <EOL> '<STR_LIT>' : Country . objects . get ( name = '<STR_LIT>' ) . mpoly . point_on_surface <EOL> } <EOL> qs = Country . objects . annotate ( point_on_surface = functions . PointOnSurface ( '<STR_LIT>' ) ) <EOL> for country in qs : <EOL> tol = <NUM_LIT> <EOL> self . assertTrue ( ref [ country . name ] . equals_exact ( country . point_on_surface , tol ) ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_reverse_geom ( self ) : <EOL> coords = [ ( - <NUM_LIT> , <NUM_LIT> ) , ( - <NUM_LIT> , <NUM_LIT> ) ] <EOL> Track . objects . create ( name = '<STR_LIT>' , line = LineString ( coords ) ) <EOL> track = Track . objects . annotate ( reverse_geom = functions . Reverse ( '<STR_LIT>' ) ) . get ( name = '<STR_LIT>' ) <EOL> coords . reverse ( ) <EOL> self . assertEqual ( tuple ( coords ) , track . reverse_geom . coords ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_scale ( self ) : <EOL> xfac , yfac = <NUM_LIT:2> , <NUM_LIT:3> <EOL> tol = <NUM_LIT:5> <EOL> qs = Country . objects . annotate ( scaled = functions . Scale ( '<STR_LIT>' , xfac , yfac ) ) <EOL> for country in qs : <EOL> for p1 , p2 in zip ( country . mpoly , country . scaled ) : <EOL> for r1 , r2 in zip ( p1 , p2 ) : <EOL> for c1 , c2 in zip ( r1 . coords , r2 . coords ) : <EOL> self . assertAlmostEqual ( c1 [ <NUM_LIT:0> ] * xfac , c2 [ <NUM_LIT:0> ] , tol ) <EOL> self . assertAlmostEqual ( c1 [ <NUM_LIT:1> ] * yfac , c2 [ <NUM_LIT:1> ] , tol ) <EOL> qs = Country . objects . annotate ( scaled = functions . Scale ( '<STR_LIT>' , <NUM_LIT> , Decimal ( '<STR_LIT>' ) ) ) <EOL> self . assertGreater ( qs [ <NUM_LIT:0> ] . scaled . area , qs [ <NUM_LIT:0> ] . mpoly . area ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_snap_to_grid ( self ) : <EOL> for bad_args in ( ( ) , range ( <NUM_LIT:3> ) , range ( <NUM_LIT:5> ) ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> Country . objects . annotate ( snap = functions . SnapToGrid ( '<STR_LIT>' , * bad_args ) ) <EOL> for bad_args in ( ( '<STR_LIT:1.0>' , ) , ( <NUM_LIT:1.0> , None ) , tuple ( map ( six . text_type , range ( <NUM_LIT:4> ) ) ) ) : <EOL> with self . assertRaises ( TypeError ) : <EOL> Country . objects . annotate ( snap = functions . SnapToGrid ( '<STR_LIT>' , * bad_args ) ) <EOL> wkt = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> Country . objects . create ( name = '<STR_LIT>' , mpoly = fromstr ( wkt ) ) <EOL> tol = <NUM_LIT> <EOL> ref = fromstr ( '<STR_LIT>' ) <EOL> self . assertTrue ( <EOL> ref . equals_exact ( <EOL> Country . objects . annotate ( <EOL> snap = functions . SnapToGrid ( '<STR_LIT>' , <NUM_LIT:0.1> ) <EOL> ) . get ( name = '<STR_LIT>' ) . snap , <EOL> tol <EOL> ) <EOL> ) <EOL> ref = fromstr ( '<STR_LIT>' ) <EOL> self . assertTrue ( <EOL> ref . equals_exact ( <EOL> Country . objects . annotate ( <EOL> snap = functions . SnapToGrid ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> ) <EOL> ) . get ( name = '<STR_LIT>' ) . snap , <EOL> tol <EOL> ) <EOL> ) <EOL> ref = fromstr ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertTrue ( <EOL> ref . equals_exact ( <EOL> Country . objects . annotate ( <EOL> snap = functions . SnapToGrid ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.5> , <NUM_LIT> ) <EOL> ) . get ( name = '<STR_LIT>' ) . snap , <EOL> tol <EOL> ) <EOL> ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_sym_difference ( self ) : <EOL> geom = Point ( <NUM_LIT:5> , <NUM_LIT> , srid = <NUM_LIT> ) <EOL> qs = Country . objects . annotate ( sym_difference = functions . SymDifference ( '<STR_LIT>' , geom ) ) <EOL> if oracle : <EOL> qs = qs . exclude ( name = '<STR_LIT>' ) <EOL> for country in qs : <EOL> self . assertTrue ( country . mpoly . sym_difference ( geom ) . equals ( country . sym_difference ) ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_transform ( self ) : <EOL> ptown = fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> prec = <NUM_LIT:3> <EOL> h = City . objects . annotate ( pt = functions . Transform ( '<STR_LIT>' , ptown . srid ) ) . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , h . pt . srid ) <EOL> self . assertAlmostEqual ( ptown . x , h . pt . x , prec ) <EOL> self . assertAlmostEqual ( ptown . y , h . pt . y , prec ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_translate ( self ) : <EOL> xfac , yfac = <NUM_LIT:5> , - <NUM_LIT> <EOL> qs = Country . objects . annotate ( translated = functions . Translate ( '<STR_LIT>' , xfac , yfac ) ) <EOL> for c in qs : <EOL> for p1 , p2 in zip ( c . mpoly , c . translated ) : <EOL> for r1 , r2 in zip ( p1 , p2 ) : <EOL> for c1 , c2 in zip ( r1 . coords , r2 . coords ) : <EOL> self . assertAlmostEqual ( c1 [ <NUM_LIT:0> ] + xfac , c2 [ <NUM_LIT:0> ] , <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( c1 [ <NUM_LIT:1> ] + yfac , c2 [ <NUM_LIT:1> ] , <NUM_LIT:5> ) <EOL> @ skipUnlessDBFeature ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_diff_intersection_union ( self ) : <EOL> "<STR_LIT>" <EOL> geom = Point ( <NUM_LIT:5> , <NUM_LIT> , srid = <NUM_LIT> ) <EOL> qs = Country . objects . all ( ) . annotate ( <EOL> difference = functions . Difference ( '<STR_LIT>' , geom ) , <EOL> sym_difference = functions . SymDifference ( '<STR_LIT>' , geom ) , <EOL> union = functions . Union ( '<STR_LIT>' , geom ) , <EOL> ) <EOL> if spatialite : <EOL> qs = qs . exclude ( name = '<STR_LIT>' ) <EOL> else : <EOL> qs = qs . annotate ( intersection = functions . Intersection ( '<STR_LIT>' , geom ) ) <EOL> if oracle : <EOL> return <EOL> for c in qs : <EOL> self . assertTrue ( c . mpoly . difference ( geom ) . equals ( c . difference ) ) <EOL> if not ( spatialite or mysql ) : <EOL> self . assertEqual ( c . mpoly . intersection ( geom ) , c . intersection ) <EOL> self . assertTrue ( c . mpoly . sym_difference ( geom ) . equals ( c . sym_difference ) ) <EOL> self . assertTrue ( c . mpoly . union ( geom ) . equals ( c . union ) ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_union ( self ) : <EOL> geom = Point ( - <NUM_LIT> , <NUM_LIT> , srid = <NUM_LIT> ) <EOL> ptown = City . objects . annotate ( union = functions . Union ( '<STR_LIT>' , geom ) ) . get ( name = '<STR_LIT>' ) <EOL> tol = <NUM_LIT> <EOL> expected1 = fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> expected2 = fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> self . assertTrue ( expected1 . equals_exact ( ptown . union , tol ) or expected2 . equals_exact ( ptown . union , tol ) ) </s>
