1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Implementation of the 'add-data' subcommand.
14 # Do not repeat documentation of subcommand classes.
15 # pylint: disable=C0111
16 # Using non-top-level imports to avoid eventually unused imports.
17 # pylint: disable=E0012,C0415
19 LOG = logging.getLogger()
23 Add additional data from a file or an online source.
25 This command allows to add or update the search data in the database.
26 The data can come either from an OSM file or single OSM objects can
27 directly be downloaded from the OSM API. This function only loads the
28 data into the database. Afterwards it still needs to be integrated
29 in the search index. Use the `nominatim index` command for that.
31 The command can also be used to add external non-OSM data to the
32 database. At the moment the only supported format is TIGER housenumber
33 data. See the online documentation at
34 https://nominatim.org/release-docs/latest/admin/Import/#installing-tiger-housenumber-data-for-the-us
40 group_name = parser.add_argument_group('Source')
41 group = group_name.add_mutually_exclusive_group(required=True)
42 group.add_argument('--file', metavar='FILE',
43 help='Import data from an OSM file or diff file')
44 group.add_argument('--diff', metavar='FILE',
45 help='Import data from an OSM diff file (deprecated: use --file)')
46 group.add_argument('--node', metavar='ID', type=int,
47 help='Import a single node from the API')
48 group.add_argument('--way', metavar='ID', type=int,
49 help='Import a single way from the API')
50 group.add_argument('--relation', metavar='ID', type=int,
51 help='Import a single relation from the API')
52 group.add_argument('--tiger-data', metavar='DIR',
53 help='Add housenumbers from the US TIGER census database')
54 group = parser.add_argument_group('Extra arguments')
55 group.add_argument('--use-main-api', action='store_true',
56 help='Use OSM API instead of Overpass to download objects')
57 group.add_argument('--osm2pgsql-cache', metavar='SIZE', type=int,
58 help='Size of cache to be used by osm2pgsql (in MB)')
59 group.add_argument('--socket-timeout', dest='socket_timeout', type=int, default=60,
60 help='Set timeout for file downloads')
64 from nominatim.tokenizer import factory as tokenizer_factory
65 from nominatim.tools import tiger_data, add_osm_data
68 tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
69 return tiger_data.add_tiger_data(args.tiger_data,
71 args.threads or psutil.cpu_count() or 1,
74 osm2pgsql_params = args.osm2pgsql_options(default_cache=1000, default_threads=1)
75 if args.file or args.diff:
76 return add_osm_data.add_data_from_file(args.file or args.diff,
80 return add_osm_data.add_osm_object('node', args.node,
85 return add_osm_data.add_osm_object('way', args.way,
90 return add_osm_data.add_osm_object('relation', args.relation,