2 Function to add additional OSM data from a file or the API into the database.
 
   4 from pathlib import Path
 
   8 from nominatim.tools.exec_utils import run_osm2pgsql, get_url
 
  10 LOG = logging.getLogger()
 
  12 def add_data_from_file(fname, options):
 
  13     """ Adds data from a OSM file to the database. The file may be a normal
 
  14         OSM file or a diff file in all formats supported by libosmium.
 
  16     options['import_file'] = Path(fname)
 
  17     options['append'] = True
 
  18     run_osm2pgsql(options)
 
  20     # No status update. We don't know where the file came from.
 
  24 def add_osm_object(osm_type, osm_id, use_main_api, options):
 
  25     """ Add or update a single OSM object from the latest version of the
 
  29         base_url = f'https://www.openstreetmap.org/api/0.6/{osm_type}/{osm_id}'
 
  30         if osm_type in ('way', 'relation'):
 
  34         if osm_type == 'node':
 
  35             data = f'node({osm_id});out meta;'
 
  36         elif osm_type == 'way':
 
  37             data = f'(way({osm_id});>;);out meta;'
 
  39             data = f'(rel(id:{osm_id});>;);out meta;'
 
  40         base_url = 'https://overpass-api.de/api/interpreter?' \
 
  41                    + urllib.parse.urlencode({'data': data})
 
  43     options['append'] = True
 
  44     options['import_data'] = get_url(base_url).encode('utf-8')
 
  46     run_osm2pgsql(options)