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_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
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 __init__(self, config, crs='epsg:27700', from_crs='epsg:4326', level=logging.DEBUG): super().__init__() logging.basicConfig(level=level) self.cnfg = config self.filter = self.cnfg["filter"] self.features_config = self.cnfg["features_config"] self.default_activities = self.cnfg["default_activities"] self.activity_config = self.cnfg["activity_config"] self.transformer = Transformer.from_proj(Proj(from_crs), Proj(crs)) self.objects = helpers.AutoTree() self.points = helpers.AutoTree() self.areas = helpers.AutoTree() self.log = { "existing": 0, "points": 0, "areas": 0, "defaults": 0 }
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]