Skip to content

Commit 0a5d35f

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

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ build:
1616
@echo "------------------------------------------------------------------"
1717
@echo "Building in production mode"
1818
@echo "------------------------------------------------------------------"
19-
@docker-compose build
19+
@docker-compose build osmenrich
2020

2121
redeploy:
2222
@echo

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: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,25 @@ def process_empty_changeset_from_table(self, table_name, table_columns, osm_id_c
444444
445445
:param osm_id_column: Column name of osm_id
446446
:type osm_id_column: str
447+
448+
:param extra_where: Other where for query
449+
:type extra_where: str
447450
"""
448451
# noinspection PyUnboundLocalVariable
449452
connection = self.create_connection()
450453
cursor = connection.cursor()
451454
row_batch = {}
452455
osm_ids = []
453456
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)
457+
check_sql = f'''
458+
select * from {self.default['DBSCHEMA_PRODUCTION']}.{table_name} WHERE "changeset_timestamp"
459+
IS NULL AND "{osm_id_column}" IS NOT NULL
460+
'''
461+
if extra_where:
462+
check_sql += f' AND {extra_where} '
463+
464+
check_sql += f''' ORDER BY "{osm_id_column}"'''
465+
456466
cursor.execute(check_sql)
457467
row = True
458468
while row:
@@ -461,10 +471,15 @@ def process_empty_changeset_from_table(self, table_name, table_columns, osm_id_c
461471
if row:
462472
row = dict(zip(table_columns, row))
463473
row_batch['%s' % row[osm_id_column]] = row
464-
osm_ids.append('%s' % row[osm_id_column])
465-
if len(osm_ids) == 30:
474+
try:
475+
osm_ids.append(f'{abs(row[osm_id_column])}')
476+
except:
477+
osm_ids.append('%s' % row[osm_id_column])
478+
if len(osm_ids) == 20:
466479
self.update_osm_enrich_from_api_in_batch(
467-
osm_ids, osm_type, row_batch, table_name, osm_id_column)
480+
osm_ids, osm_type, row_batch, table_name,
481+
osm_id_column
482+
)
468483
row_batch = {}
469484
osm_ids = []
470485

@@ -484,9 +499,22 @@ def enrich_empty_changeset(self):
484499
osm_type = table_data['osm_type']
485500
columns = table_data['columns']
486501
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)
502+
if osm_type == 'way':
503+
self.info('Checking data from table %s with type way' % table)
504+
self.process_empty_changeset_from_table(
505+
table, columns, osm_id_columnn, 'way',
506+
extra_where=f'"{osm_id_columnn}" > 0'
507+
)
508+
self.info('Checking data from table %s with type relation' % table)
509+
self.process_empty_changeset_from_table(
510+
table, columns, osm_id_columnn, 'relation',
511+
extra_where=f'"{osm_id_columnn}" < 0'
512+
)
513+
else:
514+
self.info('Checking data from table %s' % table)
515+
self.process_empty_changeset_from_table(
516+
table, columns, osm_id_columnn, osm_type
517+
)
490518
else:
491519
self.info('Does not know osm_id column for %s.' % table)
492520

0 commit comments

Comments
 (0)