<s> import os , unittest <EOL> from models import Country , City , PennsylvaniaCity , State , Feature , MinusOneSRID <EOL> from django . contrib . gis import gdal <EOL> from django . contrib . gis . db . backend import SpatialBackend <EOL> from django . contrib . gis . geos import * <EOL> from django . contrib . gis . measure import Distance <EOL> from django . contrib . gis . tests . utils import no_oracle , no_postgis <EOL> DISABLE = False <EOL> class GeoModelTest ( unittest . TestCase ) : <EOL> def test01_initial_sql ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> if SpatialBackend . oracle : <EOL> data_dir = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> def get_file ( wkt_file ) : <EOL> return os . path . join ( data_dir , wkt_file ) <EOL> State ( name = '<STR_LIT>' , poly = fromfile ( get_file ( '<STR_LIT>' ) ) ) . save ( ) <EOL> State ( name = '<STR_LIT>' , poly = fromfile ( get_file ( '<STR_LIT>' ) ) ) . save ( ) <EOL> Country ( name = '<STR_LIT>' , mpoly = fromfile ( get_file ( '<STR_LIT>' ) ) ) . save ( ) <EOL> Country ( name = '<STR_LIT>' , mpoly = fromfile ( get_file ( '<STR_LIT>' ) ) ) . save ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , Country . objects . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:8> , City . objects . count ( ) ) <EOL> if SpatialBackend . oracle : n_state = <NUM_LIT:2> <EOL> else : n_state = <NUM_LIT:3> <EOL> self . assertEqual ( n_state , State . objects . count ( ) ) <EOL> def test02_proxy ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> pnt = Point ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> nullcity = City ( name = '<STR_LIT>' , point = pnt ) <EOL> nullcity . save ( ) <EOL> for bad in [ <NUM_LIT:5> , <NUM_LIT> , LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) ] : <EOL> try : <EOL> nullcity . point = bad <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> new = Point ( <NUM_LIT:5> , <NUM_LIT> ) <EOL> nullcity . point = new <EOL> self . assertEqual ( <NUM_LIT> , nullcity . point . srid ) <EOL> nullcity . save ( ) <EOL> self . assertEqual ( new , City . objects . get ( name = '<STR_LIT>' ) . point ) <EOL> nullcity . point . x = <NUM_LIT> <EOL> nullcity . point . y = <NUM_LIT:5> <EOL> self . assertNotEqual ( Point ( <NUM_LIT> , <NUM_LIT:5> ) , City . objects . get ( name = '<STR_LIT>' ) . point ) <EOL> nullcity . save ( ) <EOL> self . assertEqual ( Point ( <NUM_LIT> , <NUM_LIT:5> ) , City . objects . get ( name = '<STR_LIT>' ) . point ) <EOL> nullcity . delete ( ) <EOL> shell = LinearRing ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:100> ) , ( <NUM_LIT:100> , <NUM_LIT:100> ) , ( <NUM_LIT:100> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> inner = LinearRing ( ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> ply = Polygon ( shell , inner ) <EOL> nullstate = State ( name = '<STR_LIT>' , poly = ply ) <EOL> self . assertEqual ( <NUM_LIT> , nullstate . poly . srid ) <EOL> nullstate . save ( ) <EOL> ns = State . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( ply , ns . poly ) <EOL> if gdal . HAS_GDAL : <EOL> self . assertEqual ( True , isinstance ( ns . poly . ogr , gdal . OGRGeometry ) ) <EOL> self . assertEqual ( ns . poly . wkb , ns . poly . ogr . wkb ) <EOL> self . assertEqual ( True , isinstance ( ns . poly . srs , gdal . SpatialReference ) ) <EOL> self . assertEqual ( '<STR_LIT>' , ns . poly . srs . name ) <EOL> new_inner = LinearRing ( ( <NUM_LIT:30> , <NUM_LIT:30> ) , ( <NUM_LIT:30> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:30> ) , ( <NUM_LIT:30> , <NUM_LIT:30> ) ) <EOL> ns . poly [ <NUM_LIT:1> ] = new_inner <EOL> ply [ <NUM_LIT:1> ] = new_inner <EOL> self . assertEqual ( <NUM_LIT> , ns . poly . srid ) <EOL> ns . save ( ) <EOL> self . assertEqual ( ply , State . objects . get ( name = '<STR_LIT>' ) . poly ) <EOL> ns . delete ( ) <EOL> @ no_oracle <EOL> def test03a_kml ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> qs = City . objects . all ( ) <EOL> self . assertRaises ( TypeError , qs . kml , '<STR_LIT:name>' ) <EOL> major , minor1 , minor2 = SpatialBackend . version <EOL> ref_kml1 = '<STR_LIT>' <EOL> ref_kml2 = '<STR_LIT>' <EOL> if major == <NUM_LIT:1> : <EOL> if minor1 > <NUM_LIT:3> or ( minor1 == <NUM_LIT:3> and minor2 >= <NUM_LIT:3> ) : ref_kml = ref_kml2 <EOL> else : ref_kml = ref_kml1 <EOL> else : <EOL> ref_kml = ref_kml2 <EOL> ptown1 = City . objects . kml ( field_name = '<STR_LIT>' , precision = <NUM_LIT:9> ) . get ( name = '<STR_LIT>' ) <EOL> ptown2 = City . objects . kml ( precision = <NUM_LIT:9> ) . get ( name = '<STR_LIT>' ) <EOL> for ptown in [ ptown1 , ptown2 ] : <EOL> self . assertEqual ( ref_kml , ptown . kml ) <EOL> def test03b_gml ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> qs = City . objects . all ( ) <EOL> self . assertRaises ( TypeError , qs . gml , field_name = '<STR_LIT:name>' ) <EOL> ptown1 = City . objects . gml ( field_name = '<STR_LIT>' , precision = <NUM_LIT:9> ) . get ( name = '<STR_LIT>' ) <EOL> ptown2 = City . objects . gml ( precision = <NUM_LIT:9> ) . get ( name = '<STR_LIT>' ) <EOL> if SpatialBackend . oracle : <EOL> import re <EOL> gml_regex = re . compile ( r'<STR_LIT>' ) <EOL> for ptown in [ ptown1 , ptown2 ] : <EOL> self . assertEqual ( True , bool ( gml_regex . match ( ptown . gml ) ) ) <EOL> else : <EOL> for ptown in [ ptown1 , ptown2 ] : <EOL> self . assertEqual ( '<STR_LIT>' , ptown . gml ) <EOL> def test04_transform ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> htown = fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> ptown = fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> prec = <NUM_LIT:3> <EOL> if not SpatialBackend . oracle : <EOL> h = City . objects . transform ( htown . srid ) . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , h . point . srid ) <EOL> self . assertAlmostEqual ( htown . x , h . point . x , prec ) <EOL> self . assertAlmostEqual ( htown . y , h . point . y , prec ) <EOL> p1 = City . objects . transform ( ptown . srid , field_name = '<STR_LIT>' ) . get ( name = '<STR_LIT>' ) <EOL> p2 = City . objects . transform ( srid = ptown . srid ) . get ( name = '<STR_LIT>' ) <EOL> for p in [ p1 , p2 ] : <EOL> self . assertEqual ( <NUM_LIT> , p . point . srid ) <EOL> self . assertAlmostEqual ( ptown . x , p . point . x , prec ) <EOL> self . assertAlmostEqual ( ptown . y , p . point . y , prec ) <EOL> @ no_oracle <EOL> def test05_extent ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> expected = ( - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> ) <EOL> qs = City . objects . filter ( name__in = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> extent = qs . extent ( ) <EOL> for val , exp in zip ( extent , expected ) : <EOL> self . assertAlmostEqual ( exp , val , <NUM_LIT:8> ) <EOL> @ no_oracle <EOL> def test06_make_line ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> self . assertRaises ( TypeError , State . objects . make_line ) <EOL> self . assertRaises ( TypeError , Country . objects . make_line ) <EOL> self . assertEqual ( GEOSGeometry ( '<STR_LIT>' , srid = <NUM_LIT> ) , <EOL> City . objects . make_line ( ) ) <EOL> def test09_disjoint ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> ptown = City . objects . get ( name = '<STR_LIT>' ) <EOL> qs1 = City . objects . filter ( point__disjoint = ptown . point ) <EOL> self . assertEqual ( <NUM_LIT:7> , qs1 . count ( ) ) <EOL> if not SpatialBackend . postgis : <EOL> qs2 = State . objects . filter ( poly__disjoint = ptown . point ) <EOL> self . assertEqual ( <NUM_LIT:1> , qs2 . count ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , qs2 [ <NUM_LIT:0> ] . name ) <EOL> def test10_contains_contained ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> texas = Country . objects . get ( name = '<STR_LIT>' ) <EOL> if not SpatialBackend . oracle : <EOL> qs = City . objects . filter ( point__contained = texas . mpoly ) <EOL> self . assertEqual ( <NUM_LIT:3> , qs . count ( ) ) <EOL> cities = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for c in qs : self . assertEqual ( True , c . name in cities ) <EOL> houston = City . objects . get ( name = '<STR_LIT>' ) <EOL> wellington = City . objects . get ( name = '<STR_LIT>' ) <EOL> pueblo = City . objects . get ( name = '<STR_LIT>' ) <EOL> okcity = City . objects . get ( name = '<STR_LIT>' ) <EOL> lawrence = City . objects . get ( name = '<STR_LIT>' ) <EOL> tx = Country . objects . get ( mpoly__contains = houston . point ) <EOL> nz = Country . objects . get ( mpoly__contains = wellington . point . hex ) <EOL> ks = State . objects . get ( poly__contains = lawrence . point ) <EOL> self . assertEqual ( '<STR_LIT>' , tx . name ) <EOL> self . assertEqual ( '<STR_LIT>' , nz . name ) <EOL> self . assertEqual ( '<STR_LIT>' , ks . name ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( Country . objects . filter ( mpoly__contains = pueblo . point ) ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( Country . objects . filter ( mpoly__contains = okcity . point . wkt ) ) ) <EOL> if not SpatialBackend . oracle : <EOL> qs = Country . objects . filter ( mpoly__bbcontains = okcity . point ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( qs ) ) <EOL> self . assertEqual ( '<STR_LIT>' , qs [ <NUM_LIT:0> ] . name ) <EOL> def test11_lookup_insert_transform ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> sa_4326 = '<STR_LIT>' <EOL> wgs_pnt = fromstr ( sa_4326 , srid = <NUM_LIT> ) <EOL> if SpatialBackend . oracle : <EOL> nad_wkt = '<STR_LIT>' <EOL> nad_srid = <NUM_LIT> <EOL> else : <EOL> nad_wkt = '<STR_LIT>' <EOL> nad_srid = <NUM_LIT> <EOL> nad_pnt = fromstr ( nad_wkt , srid = nad_srid ) <EOL> if SpatialBackend . oracle : <EOL> tx = Country . objects . get ( mpoly__contains = nad_pnt ) <EOL> else : <EOL> tx = Country . objects . get ( mpoly__intersects = nad_pnt ) <EOL> self . assertEqual ( '<STR_LIT>' , tx . name ) <EOL> sa = City ( name = '<STR_LIT>' , point = nad_pnt ) <EOL> sa . save ( ) <EOL> sa = City . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( wgs_pnt . x , sa . point . x , <NUM_LIT:6> ) <EOL> self . assertAlmostEqual ( wgs_pnt . y , sa . point . y , <NUM_LIT:6> ) <EOL> m1 = MinusOneSRID ( geom = Point ( <NUM_LIT> , <NUM_LIT> , srid = <NUM_LIT> ) ) <EOL> m1 . save ( ) <EOL> self . assertEqual ( - <NUM_LIT:1> , m1 . geom . srid ) <EOL> @ no_oracle <EOL> def test12_null_geometries ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> nullqs = State . objects . filter ( poly__isnull = True ) <EOL> validqs = State . objects . filter ( poly__isnull = False ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( nullqs ) ) <EOL> self . assertEqual ( '<STR_LIT>' , nullqs [ <NUM_LIT:0> ] . name ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( validqs ) ) <EOL> state_names = [ s . name for s in validqs ] <EOL> self . assertEqual ( True , '<STR_LIT>' in state_names ) <EOL> self . assertEqual ( True , '<STR_LIT>' in state_names ) <EOL> if not SpatialBackend . oracle : <EOL> State ( name = '<STR_LIT>' , poly = None ) . save ( ) <EOL> @ no_oracle <EOL> def test13_left_right ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> co_border = State . objects . get ( name = '<STR_LIT>' ) . poly <EOL> ks_border = State . objects . get ( name = '<STR_LIT>' ) . poly <EOL> cities = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> qs = City . objects . filter ( point__right = co_border ) <EOL> self . assertEqual ( <NUM_LIT:7> , len ( qs ) ) <EOL> for c in qs : self . assertEqual ( True , c . name in cities ) <EOL> cities = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> qs = City . objects . filter ( point__right = ks_border ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( qs ) ) <EOL> for c in qs : self . assertEqual ( True , c . name in cities ) <EOL> vic = City . objects . get ( point__left = co_border ) <EOL> self . assertEqual ( '<STR_LIT>' , vic . name ) <EOL> cities = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> qs = City . objects . filter ( point__left = ks_border ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( qs ) ) <EOL> for c in qs : self . assertEqual ( True , c . name in cities ) <EOL> def test14_equals ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> pnt = fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> c1 = City . objects . get ( point = pnt ) <EOL> c2 = City . objects . get ( point__same_as = pnt ) <EOL> c3 = City . objects . get ( point__equals = pnt ) <EOL> for c in [ c1 , c2 , c3 ] : self . assertEqual ( '<STR_LIT>' , c . name ) <EOL> def test15_relate ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> pnt1 = fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> pnt2 = fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> self . assertRaises ( TypeError , Country . objects . filter , mpoly__relate = ( <NUM_LIT> , '<STR_LIT:foo>' ) ) <EOL> for bad_args , e in [ ( ( pnt1 , <NUM_LIT:0> ) , TypeError ) , ( ( pnt2 , '<STR_LIT>' , <NUM_LIT:0> ) , ValueError ) ] : <EOL> qs = Country . objects . filter ( mpoly__relate = bad_args ) <EOL> self . assertRaises ( e , qs . count ) <EOL> if SpatialBackend . postgis : <EOL> contains_mask = '<STR_LIT>' <EOL> within_mask = '<STR_LIT>' <EOL> intersects_mask = '<STR_LIT>' <EOL> elif SpatialBackend . oracle : <EOL> contains_mask = '<STR_LIT>' <EOL> within_mask = '<STR_LIT>' <EOL> intersects_mask = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , Country . objects . get ( mpoly__relate = ( pnt1 , contains_mask ) ) . name ) <EOL> self . assertEqual ( '<STR_LIT>' , Country . objects . get ( mpoly__relate = ( pnt2 , contains_mask ) ) . name ) <EOL> ks = State . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , City . objects . get ( point__relate = ( ks . poly , within_mask ) ) . name ) <EOL> if not SpatialBackend . oracle : <EOL> self . assertEqual ( '<STR_LIT>' , Country . objects . get ( mpoly__relate = ( pnt1 , intersects_mask ) ) . name ) <EOL> self . assertEqual ( '<STR_LIT>' , Country . objects . get ( mpoly__relate = ( pnt2 , intersects_mask ) ) . name ) <EOL> self . assertEqual ( '<STR_LIT>' , City . objects . get ( point__relate = ( ks . poly , intersects_mask ) ) . name ) <EOL> def test16_createnull ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> c = City ( ) <EOL> self . assertEqual ( c . point , None ) <EOL> def test17_unionagg ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> tx = Country . objects . get ( name = '<STR_LIT>' ) . mpoly <EOL> union1 = fromstr ( '<STR_LIT>' ) <EOL> union2 = fromstr ( '<STR_LIT>' ) <EOL> qs = City . objects . filter ( point__within = tx ) <EOL> self . assertRaises ( TypeError , qs . unionagg , '<STR_LIT:name>' ) <EOL> u1 = qs . unionagg ( field_name = '<STR_LIT>' ) <EOL> u2 = qs . order_by ( '<STR_LIT:name>' ) . unionagg ( ) <EOL> tol = <NUM_LIT> <EOL> if SpatialBackend . oracle : <EOL> union = union2 <EOL> else : <EOL> union = union1 <EOL> self . assertEqual ( True , union . equals_exact ( u1 , tol ) ) <EOL> self . assertEqual ( True , union . equals_exact ( u2 , tol ) ) <EOL> qs = City . objects . filter ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( None , qs . unionagg ( field_name = '<STR_LIT>' ) ) <EOL> def test18_geometryfield ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> Feature ( name = '<STR_LIT>' , geom = Point ( <NUM_LIT:1> , <NUM_LIT:1> ) ) . save ( ) <EOL> Feature ( name = '<STR_LIT>' , geom = LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:5> , <NUM_LIT:5> ) ) ) . save ( ) <EOL> Feature ( name = '<STR_LIT>' , geom = Polygon ( LinearRing ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> ) , ( <NUM_LIT:5> , <NUM_LIT:5> ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) ) . save ( ) <EOL> Feature ( name = '<STR_LIT>' , <EOL> geom = GeometryCollection ( Point ( <NUM_LIT:2> , <NUM_LIT:2> ) , LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) ) , <EOL> Polygon ( LinearRing ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> ) , ( <NUM_LIT:5> , <NUM_LIT:5> ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) ) ) . save ( ) <EOL> f_1 = Feature . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( True , isinstance ( f_1 . geom , Point ) ) <EOL> self . assertEqual ( ( <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , f_1 . geom . tuple ) <EOL> f_2 = Feature . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( True , isinstance ( f_2 . geom , LineString ) ) <EOL> self . assertEqual ( ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT> , <NUM_LIT> ) ) , f_2 . geom . tuple ) <EOL> f_3 = Feature . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( True , isinstance ( f_3 . geom , Polygon ) ) <EOL> f_4 = Feature . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( True , isinstance ( f_4 . geom , GeometryCollection ) ) <EOL> self . assertEqual ( f_3 . geom , f_4 . geom [ <NUM_LIT:2> ] ) <EOL> def test19_centroid ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> qs = State . objects . exclude ( poly__isnull = True ) . centroid ( ) <EOL> if SpatialBackend . oracle : tol = <NUM_LIT:0.1> <EOL> else : tol = <NUM_LIT> <EOL> for s in qs : <EOL> self . assertEqual ( True , s . poly . centroid . equals_exact ( s . centroid , tol ) ) <EOL> def test20_pointonsurface ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> if SpatialBackend . oracle : <EOL> ref = { '<STR_LIT>' : fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) , <EOL> '<STR_LIT>' : fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) , <EOL> } <EOL> elif SpatialBackend . postgis : <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> for cntry in Country . objects . point_on_surface ( ) : <EOL> self . assertEqual ( ref [ cntry . name ] , cntry . point_on_surface ) <EOL> @ no_oracle <EOL> def test21_scale ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> xfac , yfac = <NUM_LIT:2> , <NUM_LIT:3> <EOL> qs = Country . objects . scale ( xfac , yfac , model_att = '<STR_LIT>' ) <EOL> for c in qs : <EOL> for p1 , p2 in zip ( c . mpoly , c . scaled ) : <EOL> for r1 , r2 in zip ( p1 , p2 ) : <EOL> for c1 , c2 in zip ( r1 . coords , r2 . coords ) : <EOL> self . assertEqual ( c1 [ <NUM_LIT:0> ] * xfac , c2 [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( c1 [ <NUM_LIT:1> ] * yfac , c2 [ <NUM_LIT:1> ] ) <EOL> @ no_oracle <EOL> def test22_translate ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> xfac , yfac = <NUM_LIT:5> , - <NUM_LIT> <EOL> qs = Country . objects . translate ( xfac , yfac , model_att = '<STR_LIT>' ) <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 . assertEqual ( c1 [ <NUM_LIT:0> ] + xfac , c2 [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( c1 [ <NUM_LIT:1> ] + yfac , c2 [ <NUM_LIT:1> ] ) <EOL> def test23_numgeom ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> for c in Country . objects . num_geom ( ) : self . assertEqual ( <NUM_LIT:2> , c . num_geom ) <EOL> for c in City . objects . filter ( point__isnull = False ) . num_geom ( ) : <EOL> if SpatialBackend . postgis : self . assertEqual ( None , c . num_geom ) <EOL> else : self . assertEqual ( <NUM_LIT:1> , c . num_geom ) <EOL> def test24_numpoints ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> for c in Country . objects . num_points ( ) : self . assertEqual ( c . mpoly . num_points , c . num_points ) <EOL> if SpatialBackend . postgis : <EOL> for c in City . objects . num_points ( ) : self . assertEqual ( <NUM_LIT:1> , c . num_points ) <EOL> @ no_oracle <EOL> def test25_geoset ( self ) : <EOL> "<STR_LIT>" <EOL> if DISABLE : return <EOL> geom = Point ( <NUM_LIT:5> , <NUM_LIT> ) <EOL> for c in Country . objects . all ( ) . intersection ( geom ) . difference ( geom ) . sym_difference ( geom ) . union ( geom ) : <EOL> self . assertEqual ( c . mpoly . difference ( geom ) , c . difference ) <EOL> self . assertEqual ( c . mpoly . intersection ( geom ) , c . intersection ) <EOL> self . assertEqual ( c . mpoly . sym_difference ( geom ) , c . sym_difference ) <EOL> self . assertEqual ( c . mpoly . union ( geom ) , c . union ) <EOL> def test26_inherited_geofields ( self ) : <EOL> "<STR_LIT>" <EOL> mansfield = PennsylvaniaCity . objects . create ( name = '<STR_LIT>' , county = '<STR_LIT>' , point = '<STR_LIT>' ) <EOL> qs = PennsylvaniaCity . objects . transform ( <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT:1> , qs . count ( ) ) <EOL> for pc in qs : self . assertEqual ( <NUM_LIT> , pc . point . srid ) <EOL> from test_feeds import GeoFeedTest <EOL> from test_sitemaps import GeoSitemapTest <EOL> def suite ( ) : <EOL> s = unittest . TestSuite ( ) <EOL> s . addTest ( unittest . makeSuite ( GeoModelTest ) ) <EOL> s . addTest ( unittest . makeSuite ( GeoFeedTest ) ) <EOL> s . addTest ( unittest . makeSuite ( GeoSitemapTest ) ) <EOL> return s </s>
