Commit 392c48e3 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

add area-of-intrest filter to osm2vadere converter

parent fa0d8ae4
......@@ -136,10 +136,22 @@ class OsmConverter:
for f in self.osm.measurement_selectors:
def filter_area_of_interest(self):
aoi = self.osm.get_area_of_intrest()
if aoi:
self.obstacles = [o for o in self.obstacles if self.osm.contained_in_area_of_intrest(aoi, o)]
self.targets = [o for o in self.targets if self.osm.contained_in_area_of_intrest(aoi, o)]
self.sources = [o for o in self.sources if self.osm.contained_in_area_of_intrest(aoi, o)]
self.measurement = [o for o in self.measurement if self.osm.contained_in_area_of_intrest(aoi, o)]
def from_args(cls, arg):
c = cls(arg.input, arg.use_osm_id)
return c
......@@ -557,5 +569,12 @@ def main_convert(cmd_args):
if __name__ == "__main__":
# i = '/home/stsc/repos/vadere/Scenarios/Demos/roVer/scenarios/mf_underground.osm'
# o = '/home/stsc/repos/vadere/Scenarios/Demos/roVer/scenarios/mf_underground.scenario'
# c = OsmConverter(i, True)
# c.filter()
# c.filter_area_of_interest()
# #
args = parse_command_line_arguments()
......@@ -782,6 +782,38 @@ class OsmData:
print(f"created new hull-way (id:{}) containing {way_ids}")
def contained_in_area_of_intrest(self, aoi, way: Element):
min_lat = aoi[0][0]
max_lat = aoi[0][1]
min_lon = aoi[1][0]
max_lon = aoi[1][1]
nodes = [self.lookup.node_to_latlon[int(id)] for id in way.xpath("nd/@ref")]
for n in nodes:
if n[0] < min_lat or n[0] > max_lat or n[1] < min_lon or n[1] > max_lon:
return False
return True
def get_area_of_intrest(self):
Return lat/lon min/max values for element within area of intrest
lat = [0,0]
lon = [0,0]
nodes = [self.lookup.node_to_latlon[int(id)] for id in self.xml.xpath("/osm/way[./tag/@k='vadere:area-of-intrest']/nd/@ref")][:-1]
node_lat = [n[0] for n in nodes]
node_lon = [n[1] for n in nodes]
return ([min(node_lat), max(node_lat)], [min(node_lon), max(node_lon)])
def lint_add_ids(self, dry_run=False):
ways_without_id: List[Element] = self.xml.xpath("/osm/way[@id < 0 and not (./tag[@k='rover:id'])]")
print(f"found {len(ways_without_id)} way elements without id")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment