<s> """<STR_LIT>""" <EOL> from . import unittest , numpy <EOL> from shapely . wkb import loads as load_wkb <EOL> from shapely . geos import lgeos <EOL> from shapely . geometry import Point , Polygon , asPolygon <EOL> from shapely . geometry . polygon import LinearRing , LineString , asLinearRing <EOL> from shapely . geometry . base import dump_coords <EOL> class PolygonTestCase ( unittest . TestCase ) : <EOL> def test_polygon ( self ) : <EOL> coords = ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) <EOL> ring = LinearRing ( coords ) <EOL> self . assertEqual ( len ( ring . coords ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( ring . coords [ <NUM_LIT:0> ] , ring . coords [ <NUM_LIT:4> ] ) <EOL> self . assertEqual ( ring . coords [ <NUM_LIT:0> ] , ring . coords [ - <NUM_LIT:1> ] ) <EOL> self . assertTrue ( ring . is_ring ) <EOL> ring . coords = ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:0.0> ) ) <EOL> self . assertEqual ( <EOL> ring . __geo_interface__ , <EOL> { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) } ) <EOL> coords = [ [ <NUM_LIT:0.0> , <NUM_LIT:0.0> ] , [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] , [ <NUM_LIT:1.0> , <NUM_LIT:1.0> ] , [ <NUM_LIT:1.0> , <NUM_LIT:0.0> ] ] <EOL> ra = asLinearRing ( coords ) <EOL> self . assertTrue ( ra . wkt . upper ( ) . startswith ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( dump_coords ( ra ) , <EOL> [ ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ] ) <EOL> coords [ <NUM_LIT:3> ] = [ <NUM_LIT> , - <NUM_LIT:1.0> ] <EOL> self . assertEqual ( dump_coords ( ra ) , <EOL> [ ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT> , - <NUM_LIT:1.0> ) , <EOL> ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ] ) <EOL> polygon = Polygon ( coords ) <EOL> self . assertEqual ( len ( polygon . exterior . coords ) , <NUM_LIT:5> ) <EOL> self . assertIsInstance ( polygon . exterior , LinearRing ) <EOL> ring = polygon . exterior <EOL> self . assertEqual ( len ( ring . coords ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( ring . coords [ <NUM_LIT:0> ] , ring . coords [ <NUM_LIT:4> ] ) <EOL> self . assertEqual ( ring . coords [ <NUM_LIT:0> ] , ( <NUM_LIT:0.> , <NUM_LIT:0.> ) ) <EOL> self . assertTrue ( ring . is_ring ) <EOL> self . assertEqual ( len ( polygon . interiors ) , <NUM_LIT:0> ) <EOL> data = polygon . wkb <EOL> polygon = None <EOL> ring = None <EOL> polygon = load_wkb ( data ) <EOL> ring = polygon . exterior <EOL> self . assertEqual ( len ( ring . coords ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( ring . coords [ <NUM_LIT:0> ] , ring . coords [ <NUM_LIT:4> ] ) <EOL> self . assertEqual ( ring . coords [ <NUM_LIT:0> ] , ( <NUM_LIT:0.> , <NUM_LIT:0.> ) ) <EOL> self . assertTrue ( ring . is_ring ) <EOL> polygon = None <EOL> polygon = Polygon ( coords , [ ( ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:0.5> ) , <EOL> ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) , ( <NUM_LIT:0.5> , <NUM_LIT> ) ) ] ) <EOL> self . assertEqual ( len ( polygon . exterior . coords ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( len ( polygon . interiors [ <NUM_LIT:0> ] . coords ) , <NUM_LIT:5> ) <EOL> with self . assertRaises ( IndexError ) : <EOL> polygon . interiors [ <NUM_LIT:1> ] <EOL> copy = Polygon ( polygon ) <EOL> self . assertEqual ( len ( polygon . exterior . coords ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( len ( polygon . interiors [ <NUM_LIT:0> ] . coords ) , <NUM_LIT:5> ) <EOL> with self . assertRaises ( IndexError ) : <EOL> polygon . interiors [ <NUM_LIT:1> ] <EOL> self . assertRaises ( NotImplementedError , polygon . _get_coords ) <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> polygon . coords <EOL> self . assertEqual ( <EOL> polygon . __geo_interface__ , <EOL> { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT> , - <NUM_LIT:1.0> ) , <EOL> ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) , ( ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:0.5> ) , <EOL> ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) , ( <NUM_LIT:0.5> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ) ) } ) <EOL> hole_coords = [ ( ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:0.5> ) , ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) , ( <NUM_LIT:0.5> , <NUM_LIT> ) ) ] <EOL> pa = asPolygon ( coords , hole_coords ) <EOL> self . assertEqual ( len ( pa . exterior . coords ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( len ( pa . interiors ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( pa . interiors [ <NUM_LIT:0> ] . coords ) , <NUM_LIT:5> ) <EOL> r_null = LinearRing ( ) <EOL> self . assertEqual ( r_null . wkt , '<STR_LIT>' ) <EOL> self . assertEqual ( r_null . length , <NUM_LIT:0.0> ) <EOL> r_null . coords = [ ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ] <EOL> self . assertAlmostEqual ( r_null . length , <NUM_LIT> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> Polygon ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] ] ) <EOL> def test_linearring_from_closed_linestring ( self ) : <EOL> coords = [ ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ] <EOL> line = LineString ( coords ) <EOL> ring = LinearRing ( line ) <EOL> self . assertEqual ( len ( ring . coords ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( ring . coords [ : ] , coords ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> lgeos . GEOSGeomType ( ring . _geom ) . decode ( '<STR_LIT:ascii>' ) ) <EOL> def test_linearring_from_unclosed_linestring ( self ) : <EOL> coords = [ ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ] <EOL> line = LineString ( coords [ : - <NUM_LIT:1> ] ) <EOL> ring = LinearRing ( line ) <EOL> self . assertEqual ( len ( ring . coords ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( ring . coords [ : ] , coords ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> lgeos . GEOSGeomType ( ring . _geom ) . decode ( '<STR_LIT:ascii>' ) ) <EOL> @ unittest . skipIf ( not numpy , '<STR_LIT>' ) <EOL> def test_numpy ( self ) : <EOL> from numpy import array , asarray <EOL> from numpy . testing import assert_array_equal <EOL> a = asarray ( ( ( <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> polygon = Polygon ( a ) <EOL> self . assertEqual ( len ( polygon . exterior . coords ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( dump_coords ( polygon . exterior ) , <EOL> [ ( <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 ( len ( polygon . interiors ) , <NUM_LIT:0> ) <EOL> b = asarray ( polygon . exterior ) <EOL> self . assertEqual ( b . shape , ( <NUM_LIT:5> , <NUM_LIT:2> ) ) <EOL> assert_array_equal ( <EOL> b , array ( [ ( <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> def test_dimensions ( self ) : <EOL> coords = ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) <EOL> polygon = Polygon ( coords ) <EOL> self . assertEqual ( polygon . _ndim , <NUM_LIT:3> ) <EOL> gi = polygon . __geo_interface__ <EOL> self . assertEqual ( <EOL> gi [ '<STR_LIT>' ] , <EOL> ( ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) , ) ) <EOL> e = polygon . exterior <EOL> self . assertEqual ( e . _ndim , <NUM_LIT:3> ) <EOL> gi = e . __geo_interface__ <EOL> self . assertEqual ( <EOL> gi [ '<STR_LIT>' ] , <EOL> ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) ) <EOL> def test_attribute_chains ( self ) : <EOL> p = Polygon ( ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) ) <EOL> self . assertEqual ( <EOL> list ( p . boundary . coords ) , <EOL> [ ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ] ) <EOL> ec = list ( Point ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) . buffer ( <NUM_LIT:1.0> , <NUM_LIT:1> ) . exterior . coords ) <EOL> self . assertIsInstance ( ec , list ) <EOL> p = Polygon ( <EOL> ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) , <EOL> [ ( ( - <NUM_LIT> , <NUM_LIT> ) , ( - <NUM_LIT> , <NUM_LIT> ) , ( - <NUM_LIT> , <NUM_LIT> ) , ( - <NUM_LIT> , <NUM_LIT> ) ) ] <EOL> ) <EOL> self . assertEqual ( p . area , <NUM_LIT> ) <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> list ( p . interiors [ <NUM_LIT:0> ] . coords ) , <EOL> [ ( - <NUM_LIT> , <NUM_LIT> ) , ( - <NUM_LIT> , <NUM_LIT> ) , ( - <NUM_LIT> , <NUM_LIT> ) , ( - <NUM_LIT> , <NUM_LIT> ) , <EOL> ( - <NUM_LIT> , <NUM_LIT> ) ] ) <EOL> xy = list ( p . interiors [ <NUM_LIT:0> ] . buffer ( <NUM_LIT:1> ) . exterior . coords ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( xy ) , <NUM_LIT:2> ) <EOL> ec = list ( p . buffer ( <NUM_LIT:1> ) . boundary . coords ) <EOL> self . assertIsInstance ( ec , list ) <EOL> def test_empty_equality ( self ) : <EOL> point1 = Point ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> polygon1 = Polygon ( ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) ) <EOL> polygon2 = Polygon ( ( ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , ( - <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) ) <EOL> polygon_empty1 = Polygon ( ) <EOL> polygon_empty2 = Polygon ( ) <EOL> self . assertNotEqual ( point1 , polygon1 ) <EOL> self . assertEqual ( polygon_empty1 , polygon_empty2 ) <EOL> self . assertNotEqual ( polygon1 , polygon_empty1 ) <EOL> self . assertEqual ( polygon1 , polygon2 ) <EOL> self . assertNotEqual ( None , polygon_empty1 ) <EOL> def test_suite ( ) : <EOL> return unittest . TestLoader ( ) . loadTestsFromTestCase ( PolygonTestCase ) </s>
