async def test_geometrycollection_should_round(connection):
    geom = GeometryCollection(COLLECTION, srid=4326)
    await connection.execute(
        'INSERT INTO geometrycollection_async (geom) '
        'VALUES ($1)', geom)
    geom = await connection.fetchval(
        'SELECT geom '
        'FROM geometrycollection_async '
        'WHERE geom=$1',
        geom,
        column=0)
    assert geom == COLLECTION
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))
            )},
        ]
    }
Exemplo n.º 3
0
 def getValues(self):
     """
     Geometry representing the values taken by the temporal value.
     """
     values = [seq.getValues for seq in self._sequenceList]
     points = [geo for geo in values if isinstance(geo, Point)]
     lines = [geo for geo in values if isinstance(geo, LineString)]
     if len(points) != 0 and len(points) != 0:
         return GeometryCollection(points + lines)
     if len(points) != 0 and len(points) == 0:
         return MultiPoint(points)
     if len(points) == 0 and len(points) != 0:
         return MultiLineString(lines)
Exemplo n.º 4
0
def test_tgeompointseqset_accessors(cursor, expected_tgeompointseqset):
    assert TGeomPointSeqSet(expected_tgeompointseqset).srid == 4326
    assert TGeomPointSeqSet(expected_tgeompointseqset).tempSubtype() == 'SequenceSet'
    assert TGeomPointSeqSet(expected_tgeompointseqset).getValues == \
        GeometryCollection([Point(10.0, 10.0), LineString([Point(20.0, 20.0), Point(30.0, 30.0)])])
    assert TGeomPointSeqSet(expected_tgeompointseqset).startValue == Point(10.0, 10.0)
    assert TGeomPointSeqSet(expected_tgeompointseqset).endValue == Point(30.0, 30.0)
    # assert TGeomPointSeqSet(expected_tgeompointseqset).valueRange == geompointrange(Point(10.0, 10.0), Point(30.0, 30.0), upper_inc=True)
    assert TGeomPointSeqSet(expected_tgeompointseqset).getTime == PeriodSet(
        '{[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01],[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]}')
    assert TGeomPointSeqSet(expected_tgeompointseqset).duration == timedelta(1)
    assert TGeomPointSeqSet(expected_tgeompointseqset).timespan == timedelta(2)
    assert TGeomPointSeqSet(expected_tgeompointseqset).period == Period('[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]')
    assert TGeomPointSeqSet(expected_tgeompointseqset).numInstants == 3
    assert TGeomPointSeqSet(expected_tgeompointseqset).startInstant == TGeomPointInst('Point(10.0 10.0)@2019-09-01 00:00:00+01')
    assert TGeomPointSeqSet(expected_tgeompointseqset).endInstant == TGeomPointInst('Point(30.0 30.0)@2019-09-03 00:00:00+01')
    assert TGeomPointSeqSet(expected_tgeompointseqset).instantN(2) == TGeomPointInst('Point(20.0 20.0)@2019-09-02 00:00:00+01')
    assert TGeomPointSeqSet(expected_tgeompointseqset).instants == [TGeomPointInst('Point(10.0 10.0)@2019-09-01 00:00:00+01'),
                                                        TGeomPointInst('Point(20.0 20.0)@2019-09-02 00:00:00+01'),
                                                        TGeomPointInst('Point(30.0 30.0)@2019-09-03 00:00:00+01')]
    assert TGeomPointSeqSet(expected_tgeompointseqset).numTimestamps == 3
    assert TGeomPointSeqSet(expected_tgeompointseqset).startTimestamp == parse('2019-09-01 00:00:00+01')
    assert TGeomPointSeqSet(expected_tgeompointseqset).endTimestamp == parse('2019-09-03 00:00:00+01')
    assert TGeomPointSeqSet(expected_tgeompointseqset).timestampN(2) == parse('2019-09-02 00:00:00+01')
    assert TGeomPointSeqSet(expected_tgeompointseqset).timestamps == [parse('2019-09-01 00:00:00+01'),
                                                          parse('2019-09-02 00:00:00+01'),
                                                          parse('2019-09-03 00:00:00+01')]
    assert TGeomPointSeqSet(expected_tgeompointseqset).numSequences == 2
    assert TGeomPointSeqSet(expected_tgeompointseqset).startSequence == TGeomPointSeq('[Point(10.0 10.0)@2019-09-01 00:00:00+01]')
    assert TGeomPointSeqSet(expected_tgeompointseqset).endSequence == TGeomPointSeq(
        '[Point(20.0 20.0)@2019-09-02 00:00:00+01, Point(30.0 30.0)@2019-09-03 00:00:00+01]')
    assert TGeomPointSeqSet(expected_tgeompointseqset).sequenceN(2) == TGeomPointSeq(
        '[Point(20.0 20.0)@2019-09-02 00:00:00+01, Point(30.0 30.0)@2019-09-03 00:00:00+01]')
    assert TGeomPointSeqSet(expected_tgeompointseqset).sequences == [TGeomPointSeq('[Point(10.0 10.0)@2019-09-01 00:00:00+01]'),
        TGeomPointSeq('[Point(20.0 20.0)@2019-09-02 00:00:00+01, Point(30.0 30.0)@2019-09-03 00:00:00+01]')]
    assert TGeomPointSeqSet(expected_tgeompointseqset).intersectsTimestamp(parse('2019-09-01 00:00:00+01')) == True
    assert TGeomPointSeqSet(expected_tgeompointseqset).intersectsTimestamp(parse('2019-09-04 00:00:00+01')) == False
    assert TGeomPointSeqSet(expected_tgeompointseqset).intersectsTimestampSet(
        TimestampSet('{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True
    assert TGeomPointSeqSet(expected_tgeompointseqset).intersectsTimestampSet(
        TimestampSet('{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False
    assert TGeomPointSeqSet(expected_tgeompointseqset).intersectsPeriod(
        Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True
    assert TGeomPointSeqSet(expected_tgeompointseqset).intersectsPeriod(
        Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False
    assert TGeomPointSeqSet(expected_tgeompointseqset).intersectsPeriodSet(
        PeriodSet('{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True
    assert TGeomPointSeqSet(expected_tgeompointseqset).intersectsPeriodSet(
        PeriodSet('{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
def test_geometrycollection_iter():
    collection = GeometryCollection(COLLECTION)
    for i, geom in enumerate(collection):
        assert geom == COLLECTION[i]
def test_geometrycollection_get_item():
    collection = GeometryCollection(COLLECTION)
    assert collection[2] == POLYGON
def test_geometrycollection_should_round(cursor):
    params = [GeometryCollection(COLLECTION, srid=4326)]
    cursor.execute('INSERT INTO geometrycollection (geom) VALUES (%s)', params)
    cursor.execute('SELECT geom FROM geometrycollection WHERE geom=%s', params)
    geom = cursor.fetchone()[0]
    assert geom == COLLECTION