Commit 6b0bd76b authored by Branko Kokanovic's avatar Branko Kokanovic

Skip entities deleted from last PBF download

parent a31bf86d
......@@ -44,8 +44,10 @@ def load_results():
sz['street'] = row['street']
sz['number'] = row['number']
sz['processed'] = True
sz['node'] = None if row['node'] == '' else int(row['node'])
sz['way'] = None if row['way'] == '' else int(row['way'])
sz['node'] = [] if len(row['node']) <= 2 else [int(i) for i in row['node'][1:-1].split(',')]
sz['way'] = [] if len(row['way']) <= 2 else [int(i) for i in row['way'][1:-1].split(',')]
sz['relation'] = [] if len(row['relation']) <= 2 else \
[int(i) for i in row['relation'][1:-1].split(',')]
sz['multiple_entities_same_housenumber'] = row['multiple_entities_same_housenumber'] == 'True'
sz['building_tag_present'] = row['building_tag_present'] == 'True'
sz['building_is_apartments'] = row['building_is_apartments'] == 'True'
......@@ -56,31 +58,32 @@ def load_results():
def main():
stambene_zajednice = load_results()
count = len([sz for sz in stambene_zajednice
if sz['processed'] and sz['way'] and sz['building_tag_present'] and not sz['building_is_apartments']])
if sz['processed'] and len(sz['way']) > 0 and sz['building_tag_present'] and not sz['building_is_apartments']])
i = 0
for sz in stambene_zajednice:
if sz['processed'] and sz['way'] and sz['building_tag_present'] and not sz['building_is_apartments']:
if sz['processed'] and len(sz['way']) > 0 and sz['building_tag_present'] and not sz['building_is_apartments']:
i = i + 1
if i < 0: # If you need to skip already processed, set this to value greater than 0
if i % 100 == 0:
logger.info('Progress: {0}/{1}'.format(i, count))
continue
logger.info('Progress: {0}/{1}'.format(i, count))
way = api.WayGet(sz['way'])
if 'building' not in way['tag']:
logger.warning('{0} is missing building tag, skipping'.format(sz['way']))
continue
if way['tag']['building'] == 'apartments':
logger.warning('{0} already have building=apartments tag, skipping'.format(sz['way']))
time.sleep(5)
continue
for k, v in way['tag'].items():
logger.info('{0}: {1}'.format(k, v))
logger.info('https://www.openstreetmap.org/way/{0}'.format(sz['way']))
to_continue = input('Proceed (y/n):')
if to_continue == '' or to_continue == 'y':
way['tag']['building'] = 'apartments'
api.WayUpdate(way)
for way_id in sz['way']:
way = api.WayGet(way_id)
if 'building' not in way['tag']:
logger.warning('{0} is missing building tag, skipping'.format(way_id))
continue
if way['tag']['building'] == 'apartments':
logger.warning('{0} already have building=apartments tag, skipping'.format(way_id))
continue
for k, v in way['tag'].items():
logger.info('{0}: {1}'.format(k, v))
logger.info('https://www.openstreetmap.org/way/{0}'.format(way_id))
logger.info('Ways found for this address: {0}'.format(len(sz['way'])))
to_continue = input('Proceed (y/n):')
if to_continue == '' or to_continue == 'y':
way['tag']['building'] = 'apartments'
api.WayUpdate(way)
api.flush()
......
......@@ -154,6 +154,9 @@ out;
// &contact=branko@kokanovic.org
""".format(entity_id))
if len(result.areas) == 0:
# It got deleted in the meantime
return None
if len(result.areas) != 1:
raise Exception("query found not one district for entity {0}{1}, but {2}".format(entity_type[0], entity_id, len(result.areas)))
return result.areas[0].tags['name']
......@@ -405,7 +408,10 @@ def process_stambena_zajednica_with_pbf(sz: dict, all_addresses: dict):
logger.debug('Examining entity {0}{1}'.format(entity['osm_type'][0], entity['osm_id']))
# Find district and municipality from overpass turbo,
# and then convert them from OSM name to name used in dataset (so we can match them)
associated_counties = osm_to_dataset_district(find_district(entity['osm_id'], entity['osm_type']).lower())
district_res = find_district(entity['osm_id'], entity['osm_type'])
if district_res is None:
continue
associated_counties = osm_to_dataset_district(district_res.lower())
associated_cities = osm_to_dataset_municipality(find_municipality(entity['osm_id'], entity['osm_type']).lower())
logger.debug('Found district/municipality {0}/{1}'.format(associated_counties, associated_cities))
found_county_city_combination = False
......@@ -518,9 +524,9 @@ def main():
sz['municipality'] == row['municipality'] and sz['street'] == row['street'] and\
sz['number'] == row['number']:
sz['processed'] = True
sz['node'] = [] if row['node'] == '' else [int(i) for i in row['node'][1:-1].split(',')]
sz['way'] = [] if row['way'] == '' else [int(i) for i in row['way'][1:-1].split(',')]
sz['relation'] = [] if row['relation'] == '' else\
sz['node'] = [] if len(row['node']) <= 2 else [int(i) for i in row['node'][1:-1].split(',')]
sz['way'] = [] if len(row['way']) <= 2 else [int(i) for i in row['way'][1:-1].split(',')]
sz['relation'] = [] if len(row['relation']) <= 2 else\
[int(i) for i in row['relation'][1:-1].split(',')]
sz['multiple_entities_same_housenumber'] = row['multiple_entities_same_housenumber'] == 'True'
sz['building_tag_present'] = row['building_tag_present'] == 'True'
......
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