def test_osm_polygon_parent_id_get_set_with_nearest_rank(session, tables):
    session.add(
        tables.osm_polygon(id=1,
                           name="Some Polygon with missing parent",
                           place_rank=20,
                           type='city',
                           geometry=WKTElement("POINT(2 2)", srid=3857)))

    session.add(
        tables.osm_polygon(
            id=2,
            name="Some Polygon with higher rank, covering the other polygon",
            place_rank=8,
            type='continent',
            geometry=WKTElement("POLYGON((0 0,4 0,4 4,0 4,0 0))", srid=3857)))

    session.add(
        tables.osm_polygon(
            id=3,
            name="Some Polygon with same rank, covering the other polygon",
            place_rank=16,
            type='country',
            geometry=WKTElement("POLYGON((0 0,4 0,4 4,0 4,0 0))", srid=3857)))

    session.commit()

    create_parent_polygons()
    set_polygons_parent_ids()

    assert session.query(tables.osm_polygon).get(1).parent_id == 3
Esempio n. 2
0
def test_parent_polygons_orders_polygons_by_place_rank(session, tables):
    session.add(
            tables.osm_polygon(
                id=1,
                type='town',
                place_rank=18,
            )
        )

    session.add(
            tables.osm_polygon(
                id=2,
                type='town',
                place_rank=22,
            )
        )

    session.add(
            tables.osm_polygon(
                id=3,
                type='town',
                place_rank=17,
            )
        )

    session.commit()

    create_parent_polygons()

    parent_polygons_ids = [polygon.id for polygon in session.query(tables.parent_polygons)]
    assert parent_polygons_ids == [2, 1, 3]
Esempio n. 3
0
def test_parent_polygons_contains_correct_polygons(session, tables):
    session.add(
            tables.osm_polygon(
                id=1,
                name="should be included",
                type='town',
                place_rank=22,
            )
        )

    session.add(
            tables.osm_polygon(
                id=2,
                name="should be included (type = 'island' but admin_level != NULL)",
                type='island',
                place_rank=20,
                admin_level=8,
            )
        )

    session.add(
            tables.osm_polygon(
                id=3,
                name="should be excluded (place_rank > 22",
                type='town',
                place_rank=23,
            )
        )

    session.add(
            tables.osm_polygon(
                id=4,
                name="should be excluded (type = 'water')",
                type='water',
                place_rank=20,
            )
        )

    session.commit()

    create_parent_polygons()

    parent_polygons_ids = [polygon.id for polygon in session.query(tables.parent_polygons)]
    assert parent_polygons_ids == [1, 2]
Esempio n. 4
0
def test_point_parent_id_get_set(session, tables):
    session.add(
        tables.osm_point(id=1,
                         name="Some point with missing parent",
                         type='town',
                         place_rank=20,
                         geometry=WKTElement("POINT(2 2)", srid=3857)))

    session.add(
        tables.osm_polygon(id=2,
                           name="Some Polygon covering the point",
                           place_rank=16,
                           type='state',
                           geometry=WKTElement(
                               "POLYGON((0 0,4 0,4 4,0 4,0 0))", srid=3857)))

    session.commit()

    create_parent_polygons()
    set_points_parent_ids()

    assert session.query(tables.osm_point).get(1).parent_id == 2
Esempio n. 5
0
def test_housenumber_parent_id_get_set_based_on_geometry_center(
        session, tables):
    session.add(
        tables.osm_housenumber(id=1,
                               name="Some housenumber with missing parent",
                               geometry_center=WKTElement("POINT(2 2)",
                                                          srid=3857)))

    session.add(
        tables.osm_polygon(id=2,
                           name="Some Polygon covering the housenumber",
                           place_rank=20,
                           type='city',
                           geometry=WKTElement(
                               "POLYGON((0 0,4 0,4 4,0 4,0 0))", srid=3857)))

    session.commit()

    create_parent_polygons()
    set_housenumbers_parent_ids()

    assert session.query(tables.osm_housenumber).get(1).parent_id == 2
def test_osm_polygon_parent_id_get_NOT_set_if_place_rank_is_lower(
        session, tables):
    session.add(
        tables.osm_polygon(id=1,
                           name="Some Polygon with missing parent",
                           place_rank=12,
                           type='city',
                           geometry=WKTElement("POINT(2 2)", srid=3857)))

    session.add(
        tables.osm_polygon(id=2,
                           name="Some Polygon covering the other polygon",
                           place_rank=20,
                           type='country',
                           geometry=WKTElement(
                               "POLYGON((0 0,4 0,4 4,0 4,0 0))", srid=3857)))

    session.commit()

    create_parent_polygons()
    set_polygons_parent_ids()

    assert session.query(tables.osm_polygon).get(1).parent_id is None
def test_polygon_parent_id_NOT_set_if_polygon_not_fully_covered(
        session, tables):
    session.add(
        tables.osm_polygon(id=1,
                           name="Some polygon with missing parent",
                           type='town',
                           geometry=WKTElement(
                               "POLYGON((2 0,6 0,4 4,0 4,2 0))", srid=3857)))

    session.add(
        tables.osm_polygon(id=2,
                           name="Some Polygon covering the polygon",
                           place_rank=20,
                           type='state',
                           geometry=WKTElement(
                               "POLYGON((0 0,4 0,4 4,0 4,0 0))", srid=3857)))

    session.commit()

    create_parent_polygons()
    set_polygons_parent_ids()

    assert session.query(tables.osm_polygon).get(1).parent_id is None