Skip to content

Commit b1f60c3

Browse files
committed
Update osm enrich for checking way and relation in split way
1 parent b9f7988 commit b1f60c3

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ services:
7474

7575
osmenrich:
7676
image: kartoza/docker-osm:osmenrich-latest
77+
build:
78+
context: ./docker-osmenrich
79+
dockerfile: Dockerfile
7780
volumes:
7881
- settings-data:/home/settings
7982
- import_done:/home/import_done

docker-osmenrich/enrich.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,10 @@ def update_osm_enrich_from_api_in_batch(
427427
self.info('%s' % e)
428428
return content
429429

430-
def process_empty_changeset_from_table(self, table_name, table_columns, osm_id_column, osm_type):
430+
def process_empty_changeset_from_table(
431+
self, table_name, table_columns,
432+
osm_id_column, osm_type, extra_where=None
433+
):
431434
""" Processing all data from table
432435
433436
:param table_name: Table source
@@ -444,15 +447,25 @@ def process_empty_changeset_from_table(self, table_name, table_columns, osm_id_c
444447
445448
:param osm_id_column: Column name of osm_id
446449
:type osm_id_column: str
450+
451+
:param extra_where: Other where for query
452+
:type extra_where: str
447453
"""
448454
# noinspection PyUnboundLocalVariable
449455
connection = self.create_connection()
450456
cursor = connection.cursor()
451457
row_batch = {}
452458
osm_ids = []
453459
try:
454-
check_sql = ''' select * from %s."%s" WHERE "changeset_timestamp"
455-
IS NULL AND "osm_id" IS NOT NULL ORDER BY "osm_id" ''' % (self.default['DBSCHEMA_PRODUCTION'], table_name)
460+
check_sql = f'''
461+
select * from {self.default['DBSCHEMA_PRODUCTION']}.{table_name} WHERE "changeset_timestamp"
462+
IS NULL AND "{osm_id_column}" IS NOT NULL
463+
'''
464+
if extra_where:
465+
check_sql += f' AND {extra_where} '
466+
467+
check_sql += f''' ORDER BY "{osm_id_column}"'''
468+
456469
cursor.execute(check_sql)
457470
row = True
458471
while row:
@@ -461,10 +474,15 @@ def process_empty_changeset_from_table(self, table_name, table_columns, osm_id_c
461474
if row:
462475
row = dict(zip(table_columns, row))
463476
row_batch['%s' % row[osm_id_column]] = row
464-
osm_ids.append('%s' % row[osm_id_column])
465-
if len(osm_ids) == 30:
477+
try:
478+
osm_ids.append(f'{abs(row[osm_id_column])}')
479+
except:
480+
osm_ids.append('%s' % row[osm_id_column])
481+
if len(osm_ids) == 20:
466482
self.update_osm_enrich_from_api_in_batch(
467-
osm_ids, osm_type, row_batch, table_name, osm_id_column)
483+
osm_ids, osm_type, row_batch, table_name,
484+
osm_id_column
485+
)
468486
row_batch = {}
469487
osm_ids = []
470488

@@ -484,9 +502,22 @@ def enrich_empty_changeset(self):
484502
osm_type = table_data['osm_type']
485503
columns = table_data['columns']
486504
if osm_id_columnn is not None:
487-
self.info('Checking data from table %s' % table)
488-
self.process_empty_changeset_from_table(
489-
table, columns, osm_id_columnn, osm_type)
505+
if osm_type == 'way':
506+
self.info('Checking data from table %s with type way' % table)
507+
self.process_empty_changeset_from_table(
508+
table, columns, osm_id_columnn, 'way',
509+
extra_where=f'"{osm_id_columnn}" > 0'
510+
)
511+
self.info('Checking data from table %s with type relation' % table)
512+
self.process_empty_changeset_from_table(
513+
table, columns, osm_id_columnn, 'relation',
514+
extra_where=f'"{osm_id_columnn}" < 0'
515+
)
516+
else:
517+
self.info('Checking data from table %s' % table)
518+
self.process_empty_changeset_from_table(
519+
table, columns, osm_id_columnn, osm_type
520+
)
490521
else:
491522
self.info('Does not know osm_id column for %s.' % table)
492523

0 commit comments

Comments
 (0)