def test_autotree_point_poly_intersection(): tree = helpers.AutoTree() target = build.OSMObject(idx=0, activity_tags=[build.OSMTag(key="b", value="b")], geom=Point((0, 0))) tree.auto_insert(target) tree.auto_insert( build.OSMObject(idx=0, activity_tags=[build.OSMTag(key="b", value="b")], geom=Point((10, 10)))) geom = Polygon([(-1, -1), (-1, 1), (1, 1), (1, -1), (-1, -1)]) assert tree.intersection(geom.bounds) == [target]
def test_object_assign_areas(): building = build.Object(idx="XL", osm_tags={"building": "yes"}, activity_tags=[], geom=Polygon([(-5, -5), (-5, 5), (5, 5), (5, -5), (-5, -5)])) tree = helpers.AutoTree() tree.auto_insert( build.OSMObject(idx=0, activity_tags=[build.OSMTag(key="a", value="a")], geom=Polygon([(-5, -5), (-5, 5), (5, 5), (5, -5), (-5, -5)]))) tree.auto_insert( build.OSMObject(idx=0, activity_tags=[build.OSMTag(key="b", value="b")], geom=Polygon([(10, 10), (10, 25), (25, 25), (25, 10), (10, 10)]))) tree.auto_insert( build.OSMObject(idx=0, activity_tags=[ build.OSMTag(key="c", value="c"), build.OSMTag(key="d", value="d") ], geom=Polygon([(-50, -50), (-50, 50), (50, 50), (50, -50), (-50, -50)]))) assert building.assign_points(tree) assert building.activity_tags == [ build.OSMTag(key='a', value='a'), build.OSMTag(key='c', value='c'), build.OSMTag(key='d', value='d') ]
def test_autotree_insert(): tree = helpers.AutoTree() facility = build.OSMObject( idx=0, activity_tags=[build.OSMTag(key="b", value="b")], geom=Point((10, 10))) tree.auto_insert(facility) assert len(tree.objects) == 1 assert tree.counter == 1
def test_autotree_iter(): tree = helpers.AutoTree() for i in range(3): tree.auto_insert( build.OSMObject(idx=0, activity_tags=[build.OSMTag(key="b", value="b")], geom=Point((10, 10)))) out = [o for o in tree] assert len(out) == 3