<s> from __future__ import unicode_literals <EOL> import ctypes <EOL> import json <EOL> import random <EOL> from binascii import a2b_hex , b2a_hex <EOL> from io import BytesIO <EOL> from unittest import skipUnless <EOL> from django . contrib . gis import gdal <EOL> from django . contrib . gis . gdal import HAS_GDAL <EOL> from django . contrib . gis . geos import ( <EOL> HAS_GEOS , GeometryCollection , GEOSException , GEOSGeometry , LinearRing , <EOL> LineString , MultiLineString , MultiPoint , MultiPolygon , Point , Polygon , <EOL> fromfile , fromstr , <EOL> ) <EOL> from django . contrib . gis . geos . base import GEOSBase <EOL> from django . contrib . gis . geos . libgeos import geos_version_info <EOL> from django . contrib . gis . shortcuts import numpy <EOL> from django . template import Context <EOL> from django . template . engine import Engine <EOL> from django . test import SimpleTestCase , ignore_warnings , mock <EOL> from django . utils import six <EOL> from django . utils . deprecation import RemovedInDjango20Warning <EOL> from django . utils . encoding import force_bytes <EOL> from django . utils . six . moves import range <EOL> from . . test_data import TestDataMixin <EOL> @ skipUnless ( HAS_GEOS , "<STR_LIT>" ) <EOL> class GEOSTest ( SimpleTestCase , TestDataMixin ) : <EOL> def test_base ( self ) : <EOL> "<STR_LIT>" <EOL> class FakeGeom1 ( GEOSBase ) : <EOL> pass <EOL> c_float_p = ctypes . POINTER ( ctypes . c_float ) <EOL> class FakeGeom2 ( GEOSBase ) : <EOL> ptr_type = c_float_p <EOL> fg1 = FakeGeom1 ( ) <EOL> fg2 = FakeGeom2 ( ) <EOL> fg1 . ptr = ctypes . c_void_p ( ) <EOL> fg1 . ptr = None <EOL> fg2 . ptr = c_float_p ( ctypes . c_float ( <NUM_LIT> ) ) <EOL> fg2 . ptr = None <EOL> for fg in ( fg1 , fg2 ) : <EOL> with self . assertRaises ( GEOSException ) : <EOL> fg . _get_ptr ( ) <EOL> bad_ptrs = ( <NUM_LIT:5> , ctypes . c_char_p ( b'<STR_LIT>' ) ) <EOL> for bad_ptr in bad_ptrs : <EOL> with self . assertRaises ( TypeError ) : <EOL> fg1 . _set_ptr ( bad_ptr ) <EOL> with self . assertRaises ( TypeError ) : <EOL> fg2 . _set_ptr ( bad_ptr ) <EOL> def test_wkt ( self ) : <EOL> "<STR_LIT>" <EOL> for g in self . geometries . wkt_out : <EOL> geom = fromstr ( g . wkt ) <EOL> if geom . hasz : <EOL> self . assertEqual ( g . ewkt , geom . wkt ) <EOL> def test_hex ( self ) : <EOL> "<STR_LIT>" <EOL> for g in self . geometries . hex_wkt : <EOL> geom = fromstr ( g . wkt ) <EOL> self . assertEqual ( g . hex , geom . hex . decode ( ) ) <EOL> def test_hexewkb ( self ) : <EOL> "<STR_LIT>" <EOL> ogc_hex = b'<STR_LIT>' <EOL> ogc_hex_3d = b'<STR_LIT>' <EOL> hexewkb_2d = b'<STR_LIT>' <EOL> hexewkb_3d = b'<STR_LIT>' <EOL> pnt_2d = Point ( <NUM_LIT:0> , <NUM_LIT:1> , srid = <NUM_LIT> ) <EOL> pnt_3d = Point ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , srid = <NUM_LIT> ) <EOL> self . assertEqual ( ogc_hex , pnt_2d . hex ) <EOL> self . assertEqual ( ogc_hex_3d , pnt_3d . hex ) <EOL> self . assertEqual ( hexewkb_2d , pnt_2d . hexewkb ) <EOL> self . assertEqual ( hexewkb_3d , pnt_3d . hexewkb ) <EOL> self . assertEqual ( True , GEOSGeometry ( hexewkb_3d ) . hasz ) <EOL> self . assertEqual ( six . memoryview ( a2b_hex ( hexewkb_2d ) ) , pnt_2d . ewkb ) <EOL> self . assertEqual ( six . memoryview ( a2b_hex ( hexewkb_3d ) ) , pnt_3d . ewkb ) <EOL> self . assertEqual ( <NUM_LIT> , GEOSGeometry ( hexewkb_2d ) . srid ) <EOL> def test_kml ( self ) : <EOL> "<STR_LIT>" <EOL> for tg in self . geometries . wkt_out : <EOL> geom = fromstr ( tg . wkt ) <EOL> kml = getattr ( tg , '<STR_LIT>' , False ) <EOL> if kml : <EOL> self . assertEqual ( kml , geom . kml ) <EOL> def test_errors ( self ) : <EOL> "<STR_LIT>" <EOL> for err in self . geometries . errors : <EOL> with self . assertRaises ( ( GEOSException , ValueError ) ) : <EOL> fromstr ( err . wkt ) <EOL> with self . assertRaises ( GEOSException ) : <EOL> GEOSGeometry ( six . memoryview ( b'<STR_LIT:0>' ) ) <EOL> class NotAGeometry ( object ) : <EOL> pass <EOL> with self . assertRaises ( TypeError ) : <EOL> GEOSGeometry ( NotAGeometry ( ) ) <EOL> with self . assertRaises ( TypeError ) : <EOL> GEOSGeometry ( None ) <EOL> def test_wkb ( self ) : <EOL> "<STR_LIT>" <EOL> for g in self . geometries . hex_wkt : <EOL> geom = fromstr ( g . wkt ) <EOL> wkb = geom . wkb <EOL> self . assertEqual ( b2a_hex ( wkb ) . decode ( ) . upper ( ) , g . hex ) <EOL> def test_create_hex ( self ) : <EOL> "<STR_LIT>" <EOL> for g in self . geometries . hex_wkt : <EOL> geom_h = GEOSGeometry ( g . hex ) <EOL> geom_t = fromstr ( g . wkt ) <EOL> self . assertEqual ( geom_t . wkt , geom_h . wkt ) <EOL> def test_create_wkb ( self ) : <EOL> "<STR_LIT>" <EOL> for g in self . geometries . hex_wkt : <EOL> wkb = six . memoryview ( a2b_hex ( g . hex . encode ( ) ) ) <EOL> geom_h = GEOSGeometry ( wkb ) <EOL> geom_t = fromstr ( g . wkt ) <EOL> self . assertEqual ( geom_t . wkt , geom_h . wkt ) <EOL> def test_ewkt ( self ) : <EOL> "<STR_LIT>" <EOL> srids = ( - <NUM_LIT:1> , <NUM_LIT> ) <EOL> for srid in srids : <EOL> for p in self . geometries . polygons : <EOL> ewkt = '<STR_LIT>' % ( srid , p . wkt ) <EOL> poly = fromstr ( ewkt ) <EOL> self . assertEqual ( srid , poly . srid ) <EOL> self . assertEqual ( srid , poly . shell . srid ) <EOL> self . assertEqual ( srid , fromstr ( poly . ewkt ) . srid ) <EOL> @ skipUnless ( HAS_GDAL , "<STR_LIT>" ) <EOL> def test_json ( self ) : <EOL> "<STR_LIT>" <EOL> for g in self . geometries . json_geoms : <EOL> geom = GEOSGeometry ( g . wkt ) <EOL> if not hasattr ( g , '<STR_LIT>' ) : <EOL> self . assertEqual ( json . loads ( g . json ) , json . loads ( geom . json ) ) <EOL> self . assertEqual ( json . loads ( g . json ) , json . loads ( geom . geojson ) ) <EOL> self . assertEqual ( GEOSGeometry ( g . wkt ) , GEOSGeometry ( geom . json ) ) <EOL> def test_fromfile ( self ) : <EOL> "<STR_LIT>" <EOL> ref_pnt = GEOSGeometry ( '<STR_LIT>' ) <EOL> wkt_f = BytesIO ( ) <EOL> wkt_f . write ( force_bytes ( ref_pnt . wkt ) ) <EOL> wkb_f = BytesIO ( ) <EOL> wkb_f . write ( bytes ( ref_pnt . wkb ) ) <EOL> for fh in ( wkt_f , wkb_f ) : <EOL> fh . seek ( <NUM_LIT:0> ) <EOL> pnt = fromfile ( fh ) <EOL> self . assertEqual ( ref_pnt , pnt ) <EOL> def test_eq ( self ) : <EOL> "<STR_LIT>" <EOL> p = fromstr ( '<STR_LIT>' ) <EOL> self . assertEqual ( p , p . wkt ) <EOL> self . assertNotEqual ( p , '<STR_LIT:foo>' ) <EOL> ls = fromstr ( '<STR_LIT>' ) <EOL> self . assertEqual ( ls , ls . wkt ) <EOL> self . assertNotEqual ( p , '<STR_LIT:bar>' ) <EOL> for g in ( p , ls ) : <EOL> self . assertNotEqual ( g , None ) <EOL> self . assertNotEqual ( g , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> self . assertNotEqual ( g , False ) <EOL> def test_points ( self ) : <EOL> "<STR_LIT>" <EOL> prev = fromstr ( '<STR_LIT>' ) <EOL> for p in self . geometries . points : <EOL> pnt = fromstr ( p . wkt ) <EOL> self . assertEqual ( pnt . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( pnt . geom_typeid , <NUM_LIT:0> ) <EOL> self . assertEqual ( pnt . dims , <NUM_LIT:0> ) <EOL> self . assertEqual ( p . x , pnt . x ) <EOL> self . assertEqual ( p . y , pnt . y ) <EOL> self . assertEqual ( pnt , fromstr ( p . wkt ) ) <EOL> self . assertEqual ( False , pnt == prev ) <EOL> self . assertAlmostEqual ( p . x , pnt . tuple [ <NUM_LIT:0> ] , <NUM_LIT:9> ) <EOL> self . assertAlmostEqual ( p . y , pnt . tuple [ <NUM_LIT:1> ] , <NUM_LIT:9> ) <EOL> if hasattr ( p , '<STR_LIT:z>' ) : <EOL> self . assertEqual ( True , pnt . hasz ) <EOL> self . assertEqual ( p . z , pnt . z ) <EOL> self . assertEqual ( p . z , pnt . tuple [ <NUM_LIT:2> ] , <NUM_LIT:9> ) <EOL> tup_args = ( p . x , p . y , p . z ) <EOL> set_tup1 = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> set_tup2 = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> else : <EOL> self . assertEqual ( False , pnt . hasz ) <EOL> self . assertIsNone ( pnt . z ) <EOL> tup_args = ( p . x , p . y ) <EOL> set_tup1 = ( <NUM_LIT> , <NUM_LIT> ) <EOL> set_tup2 = ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertEqual ( p . centroid , pnt . centroid . tuple ) <EOL> pnt2 = Point ( tup_args ) <EOL> pnt3 = Point ( * tup_args ) <EOL> self . assertEqual ( pnt , pnt2 ) <EOL> self . assertEqual ( pnt , pnt3 ) <EOL> pnt . y = <NUM_LIT> <EOL> pnt . x = <NUM_LIT> <EOL> self . assertEqual ( <NUM_LIT> , pnt . y ) <EOL> self . assertEqual ( <NUM_LIT> , pnt . x ) <EOL> pnt . tuple = set_tup1 <EOL> self . assertEqual ( set_tup1 , pnt . tuple ) <EOL> pnt . coords = set_tup2 <EOL> self . assertEqual ( set_tup2 , pnt . coords ) <EOL> prev = pnt <EOL> def test_multipoints ( self ) : <EOL> "<STR_LIT>" <EOL> for mp in self . geometries . multipoints : <EOL> mpnt = fromstr ( mp . wkt ) <EOL> self . assertEqual ( mpnt . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( mpnt . geom_typeid , <NUM_LIT:4> ) <EOL> self . assertEqual ( mpnt . dims , <NUM_LIT:0> ) <EOL> self . assertAlmostEqual ( mp . centroid [ <NUM_LIT:0> ] , mpnt . centroid . tuple [ <NUM_LIT:0> ] , <NUM_LIT:9> ) <EOL> self . assertAlmostEqual ( mp . centroid [ <NUM_LIT:1> ] , mpnt . centroid . tuple [ <NUM_LIT:1> ] , <NUM_LIT:9> ) <EOL> with self . assertRaises ( IndexError ) : <EOL> mpnt . __getitem__ ( len ( mpnt ) ) <EOL> self . assertEqual ( mp . centroid , mpnt . centroid . tuple ) <EOL> self . assertEqual ( mp . coords , tuple ( m . tuple for m in mpnt ) ) <EOL> for p in mpnt : <EOL> self . assertEqual ( p . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( p . geom_typeid , <NUM_LIT:0> ) <EOL> self . assertEqual ( p . empty , False ) <EOL> self . assertEqual ( p . valid , True ) <EOL> def test_linestring ( self ) : <EOL> "<STR_LIT>" <EOL> prev = fromstr ( '<STR_LIT>' ) <EOL> for l in self . geometries . linestrings : <EOL> ls = fromstr ( l . wkt ) <EOL> self . assertEqual ( ls . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( ls . geom_typeid , <NUM_LIT:1> ) <EOL> self . assertEqual ( ls . dims , <NUM_LIT:1> ) <EOL> self . assertEqual ( ls . empty , False ) <EOL> self . assertEqual ( ls . ring , False ) <EOL> if hasattr ( l , '<STR_LIT>' ) : <EOL> self . assertEqual ( l . centroid , ls . centroid . tuple ) <EOL> if hasattr ( l , '<STR_LIT>' ) : <EOL> self . assertEqual ( l . tup , ls . tuple ) <EOL> self . assertEqual ( ls , fromstr ( l . wkt ) ) <EOL> self . assertEqual ( False , ls == prev ) <EOL> with self . assertRaises ( IndexError ) : <EOL> ls . __getitem__ ( len ( ls ) ) <EOL> prev = ls <EOL> self . assertEqual ( ls , LineString ( ls . tuple ) ) <EOL> self . assertEqual ( ls , LineString ( * ls . tuple ) ) <EOL> self . assertEqual ( ls , LineString ( [ list ( tup ) for tup in ls . tuple ] ) ) <EOL> self . assertEqual ( ls . wkt , LineString ( * tuple ( Point ( tup ) for tup in ls . tuple ) ) . wkt ) <EOL> if numpy : <EOL> self . assertEqual ( ls , LineString ( numpy . array ( ls . tuple ) ) ) <EOL> with self . assertRaisesMessage ( TypeError , '<STR_LIT>' ) : <EOL> LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> with self . assertRaisesMessage ( ValueError , '<STR_LIT>' ) : <EOL> LineString ( [ ( <NUM_LIT:0> , <NUM_LIT:0> ) ] ) <EOL> if numpy : <EOL> with self . assertRaisesMessage ( ValueError , '<STR_LIT>' ) : <EOL> LineString ( numpy . array ( [ ( <NUM_LIT:0> , <NUM_LIT:0> ) ] ) ) <EOL> with mock . patch ( '<STR_LIT>' , False ) : <EOL> with self . assertRaisesMessage ( TypeError , '<STR_LIT>' ) : <EOL> LineString ( '<STR_LIT>' ) <EOL> def test_multilinestring ( self ) : <EOL> "<STR_LIT>" <EOL> prev = fromstr ( '<STR_LIT>' ) <EOL> for l in self . geometries . multilinestrings : <EOL> ml = fromstr ( l . wkt ) <EOL> self . assertEqual ( ml . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( ml . geom_typeid , <NUM_LIT:5> ) <EOL> self . assertEqual ( ml . dims , <NUM_LIT:1> ) <EOL> self . assertAlmostEqual ( l . centroid [ <NUM_LIT:0> ] , ml . centroid . x , <NUM_LIT:9> ) <EOL> self . assertAlmostEqual ( l . centroid [ <NUM_LIT:1> ] , ml . centroid . y , <NUM_LIT:9> ) <EOL> self . assertEqual ( ml , fromstr ( l . wkt ) ) <EOL> self . assertEqual ( False , ml == prev ) <EOL> prev = ml <EOL> for ls in ml : <EOL> self . assertEqual ( ls . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( ls . geom_typeid , <NUM_LIT:1> ) <EOL> self . assertEqual ( ls . empty , False ) <EOL> with self . assertRaises ( IndexError ) : <EOL> ml . __getitem__ ( len ( ml ) ) <EOL> self . assertEqual ( ml . wkt , MultiLineString ( * tuple ( s . clone ( ) for s in ml ) ) . wkt ) <EOL> self . assertEqual ( ml , MultiLineString ( * tuple ( LineString ( s . tuple ) for s in ml ) ) ) <EOL> def test_linearring ( self ) : <EOL> "<STR_LIT>" <EOL> for rr in self . geometries . linearrings : <EOL> lr = fromstr ( rr . wkt ) <EOL> self . assertEqual ( lr . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( lr . geom_typeid , <NUM_LIT:2> ) <EOL> self . assertEqual ( lr . dims , <NUM_LIT:1> ) <EOL> self . assertEqual ( rr . n_p , len ( lr ) ) <EOL> self . assertEqual ( True , lr . valid ) <EOL> self . assertEqual ( False , lr . empty ) <EOL> self . assertEqual ( lr , LinearRing ( lr . tuple ) ) <EOL> self . assertEqual ( lr , LinearRing ( * lr . tuple ) ) <EOL> self . assertEqual ( lr , LinearRing ( [ list ( tup ) for tup in lr . tuple ] ) ) <EOL> if numpy : <EOL> self . assertEqual ( lr , LinearRing ( numpy . array ( lr . tuple ) ) ) <EOL> with self . assertRaisesMessage ( ValueError , '<STR_LIT>' ) : <EOL> LinearRing ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> with self . assertRaisesMessage ( ValueError , '<STR_LIT>' ) : <EOL> LinearRing ( [ ( <NUM_LIT:0> , <NUM_LIT:0> ) ] ) <EOL> if numpy : <EOL> with self . assertRaisesMessage ( ValueError , '<STR_LIT>' ) : <EOL> LinearRing ( numpy . array ( [ ( <NUM_LIT:0> , <NUM_LIT:0> ) ] ) ) <EOL> def test_polygons_from_bbox ( self ) : <EOL> "<STR_LIT>" <EOL> bbox = ( - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> p = Polygon . from_bbox ( bbox ) <EOL> self . assertEqual ( bbox , p . extent ) <EOL> x = <NUM_LIT> <EOL> bbox = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , x ) <EOL> p = Polygon . from_bbox ( bbox ) <EOL> y = p . extent [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( format ( x , '<STR_LIT>' ) , format ( y , '<STR_LIT>' ) ) <EOL> def test_polygons ( self ) : <EOL> "<STR_LIT>" <EOL> prev = fromstr ( '<STR_LIT>' ) <EOL> for p in self . geometries . polygons : <EOL> poly = fromstr ( p . wkt ) <EOL> self . assertEqual ( poly . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( poly . geom_typeid , <NUM_LIT:3> ) <EOL> self . assertEqual ( poly . dims , <NUM_LIT:2> ) <EOL> self . assertEqual ( poly . empty , False ) <EOL> self . assertEqual ( poly . ring , False ) <EOL> self . assertEqual ( p . n_i , poly . num_interior_rings ) <EOL> self . assertEqual ( p . n_i + <NUM_LIT:1> , len ( poly ) ) <EOL> self . assertEqual ( p . n_p , poly . num_points ) <EOL> self . assertAlmostEqual ( p . area , poly . area , <NUM_LIT:9> ) <EOL> self . assertAlmostEqual ( p . centroid [ <NUM_LIT:0> ] , poly . centroid . tuple [ <NUM_LIT:0> ] , <NUM_LIT:9> ) <EOL> self . assertAlmostEqual ( p . centroid [ <NUM_LIT:1> ] , poly . centroid . tuple [ <NUM_LIT:1> ] , <NUM_LIT:9> ) <EOL> self . assertEqual ( poly , fromstr ( p . wkt ) ) <EOL> self . assertEqual ( False , poly == prev ) <EOL> self . assertNotEqual ( poly , prev ) <EOL> ring = poly . exterior_ring <EOL> self . assertEqual ( ring . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( ring . geom_typeid , <NUM_LIT:2> ) <EOL> if p . ext_ring_cs : <EOL> self . assertEqual ( p . ext_ring_cs , ring . tuple ) <EOL> self . assertEqual ( p . ext_ring_cs , poly [ <NUM_LIT:0> ] . tuple ) <EOL> with self . assertRaises ( IndexError ) : <EOL> poly . __getitem__ ( len ( poly ) ) <EOL> with self . assertRaises ( IndexError ) : <EOL> poly . __setitem__ ( len ( poly ) , False ) <EOL> with self . assertRaises ( IndexError ) : <EOL> poly . __getitem__ ( - <NUM_LIT:1> * len ( poly ) - <NUM_LIT:1> ) <EOL> for r in poly : <EOL> self . assertEqual ( r . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( r . geom_typeid , <NUM_LIT:2> ) <EOL> with self . assertRaises ( TypeError ) : <EOL> Polygon ( <NUM_LIT:0> , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> with self . assertRaises ( TypeError ) : <EOL> Polygon ( '<STR_LIT:foo>' ) <EOL> rings = tuple ( r for r in poly ) <EOL> self . assertEqual ( poly , Polygon ( rings [ <NUM_LIT:0> ] , rings [ <NUM_LIT:1> : ] ) ) <EOL> ring_tuples = tuple ( r . tuple for r in poly ) <EOL> self . assertEqual ( poly , Polygon ( * ring_tuples ) ) <EOL> self . assertEqual ( poly . wkt , Polygon ( * tuple ( r for r in poly ) ) . wkt ) <EOL> self . assertEqual ( poly . wkt , Polygon ( * tuple ( LinearRing ( r . tuple ) for r in poly ) ) . wkt ) <EOL> def test_polygons_templates ( self ) : <EOL> engine = Engine ( ) <EOL> template = engine . from_string ( '<STR_LIT>' ) <EOL> polygons = [ fromstr ( p . wkt ) for p in self . geometries . multipolygons [ : <NUM_LIT:2> ] ] <EOL> content = template . render ( Context ( { '<STR_LIT>' : polygons } ) ) <EOL> self . assertIn ( '<STR_LIT>' , content ) <EOL> def test_polygon_comparison ( self ) : <EOL> p1 = Polygon ( ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> p2 = Polygon ( ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> self . assertGreater ( p1 , p2 ) <EOL> self . assertLess ( p2 , p1 ) <EOL> p3 = Polygon ( ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> p4 = Polygon ( ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> self . assertGreater ( p4 , p3 ) <EOL> self . assertLess ( p3 , p4 ) <EOL> def test_multipolygons ( self ) : <EOL> "<STR_LIT>" <EOL> fromstr ( '<STR_LIT>' ) <EOL> for mp in self . geometries . multipolygons : <EOL> mpoly = fromstr ( mp . wkt ) <EOL> self . assertEqual ( mpoly . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( mpoly . geom_typeid , <NUM_LIT:6> ) <EOL> self . assertEqual ( mpoly . dims , <NUM_LIT:2> ) <EOL> self . assertEqual ( mp . valid , mpoly . valid ) <EOL> if mp . valid : <EOL> self . assertEqual ( mp . num_geom , mpoly . num_geom ) <EOL> self . assertEqual ( mp . n_p , mpoly . num_coords ) <EOL> self . assertEqual ( mp . num_geom , len ( mpoly ) ) <EOL> with self . assertRaises ( IndexError ) : <EOL> mpoly . __getitem__ ( len ( mpoly ) ) <EOL> for p in mpoly : <EOL> self . assertEqual ( p . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( p . geom_typeid , <NUM_LIT:3> ) <EOL> self . assertEqual ( p . valid , True ) <EOL> self . assertEqual ( mpoly . wkt , MultiPolygon ( * tuple ( poly . clone ( ) for poly in mpoly ) ) . wkt ) <EOL> def test_memory_hijinks ( self ) : <EOL> "<STR_LIT>" <EOL> poly = fromstr ( self . geometries . polygons [ <NUM_LIT:1> ] . wkt ) <EOL> ring1 = poly [ <NUM_LIT:0> ] <EOL> ring2 = poly [ <NUM_LIT:1> ] <EOL> del ring1 <EOL> del ring2 <EOL> ring1 = poly [ <NUM_LIT:0> ] <EOL> ring2 = poly [ <NUM_LIT:1> ] <EOL> del poly <EOL> str ( ring1 ) <EOL> str ( ring2 ) <EOL> def test_coord_seq ( self ) : <EOL> "<STR_LIT>" <EOL> for p in self . geometries . polygons : <EOL> if p . ext_ring_cs : <EOL> poly = fromstr ( p . wkt ) <EOL> cs = poly . exterior_ring . coord_seq <EOL> self . assertEqual ( p . ext_ring_cs , cs . tuple ) <EOL> self . assertEqual ( len ( p . ext_ring_cs ) , len ( cs ) ) <EOL> for i in range ( len ( p . ext_ring_cs ) ) : <EOL> c1 = p . ext_ring_cs [ i ] <EOL> c2 = cs [ i ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> if len ( c1 ) == <NUM_LIT:2> : <EOL> tset = ( <NUM_LIT:5> , <NUM_LIT> ) <EOL> else : <EOL> tset = ( <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:8> ) <EOL> cs [ i ] = tset <EOL> for j in range ( len ( tset ) ) : <EOL> cs [ i ] = tset <EOL> self . assertEqual ( tset [ j ] , cs [ i ] [ j ] ) <EOL> def test_relate_pattern ( self ) : <EOL> "<STR_LIT>" <EOL> g = fromstr ( '<STR_LIT>' ) <EOL> with self . assertRaises ( GEOSException ) : <EOL> g . relate_pattern ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> for rg in self . geometries . relate_geoms : <EOL> a = fromstr ( rg . wkt_a ) <EOL> b = fromstr ( rg . wkt_b ) <EOL> self . assertEqual ( rg . result , a . relate_pattern ( b , rg . pattern ) ) <EOL> self . assertEqual ( rg . pattern , a . relate ( b ) ) <EOL> def test_intersection ( self ) : <EOL> "<STR_LIT>" <EOL> for i in range ( len ( self . geometries . topology_geoms ) ) : <EOL> a = fromstr ( self . geometries . topology_geoms [ i ] . wkt_a ) <EOL> b = fromstr ( self . geometries . topology_geoms [ i ] . wkt_b ) <EOL> i1 = fromstr ( self . geometries . intersect_geoms [ i ] . wkt ) <EOL> self . assertEqual ( True , a . intersects ( b ) ) <EOL> i2 = a . intersection ( b ) <EOL> self . assertEqual ( i1 , i2 ) <EOL> self . assertEqual ( i1 , a & b ) <EOL> a &= b <EOL> self . assertEqual ( i1 , a ) <EOL> def test_union ( self ) : <EOL> "<STR_LIT>" <EOL> for i in range ( len ( self . geometries . topology_geoms ) ) : <EOL> a = fromstr ( self . geometries . topology_geoms [ i ] . wkt_a ) <EOL> b = fromstr ( self . geometries . topology_geoms [ i ] . wkt_b ) <EOL> u1 = fromstr ( self . geometries . union_geoms [ i ] . wkt ) <EOL> u2 = a . union ( b ) <EOL> self . assertEqual ( u1 , u2 ) <EOL> self . assertEqual ( u1 , a | b ) <EOL> a |= b <EOL> self . assertEqual ( u1 , a ) <EOL> def test_unary_union ( self ) : <EOL> "<STR_LIT>" <EOL> for i in range ( len ( self . geometries . topology_geoms ) ) : <EOL> a = fromstr ( self . geometries . topology_geoms [ i ] . wkt_a ) <EOL> b = fromstr ( self . geometries . topology_geoms [ i ] . wkt_b ) <EOL> u1 = fromstr ( self . geometries . union_geoms [ i ] . wkt ) <EOL> u2 = GeometryCollection ( a , b ) . unary_union <EOL> self . assertTrue ( u1 . equals ( u2 ) ) <EOL> def test_difference ( self ) : <EOL> "<STR_LIT>" <EOL> for i in range ( len ( self . geometries . topology_geoms ) ) : <EOL> a = fromstr ( self . geometries . topology_geoms [ i ] . wkt_a ) <EOL> b = fromstr ( self . geometries . topology_geoms [ i ] . wkt_b ) <EOL> d1 = fromstr ( self . geometries . diff_geoms [ i ] . wkt ) <EOL> d2 = a . difference ( b ) <EOL> self . assertEqual ( d1 , d2 ) <EOL> self . assertEqual ( d1 , a - b ) <EOL> a -= b <EOL> self . assertEqual ( d1 , a ) <EOL> def test_symdifference ( self ) : <EOL> "<STR_LIT>" <EOL> for i in range ( len ( self . geometries . topology_geoms ) ) : <EOL> a = fromstr ( self . geometries . topology_geoms [ i ] . wkt_a ) <EOL> b = fromstr ( self . geometries . topology_geoms [ i ] . wkt_b ) <EOL> d1 = fromstr ( self . geometries . sdiff_geoms [ i ] . wkt ) <EOL> d2 = a . sym_difference ( b ) <EOL> self . assertEqual ( d1 , d2 ) <EOL> self . assertEqual ( d1 , a ^ b ) <EOL> a ^= b <EOL> self . assertEqual ( d1 , a ) <EOL> def test_buffer ( self ) : <EOL> "<STR_LIT>" <EOL> for bg in self . geometries . buffer_geoms : <EOL> g = fromstr ( bg . wkt ) <EOL> exp_buf = fromstr ( bg . buffer_wkt ) <EOL> quadsegs = bg . quadsegs <EOL> width = bg . width <EOL> with self . assertRaises ( ctypes . ArgumentError ) : <EOL> g . buffer ( width , float ( quadsegs ) ) <EOL> buf = g . buffer ( width , quadsegs ) <EOL> self . assertEqual ( exp_buf . num_coords , buf . num_coords ) <EOL> self . assertEqual ( len ( exp_buf ) , len ( buf ) ) <EOL> for j in range ( len ( exp_buf ) ) : <EOL> exp_ring = exp_buf [ j ] <EOL> buf_ring = buf [ j ] <EOL> self . assertEqual ( len ( exp_ring ) , len ( buf_ring ) ) <EOL> for k in range ( len ( exp_ring ) ) : <EOL> self . assertAlmostEqual ( exp_ring [ k ] [ <NUM_LIT:0> ] , buf_ring [ k ] [ <NUM_LIT:0> ] , <NUM_LIT:9> ) <EOL> self . assertAlmostEqual ( exp_ring [ k ] [ <NUM_LIT:1> ] , buf_ring [ k ] [ <NUM_LIT:1> ] , <NUM_LIT:9> ) <EOL> def test_covers ( self ) : <EOL> poly = Polygon ( ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:10> ) , ( <NUM_LIT:10> , <NUM_LIT:10> ) , ( <NUM_LIT:10> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> self . assertTrue ( poly . covers ( Point ( <NUM_LIT:5> , <NUM_LIT:5> ) ) ) <EOL> self . assertFalse ( poly . covers ( Point ( <NUM_LIT:100> , <NUM_LIT:100> ) ) ) <EOL> def test_closed ( self ) : <EOL> ls_closed = LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> ls_not_closed = LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . assertFalse ( ls_not_closed . closed ) <EOL> self . assertTrue ( ls_closed . closed ) <EOL> if geos_version_info ( ) [ '<STR_LIT:version>' ] >= '<STR_LIT>' : <EOL> self . assertFalse ( MultiLineString ( ls_closed , ls_not_closed ) . closed ) <EOL> self . assertTrue ( MultiLineString ( ls_closed , ls_closed ) . closed ) <EOL> with mock . patch ( '<STR_LIT>' , lambda : { '<STR_LIT:version>' : '<STR_LIT>' } ) : <EOL> with self . assertRaisesMessage ( GEOSException , "<STR_LIT>" ) : <EOL> MultiLineString ( ) . closed <EOL> def test_srid ( self ) : <EOL> "<STR_LIT>" <EOL> pnt = Point ( <NUM_LIT:5> , <NUM_LIT> , srid = <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT> , pnt . srid ) <EOL> pnt . srid = <NUM_LIT> <EOL> self . assertEqual ( <NUM_LIT> , pnt . srid ) <EOL> with self . assertRaises ( ctypes . ArgumentError ) : <EOL> pnt . srid = '<STR_LIT>' <EOL> poly = fromstr ( self . geometries . polygons [ <NUM_LIT:1> ] . wkt , srid = <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT> , poly . srid ) <EOL> for ring in poly : <EOL> self . assertEqual ( <NUM_LIT> , ring . srid ) <EOL> poly . srid = <NUM_LIT> <EOL> self . assertEqual ( <NUM_LIT> , poly . shell . srid ) <EOL> gc = GeometryCollection ( Point ( <NUM_LIT:5> , <NUM_LIT> ) , LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:3> , <NUM_LIT:3> ) ) , srid = <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT> , gc . srid ) <EOL> for i in range ( len ( gc ) ) : <EOL> self . assertEqual ( <NUM_LIT> , gc [ i ] . srid ) <EOL> hex = '<STR_LIT>' <EOL> p1 = fromstr ( hex ) <EOL> self . assertEqual ( <NUM_LIT> , p1 . srid ) <EOL> p2 = fromstr ( p1 . hex ) <EOL> self . assertIsNone ( p2 . srid ) <EOL> p3 = fromstr ( p1 . hex , srid = - <NUM_LIT:1> ) <EOL> self . assertEqual ( - <NUM_LIT:1> , p3 . srid ) <EOL> pnt_wo_srid = Point ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> pnt_wo_srid . srid = pnt_wo_srid . srid <EOL> @ skipUnless ( HAS_GDAL , "<STR_LIT>" ) <EOL> def test_custom_srid ( self ) : <EOL> """<STR_LIT>""" <EOL> for srid in [ None , <NUM_LIT> ] : <EOL> pnt = Point ( <NUM_LIT> , <NUM_LIT> , srid = srid ) <EOL> self . assertTrue ( pnt . ewkt . startswith ( ( "<STR_LIT>" % srid if srid else '<STR_LIT>' ) + "<STR_LIT>" ) ) <EOL> self . assertIsInstance ( pnt . ogr , gdal . OGRGeometry ) <EOL> self . assertIsNone ( pnt . srs ) <EOL> c2w = gdal . CoordTransform ( <EOL> gdal . SpatialReference ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> gdal . SpatialReference ( <NUM_LIT> ) ) <EOL> new_pnt = pnt . transform ( c2w , clone = True ) <EOL> self . assertEqual ( new_pnt . srid , <NUM_LIT> ) <EOL> self . assertAlmostEqual ( new_pnt . x , <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> self . assertAlmostEqual ( new_pnt . y , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> def test_mutable_geometries ( self ) : <EOL> "<STR_LIT>" <EOL> for p in self . geometries . polygons : <EOL> poly = fromstr ( p . wkt ) <EOL> with self . assertRaises ( TypeError ) : <EOL> poly . __setitem__ ( <NUM_LIT:0> , LineString ( ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) <EOL> shell_tup = poly . shell . tuple <EOL> new_coords = [ ] <EOL> for point in shell_tup : <EOL> new_coords . append ( ( point [ <NUM_LIT:0> ] + <NUM_LIT> , point [ <NUM_LIT:1> ] + <NUM_LIT> ) ) <EOL> new_shell = LinearRing ( * tuple ( new_coords ) ) <EOL> poly . exterior_ring = new_shell <EOL> str ( new_shell ) <EOL> self . assertEqual ( poly . exterior_ring , new_shell ) <EOL> self . assertEqual ( poly [ <NUM_LIT:0> ] , new_shell ) <EOL> for tg in self . geometries . multipoints : <EOL> mp = fromstr ( tg . wkt ) <EOL> for i in range ( len ( mp ) ) : <EOL> pnt = mp [ i ] <EOL> new = Point ( random . randint ( <NUM_LIT> , <NUM_LIT:100> ) , random . randint ( <NUM_LIT> , <NUM_LIT:100> ) ) <EOL> mp [ i ] = new <EOL> str ( new ) <EOL> self . assertEqual ( mp [ i ] , new ) <EOL> self . assertEqual ( mp [ i ] . wkt , new . wkt ) <EOL> self . assertNotEqual ( pnt , mp [ i ] ) <EOL> for tg in self . geometries . multipolygons : <EOL> mpoly = fromstr ( tg . wkt ) <EOL> for i in range ( len ( mpoly ) ) : <EOL> poly = mpoly [ i ] <EOL> old_poly = mpoly [ i ] <EOL> for j in range ( len ( poly ) ) : <EOL> r = poly [ j ] <EOL> for k in range ( len ( r ) ) : <EOL> r [ k ] = ( r [ k ] [ <NUM_LIT:0> ] + <NUM_LIT> , r [ k ] [ <NUM_LIT:1> ] + <NUM_LIT> ) <EOL> poly [ j ] = r <EOL> self . assertNotEqual ( mpoly [ i ] , poly ) <EOL> mpoly [ i ] = poly <EOL> str ( poly ) <EOL> self . assertEqual ( mpoly [ i ] , poly ) <EOL> self . assertNotEqual ( mpoly [ i ] , old_poly ) <EOL> def test_point_list_assignment ( self ) : <EOL> p = Point ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> p [ : ] = ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> self . assertEqual ( p , Point ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> p [ : ] = ( ) <EOL> self . assertEqual ( p . wkt , Point ( ) ) <EOL> p [ : ] = ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> self . assertEqual ( p . wkt , Point ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> p [ : ] = ( <NUM_LIT:1> , ) <EOL> with self . assertRaises ( ValueError ) : <EOL> p [ : ] = ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) <EOL> def test_linestring_list_assignment ( self ) : <EOL> ls = LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> ls [ : ] = ( ) <EOL> self . assertEqual ( ls , LineString ( ) ) <EOL> ls [ : ] = ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( ls , LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> ls [ : ] = ( <NUM_LIT:1> , ) <EOL> def test_linearring_list_assignment ( self ) : <EOL> ls = LinearRing ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> ls [ : ] = ( ) <EOL> self . assertEqual ( ls , LinearRing ( ) ) <EOL> ls [ : ] = ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( ls , LinearRing ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> ls [ : ] = ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> def test_polygon_list_assignment ( self ) : <EOL> pol = Polygon ( ) <EOL> pol [ : ] = ( ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) , ) <EOL> self . assertEqual ( pol , Polygon ( ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) , ) ) <EOL> pol [ : ] = ( ) <EOL> self . assertEqual ( pol , Polygon ( ) ) <EOL> def test_geometry_collection_list_assignment ( self ) : <EOL> p = Point ( ) <EOL> gc = GeometryCollection ( ) <EOL> gc [ : ] = [ p ] <EOL> self . assertEqual ( gc , GeometryCollection ( p ) ) <EOL> gc [ : ] = ( ) <EOL> self . assertEqual ( gc , GeometryCollection ( ) ) <EOL> def test_threed ( self ) : <EOL> "<STR_LIT>" <EOL> pnt = Point ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:8> ) <EOL> self . assertEqual ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , pnt . coords ) <EOL> with self . assertRaises ( TypeError ) : <EOL> pnt . tuple = ( <NUM_LIT:1.> , <NUM_LIT> ) <EOL> pnt . coords = ( <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertEqual ( ( <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ) , pnt . coords ) <EOL> ls = LineString ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ) <EOL> self . assertEqual ( ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ) , ls . tuple ) <EOL> with self . assertRaises ( TypeError ) : <EOL> ls . __setitem__ ( <NUM_LIT:0> , ( <NUM_LIT:1.> , <NUM_LIT> ) ) <EOL> ls [ <NUM_LIT:0> ] = ( <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertEqual ( ( <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ) , ls [ <NUM_LIT:0> ] ) <EOL> def test_distance ( self ) : <EOL> "<STR_LIT>" <EOL> pnt = Point ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertEqual ( <NUM_LIT:0.0> , pnt . distance ( Point ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> self . assertEqual ( <NUM_LIT:1.0> , pnt . distance ( Point ( <NUM_LIT:0> , <NUM_LIT:1> ) ) ) <EOL> self . assertAlmostEqual ( <NUM_LIT> , pnt . distance ( Point ( <NUM_LIT:1> , <NUM_LIT:1> ) ) , <NUM_LIT:11> ) <EOL> ls1 = LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> ls2 = LineString ( ( <NUM_LIT:5> , <NUM_LIT:2> ) , ( <NUM_LIT:6> , <NUM_LIT:1> ) , ( <NUM_LIT:7> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( <NUM_LIT:3> , ls1 . distance ( ls2 ) ) <EOL> def test_length ( self ) : <EOL> "<STR_LIT>" <EOL> pnt = Point ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertEqual ( <NUM_LIT:0.0> , pnt . length ) <EOL> ls = LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . assertAlmostEqual ( <NUM_LIT> , ls . length , <NUM_LIT:11> ) <EOL> poly = Polygon ( LinearRing ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> self . assertEqual ( <NUM_LIT> , poly . length ) <EOL> mpoly = MultiPolygon ( poly . clone ( ) , poly ) <EOL> self . assertEqual ( <NUM_LIT> , mpoly . length ) <EOL> def test_emptyCollections ( self ) : <EOL> "<STR_LIT>" <EOL> geoms = [ <EOL> GeometryCollection ( [ ] ) , <EOL> fromstr ( '<STR_LIT>' ) , <EOL> GeometryCollection ( ) , <EOL> fromstr ( '<STR_LIT>' ) , <EOL> Point ( ) , <EOL> fromstr ( '<STR_LIT>' ) , <EOL> LineString ( ) , <EOL> fromstr ( '<STR_LIT>' ) , <EOL> Polygon ( ) , <EOL> fromstr ( '<STR_LIT>' ) , <EOL> MultiLineString ( ) , <EOL> fromstr ( '<STR_LIT>' ) , <EOL> MultiPolygon ( ( ) ) , <EOL> MultiPolygon ( ) , <EOL> ] <EOL> if numpy : <EOL> geoms . append ( LineString ( numpy . array ( [ ] ) ) ) <EOL> for g in geoms : <EOL> self . assertEqual ( True , g . empty ) <EOL> if isinstance ( g , Polygon ) : <EOL> self . assertEqual ( <NUM_LIT:1> , len ( g ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , g . num_geom ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( g [ <NUM_LIT:0> ] ) ) <EOL> elif isinstance ( g , ( Point , LineString ) ) : <EOL> self . assertEqual ( <NUM_LIT:1> , g . num_geom ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( g ) ) <EOL> else : <EOL> self . assertEqual ( <NUM_LIT:0> , g . num_geom ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( g ) ) <EOL> if isinstance ( g , Point ) : <EOL> with self . assertRaises ( IndexError ) : <EOL> g . x <EOL> elif isinstance ( g , Polygon ) : <EOL> lr = g . shell <EOL> self . assertEqual ( '<STR_LIT>' , lr . wkt ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( lr ) ) <EOL> self . assertEqual ( True , lr . empty ) <EOL> with self . assertRaises ( IndexError ) : <EOL> lr . __getitem__ ( <NUM_LIT:0> ) <EOL> else : <EOL> with self . assertRaises ( IndexError ) : <EOL> g . __getitem__ ( <NUM_LIT:0> ) <EOL> def test_collection_dims ( self ) : <EOL> gc = GeometryCollection ( [ ] ) <EOL> self . assertEqual ( gc . dims , - <NUM_LIT:1> ) <EOL> gc = GeometryCollection ( Point ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( gc . dims , <NUM_LIT:0> ) <EOL> gc = GeometryCollection ( LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) , Point ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( gc . dims , <NUM_LIT:1> ) <EOL> gc = GeometryCollection ( LineString ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) , Polygon ( ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) , Point ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( gc . dims , <NUM_LIT:2> ) <EOL> def test_collections_of_collections ( self ) : <EOL> "<STR_LIT>" <EOL> coll = [ mp . wkt for mp in self . geometries . multipolygons if mp . valid ] <EOL> coll . extend ( mls . wkt for mls in self . geometries . multilinestrings ) <EOL> coll . extend ( p . wkt for p in self . geometries . polygons ) <EOL> coll . extend ( mp . wkt for mp in self . geometries . multipoints ) <EOL> gc_wkt = '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( coll ) <EOL> gc1 = GEOSGeometry ( gc_wkt ) <EOL> gc2 = GeometryCollection ( * tuple ( g for g in gc1 ) ) <EOL> self . assertEqual ( gc1 , gc2 ) <EOL> @ skipUnless ( HAS_GDAL , "<STR_LIT>" ) <EOL> def test_gdal ( self ) : <EOL> "<STR_LIT>" <EOL> g1 = fromstr ( '<STR_LIT>' ) <EOL> self . assertIsInstance ( g1 . ogr , gdal . OGRGeometry ) <EOL> self . assertIsNone ( g1 . srs ) <EOL> g1_3d = fromstr ( '<STR_LIT>' ) <EOL> self . assertIsInstance ( g1_3d . ogr , gdal . OGRGeometry ) <EOL> self . assertEqual ( g1_3d . ogr . z , <NUM_LIT:8> ) <EOL> g2 = fromstr ( '<STR_LIT>' , srid = <NUM_LIT> ) <EOL> self . assertIsInstance ( g2 . ogr , gdal . OGRGeometry ) <EOL> self . assertIsInstance ( g2 . srs , gdal . SpatialReference ) <EOL> self . assertEqual ( g2 . hex , g2 . ogr . hex ) <EOL> self . assertEqual ( '<STR_LIT>' , g2 . srs . name ) <EOL> def test_copy ( self ) : <EOL> "<STR_LIT>" <EOL> import copy <EOL> poly = GEOSGeometry ( '<STR_LIT>' ) <EOL> cpy1 = copy . copy ( poly ) <EOL> cpy2 = copy . deepcopy ( poly ) <EOL> self . assertNotEqual ( poly . _ptr , cpy1 . _ptr ) <EOL> self . assertNotEqual ( poly . _ptr , cpy2 . _ptr ) <EOL> @ skipUnless ( HAS_GDAL , "<STR_LIT>" ) <EOL> def test_transform ( self ) : <EOL> "<STR_LIT>" <EOL> orig = GEOSGeometry ( '<STR_LIT>' , <NUM_LIT> ) <EOL> trans = GEOSGeometry ( '<STR_LIT>' , <NUM_LIT> ) <EOL> t1 , t2 , t3 = orig . clone ( ) , orig . clone ( ) , orig . clone ( ) <EOL> t1 . transform ( trans . srid ) <EOL> t2 . transform ( gdal . SpatialReference ( '<STR_LIT>' ) ) <EOL> ct = gdal . CoordTransform ( gdal . SpatialReference ( '<STR_LIT>' ) , gdal . SpatialReference ( <NUM_LIT> ) ) <EOL> t3 . transform ( ct ) <EOL> k1 = orig . clone ( ) <EOL> k2 = k1 . transform ( trans . srid , clone = True ) <EOL> self . assertEqual ( k1 , orig ) <EOL> self . assertNotEqual ( k1 , k2 ) <EOL> prec = <NUM_LIT:3> <EOL> for p in ( t1 , t2 , t3 , k2 ) : <EOL> self . assertAlmostEqual ( trans . x , p . x , prec ) <EOL> self . assertAlmostEqual ( trans . y , p . y , prec ) <EOL> @ skipUnless ( HAS_GDAL , "<STR_LIT>" ) <EOL> def test_transform_3d ( self ) : <EOL> p3d = GEOSGeometry ( '<STR_LIT>' , <NUM_LIT> ) <EOL> p3d . transform ( <NUM_LIT> ) <EOL> self . assertEqual ( p3d . z , <NUM_LIT:100> ) <EOL> @ skipUnless ( HAS_GDAL , "<STR_LIT>" ) <EOL> def test_transform_noop ( self ) : <EOL> """<STR_LIT>""" <EOL> g = GEOSGeometry ( '<STR_LIT>' , <NUM_LIT> ) <EOL> gt = g . tuple <EOL> g . transform ( <NUM_LIT> ) <EOL> self . assertEqual ( g . tuple , gt ) <EOL> self . assertEqual ( g . srid , <NUM_LIT> ) <EOL> g = GEOSGeometry ( '<STR_LIT>' , <NUM_LIT> ) <EOL> g1 = g . transform ( <NUM_LIT> , clone = True ) <EOL> self . assertEqual ( g1 . tuple , g . tuple ) <EOL> self . assertEqual ( g1 . srid , <NUM_LIT> ) <EOL> self . assertIsNot ( g1 , g , "<STR_LIT>" ) <EOL> with mock . patch ( '<STR_LIT>' , False ) : <EOL> g = GEOSGeometry ( '<STR_LIT>' , <NUM_LIT> ) <EOL> gt = g . tuple <EOL> g . transform ( <NUM_LIT> ) <EOL> self . assertEqual ( g . tuple , gt ) <EOL> self . assertEqual ( g . srid , <NUM_LIT> ) <EOL> g = GEOSGeometry ( '<STR_LIT>' , <NUM_LIT> ) <EOL> g1 = g . transform ( <NUM_LIT> , clone = True ) <EOL> self . assertEqual ( g1 . tuple , g . tuple ) <EOL> self . assertEqual ( g1 . srid , <NUM_LIT> ) <EOL> self . assertIsNot ( g1 , g , "<STR_LIT>" ) <EOL> @ skipUnless ( HAS_GDAL , "<STR_LIT>" ) <EOL> def test_transform_nosrid ( self ) : <EOL> """<STR_LIT>""" <EOL> g = GEOSGeometry ( '<STR_LIT>' , srid = None ) <EOL> with self . assertRaises ( GEOSException ) : <EOL> g . transform ( <NUM_LIT> ) <EOL> g = GEOSGeometry ( '<STR_LIT>' , srid = None ) <EOL> with self . assertRaises ( GEOSException ) : <EOL> g . transform ( <NUM_LIT> , clone = True ) <EOL> g = GEOSGeometry ( '<STR_LIT>' , srid = - <NUM_LIT:1> ) <EOL> with self . assertRaises ( GEOSException ) : <EOL> g . transform ( <NUM_LIT> ) <EOL> g = GEOSGeometry ( '<STR_LIT>' , srid = - <NUM_LIT:1> ) <EOL> with self . assertRaises ( GEOSException ) : <EOL> g . transform ( <NUM_LIT> , clone = True ) <EOL> @ mock . patch ( '<STR_LIT>' , False ) <EOL> def test_transform_nogdal ( self ) : <EOL> """<STR_LIT>""" <EOL> g = GEOSGeometry ( '<STR_LIT>' , <NUM_LIT> ) <EOL> with self . assertRaises ( GEOSException ) : <EOL> g . transform ( <NUM_LIT> ) <EOL> g = GEOSGeometry ( '<STR_LIT>' , <NUM_LIT> ) <EOL> with self . assertRaises ( GEOSException ) : <EOL> g . transform ( <NUM_LIT> , clone = True ) <EOL> def test_extent ( self ) : <EOL> "<STR_LIT>" <EOL> mp = MultiPoint ( Point ( <NUM_LIT:5> , <NUM_LIT> ) , Point ( <NUM_LIT:0> , <NUM_LIT:0> ) , Point ( <NUM_LIT:10> , <NUM_LIT:50> ) ) <EOL> self . assertEqual ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT> ) , mp . extent ) <EOL> pnt = Point ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertEqual ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , pnt . extent ) <EOL> poly = fromstr ( self . geometries . polygons [ <NUM_LIT:3> ] . wkt ) <EOL> ring = poly . shell <EOL> x , y = ring . x , ring . y <EOL> xmin , ymin = min ( x ) , min ( y ) <EOL> xmax , ymax = max ( x ) , max ( y ) <EOL> self . assertEqual ( ( xmin , ymin , xmax , ymax ) , poly . extent ) <EOL> def test_pickle ( self ) : <EOL> "<STR_LIT>" <EOL> from django . utils . six . moves import cPickle <EOL> import pickle <EOL> def get_geoms ( lst , srid = None ) : <EOL> return [ GEOSGeometry ( tg . wkt , srid ) for tg in lst ] <EOL> tgeoms = get_geoms ( self . geometries . points ) <EOL> tgeoms . extend ( get_geoms ( self . geometries . multilinestrings , <NUM_LIT> ) ) <EOL> tgeoms . extend ( get_geoms ( self . geometries . polygons , <NUM_LIT> ) ) <EOL> tgeoms . extend ( get_geoms ( self . geometries . multipolygons , <NUM_LIT> ) ) <EOL> for geom in tgeoms : <EOL> s1 , s2 = cPickle . dumps ( geom ) , pickle . dumps ( geom ) <EOL> g1 , g2 = cPickle . loads ( s1 ) , pickle . loads ( s2 ) <EOL> for tmpg in ( g1 , g2 ) : <EOL> self . assertEqual ( geom , tmpg ) <EOL> self . assertEqual ( geom . srid , tmpg . srid ) <EOL> def test_prepared ( self ) : <EOL> "<STR_LIT>" <EOL> mpoly = GEOSGeometry ( '<STR_LIT>' ) <EOL> prep = mpoly . prepared <EOL> pnts = [ Point ( <NUM_LIT:5> , <NUM_LIT:5> ) , Point ( <NUM_LIT> , <NUM_LIT> ) , Point ( <NUM_LIT> , <NUM_LIT> ) ] <EOL> for pnt in pnts : <EOL> self . assertEqual ( mpoly . contains ( pnt ) , prep . contains ( pnt ) ) <EOL> self . assertEqual ( mpoly . intersects ( pnt ) , prep . intersects ( pnt ) ) <EOL> self . assertEqual ( mpoly . covers ( pnt ) , prep . covers ( pnt ) ) <EOL> self . assertTrue ( prep . crosses ( fromstr ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( prep . disjoint ( Point ( - <NUM_LIT:5> , - <NUM_LIT:5> ) ) ) <EOL> poly = Polygon ( ( ( - <NUM_LIT:1> , - <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ) ) <EOL> self . assertTrue ( prep . overlaps ( poly ) ) <EOL> poly = Polygon ( ( ( - <NUM_LIT:5> , <NUM_LIT:0> ) , ( - <NUM_LIT:5> , <NUM_LIT:5> ) , ( <NUM_LIT:0> , <NUM_LIT:5> ) , ( - <NUM_LIT:5> , <NUM_LIT:0> ) ) ) <EOL> self . assertTrue ( prep . touches ( poly ) ) <EOL> poly = Polygon ( ( ( - <NUM_LIT:1> , - <NUM_LIT:1> ) , ( - <NUM_LIT:1> , <NUM_LIT:11> ) , ( <NUM_LIT:11> , <NUM_LIT:11> ) , ( <NUM_LIT:11> , - <NUM_LIT:1> ) , ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ) ) <EOL> self . assertTrue ( prep . within ( poly ) ) <EOL> del mpoly <EOL> self . assertTrue ( prep . covers ( Point ( <NUM_LIT:5> , <NUM_LIT:5> ) ) ) <EOL> def test_line_merge ( self ) : <EOL> "<STR_LIT>" <EOL> ref_geoms = ( fromstr ( '<STR_LIT>' ) , <EOL> fromstr ( '<STR_LIT>' ) , <EOL> ) <EOL> ref_merged = ( fromstr ( '<STR_LIT>' ) , <EOL> fromstr ( '<STR_LIT>' ) , <EOL> ) <EOL> for geom , merged in zip ( ref_geoms , ref_merged ) : <EOL> self . assertEqual ( merged , geom . merged ) <EOL> def test_valid_reason ( self ) : <EOL> "<STR_LIT>" <EOL> g = GEOSGeometry ( "<STR_LIT>" ) <EOL> self . assertTrue ( g . valid ) <EOL> self . assertIsInstance ( g . valid_reason , six . string_types ) <EOL> self . assertEqual ( g . valid_reason , "<STR_LIT>" ) <EOL> g = GEOSGeometry ( "<STR_LIT>" ) <EOL> self . assertFalse ( g . valid ) <EOL> self . assertIsInstance ( g . valid_reason , six . string_types ) <EOL> self . assertTrue ( g . valid_reason . startswith ( "<STR_LIT>" ) ) <EOL> def test_linearref ( self ) : <EOL> "<STR_LIT>" <EOL> ls = fromstr ( '<STR_LIT>' ) <EOL> mls = fromstr ( '<STR_LIT>' ) <EOL> self . assertEqual ( ls . project ( Point ( <NUM_LIT:0> , <NUM_LIT:20> ) ) , <NUM_LIT> ) <EOL> self . assertEqual ( ls . project ( Point ( <NUM_LIT:7> , <NUM_LIT:6> ) ) , <NUM_LIT> ) <EOL> self . assertEqual ( ls . project_normalized ( Point ( <NUM_LIT:0> , <NUM_LIT:20> ) ) , <NUM_LIT:1.0> / <NUM_LIT:3> ) <EOL> self . assertEqual ( ls . interpolate ( <NUM_LIT:10> ) , Point ( <NUM_LIT:0> , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( ls . interpolate ( <NUM_LIT> ) , Point ( <NUM_LIT:10> , <NUM_LIT:6> ) ) <EOL> self . assertEqual ( ls . interpolate_normalized ( <NUM_LIT:1.0> / <NUM_LIT:3> ) , Point ( <NUM_LIT:0> , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( mls . project ( Point ( <NUM_LIT:0> , <NUM_LIT:20> ) ) , <NUM_LIT:10> ) <EOL> self . assertEqual ( mls . project ( Point ( <NUM_LIT:7> , <NUM_LIT:6> ) ) , <NUM_LIT:16> ) <EOL> self . assertEqual ( mls . interpolate ( <NUM_LIT:9> ) , Point ( <NUM_LIT:0> , <NUM_LIT:9> ) ) <EOL> self . assertEqual ( mls . interpolate ( <NUM_LIT> ) , Point ( <NUM_LIT:10> , <NUM_LIT:7> ) ) <EOL> def test_geos_version ( self ) : <EOL> """<STR_LIT>""" <EOL> from django . contrib . gis . geos . libgeos import version_regex <EOL> versions = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> for v_init , v_geos , v_capi in versions : <EOL> m = version_regex . match ( v_init ) <EOL> self . assertTrue ( m , msg = "<STR_LIT>" % v_init ) <EOL> self . assertEqual ( m . group ( '<STR_LIT:version>' ) , v_geos ) <EOL> self . assertEqual ( m . group ( '<STR_LIT>' ) , v_capi ) <EOL> @ ignore_warnings ( category = RemovedInDjango20Warning ) <EOL> def test_deprecated_srid_getters_setters ( self ) : <EOL> p = Point ( <NUM_LIT:1> , <NUM_LIT:2> , srid = <NUM_LIT> ) <EOL> self . assertEqual ( p . get_srid ( ) , p . srid ) <EOL> p . set_srid ( <NUM_LIT> ) <EOL> self . assertEqual ( p . srid , <NUM_LIT> ) <EOL> @ ignore_warnings ( category = RemovedInDjango20Warning ) <EOL> def test_deprecated_point_coordinate_getters_setters ( self ) : <EOL> p = Point ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> self . assertEqual ( ( p . get_x ( ) , p . get_y ( ) , p . get_z ( ) ) , ( p . x , p . y , p . z ) ) <EOL> p . set_x ( <NUM_LIT:3> ) <EOL> p . set_y ( <NUM_LIT:2> ) <EOL> p . set_z ( <NUM_LIT:1> ) <EOL> self . assertEqual ( ( p . x , p . y , p . z ) , ( <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> @ ignore_warnings ( category = RemovedInDjango20Warning ) <EOL> def test_deprecated_point_tuple_getters_setters ( self ) : <EOL> p = Point ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> self . assertEqual ( p . get_coords ( ) , ( p . x , p . y , p . z ) ) <EOL> p . set_coords ( ( <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( p . get_coords ( ) , ( <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> @ ignore_warnings ( category = RemovedInDjango20Warning ) <EOL> def test_deprecated_cascaded_union ( self ) : <EOL> for geom in self . geometries . multipolygons : <EOL> mpoly = GEOSGeometry ( geom . wkt ) <EOL> self . assertEqual ( mpoly . cascaded_union , mpoly . unary_union ) </s>
