Ejemplo n.º 1
0
async def test_polygon_should_round(connection, expected):
    geom = Polygon(expected, srid=4326)
    await connection.execute('INSERT INTO polygon_async (geom) VALUES ($1)',
                             geom)
    geom = await connection.fetchval(
        'SELECT geom FROM polygon_async WHERE '
        'geom=$1', geom, column=0)
    assert geom.coords == expected
Ejemplo n.º 2
0
def test_polyggon_should_round(cursor, expected):
    params = [Polygon(expected, srid=4326)]
    cursor.execute('INSERT INTO polygon (geom) VALUES (%s)', params)
    cursor.execute('SELECT geom FROM polygon WHERE geom=%s', params)
    geom = cursor.fetchone()[0]
    assert geom.coords == expected
def test_multipolygon_get_item():
    multi = MultiPolygon(MULTI)
    assert multi[0] == Polygon(MULTI[0])
from postgis import Point, LineString, Polygon, GeometryCollection

POLYGON = Polygon((
    ((1, 2), (3, 4), (5, 6), (1, 2)),
    ((2, 3), (4, 5), (6, 7), (2, 3))
))

COLLECTION = [
    Point(1, 2),
    LineString(((1, 2), (3, 4))),
    POLYGON
]


def test_geometrycollection_geojson():
    collection = GeometryCollection(COLLECTION)
    assert collection.geojson == {
        "type": "GeometryCollection",
        "geometries": [
            {'type': 'Point', 'coordinates': (1, 2)},
            {'type': 'LineString', 'coordinates': ((1, 2), (3, 4))},
            {'type': 'Polygon', 'coordinates': (
                ((1, 2), (3, 4), (5, 6), (1, 2)),
                ((2, 3), (4, 5), (6, 7), (2, 3))
            )},
        ]
    }


def test_geometrycollection_get_item():
    collection = GeometryCollection(COLLECTION)
Ejemplo n.º 5
0
def test_polygon_geojson():
    poly = Polygon((((1, 2), (3, 4), (5, 6), (1, 2)),))
    assert poly.geojson == {"type": "Polygon",
                            "coordinates": (((1, 2), (3, 4), (5, 6), (1, 2)),)}
Ejemplo n.º 6
0
def test_geom_should_compare_with_coords():
    assert (((35, 10), (45, 45), (15, 40), (10, 20), (35, 10)), ((20, 30), (35, 35), (30, 20), (20, 30))) == Polygon((((35, 10), (45, 45), (15, 40), (10, 20), (35, 10)), ((20, 30), (35, 35), (30, 20), (20, 30))))  # noqa
Ejemplo n.º 7
0
def test_polygon_wkt():
    poly = Polygon((((1, 2), (3, 4), (5, 6), (1, 2)), ))
    wkt = poly.wkt
    wkt = wkt.replace('.0', '')
    wkt = wkt.replace(', ', ',')
    assert wkt == 'POLYGON((1 2,3 4,5 6,1 2))'