def test_set_sequencenumber(self): "Sequence number is not defined by default but can be set manually" osm_change = OSMChange() self.assertIsNone(osm_change.sequence_number) osm_change.sequence_number = 12345 self.assertEqual(osm_change.sequence_number, 12345) osm_change.sequence_number = "12345" self.assertEqual(osm_change.sequence_number, 12345)
def test_init_osmchange(self): "Test OSMChange init" osmchange = OSMChange() self.assertIsInstance(osmchange, OSMChange) self.assertIsInstance(osmchange.create, list) self.assertIsInstance(osmchange.modify, list) self.assertIsInstance(osmchange.delete, list) self.assertEqual(len(osmchange.create), 0) self.assertEqual(len(osmchange.modify), 0) self.assertEqual(len(osmchange.delete), 0)
def test_3_readfromfile(self): "Test initializing from file" osmchange = OSMChange.from_xml(self.osmchange_file_path) self.assertEqual(len(osmchange.create), 831) self.assertEqual(len(osmchange.modify), 368) self.assertEqual(len(osmchange.delete), 3552) nodes_created = [o for o in osmchange.create if isinstance(o, Node)] ways_created = [o for o in osmchange.create if isinstance(o, Way)] rels_created = [o for o in osmchange.create if isinstance(o, Relation)] self.assertEqual(len(nodes_created), 699) self.assertEqual(len(ways_created), 132) self.assertEqual(len(rels_created), 0) self.assertEqual(len(nodes_created + ways_created + rels_created), len(osmchange.create))
def test_1_initialization(self): "Test successful initiaization" osm_change = OSMChange() self.assertIsInstance(osm_change, OSMChange)
def test_4_state(self): "Test getting state (requires internet)" osm_change = OSMChange() self.assertTrue(osm_change.get_state()) self.assertIsInstance(osm_change.sequence_number, int)
#!/usr/bin/env python from osmdiff import OSMChange, AugmentedDiff from osmdiff.osm import Node, Way, Relation debug = True r = OSMChange(debug=debug) r.get_state() r.retrieve() print(r) r = OSMChange(file="test_osmchange.xml", debug=debug) print(r) a = AugmentedDiff(file="test_adiff.xml", debug=debug) print(a) a = AugmentedDiff( # minlon=-160.0, # minlat=20.0, # maxlon=-80.0, # maxlat=60.0, debug=debug) a.get_state() a.retrieve() print(a) # n = Node() # w = Way() # r = Relation()
def parse_diff(file, configMergeDistance, configPercentageToMerge, polygonMinimumSize, verbose): nodes_count = 0 ways_count = 0 relations_count = 0 global mergeDistance mergeDistance = configMergeDistance global mergePercentage mergePercentage = configPercentageToMerge global polygonMinSize polygonMinSize = polygonMinimumSize d = OSMChange(file=file) for osmObject in d.create: type_of = parse_object(osmObject) if type_of == 1: nodes_count += 1 elif type_of == 2: ways_count += 1 elif type_of == 3: relations_count += 1 else: print('This part shouldn\'t be reached, check algorithm') if verbose is True: print('Created: {nodes} nodes, {ways} ways and {relations} relations'.format(nodes=nodes_count, ways=ways_count, relations=relations_count)) nodes_count = 0 ways_count = 0 relations_count = 0 for osmObject in d.modify: type_of = parse_object(osmObject) if type_of == 1: nodes_count += 1 elif type_of == 2: ways_count += 1 elif type_of == 3: relations_count += 1 else: print('This part shouldn\'t be reached, check algorithm') if verbose is True: print('Modified: {nodes} nodes, {ways} ways and {relations} relations'.format(nodes=nodes_count, ways=ways_count, relations=relations_count)) nodes_count = 0 ways_count = 0 relations_count = 0 for osmObject in d.delete: type_of = parse_object(osmObject) if type_of == 1: nodes_count += 1 elif type_of == 2: ways_count += 1 elif type_of == 3: relations_count += 1 else: print('This part shouldn\'t be reached, check algorithm') if verbose is True: print('Deleted: {nodes} nodes, {ways} ways and {relations} relations'.format(nodes=nodes_count, ways=ways_count, relations=relations_count)) iterator = 0 # Merge polygons until its possible while True: merged = False for bbox1 in bboxes: if bbox1.merged is False: for bbox2 in bboxes: if bbox1 != bbox2 and bbox2.merged is False: area = bbox1.get_poly().intersection(bbox2.get_poly()).area if (bbox1.is_suitable_for_merge(area)) or bbox2.is_suitable_for_merge(area): bbox1.merge_into(bbox2) merged = True if not merged: break iterator += 1 if verbose is True: print('Merged in {} iteration(s)'.format(iterator)) return filter(lambda x: x.merged is False, bboxes)