+ def run(args):
+ params = dict(lat=args.lat, lon=args.lon)
+ if args.zoom is not None:
+ params['zoom'] = args.zoom
+
+ for param, _ in EXTRADATA_PARAMS:
+ if getattr(args, param):
+ params[param] = '1'
+ if args.format:
+ params['format'] = args.format
+ if args.lang:
+ params['accept-language'] = args.lang
+ if args.polygon_output:
+ params['polygon_' + args.polygon_output] = '1'
+ if args.polygon_threshold:
+ params['polygon_threshold'] = args.polygon_threshold
+
+ return run_api_script('reverse', args.project_dir,
+ phpcgi_bin=args.phpcgi_path, params=params)
+
+
+class APILookup:
+ """\
+ Execute API reverse query.
+ """
+
+ @staticmethod
+ def add_args(parser):
+ group = parser.add_argument_group('Query arguments')
+ group.add_argument('--id', metavar='OSMID',
+ action='append', required=True, dest='ids',
+ help='OSM id to lookup in format <NRW><id> (may be repeated)')
+
+ _add_api_output_arguments(parser)
+
+
+ @staticmethod
+ def run(args):
+ params = dict(osm_ids=','.join(args.ids))
+
+ for param, _ in EXTRADATA_PARAMS:
+ if getattr(args, param):
+ params[param] = '1'
+ if args.format:
+ params['format'] = args.format
+ if args.lang:
+ params['accept-language'] = args.lang
+ if args.polygon_output:
+ params['polygon_' + args.polygon_output] = '1'
+ if args.polygon_threshold:
+ params['polygon_threshold'] = args.polygon_threshold
+
+ return run_api_script('lookup', args.project_dir,
+ phpcgi_bin=args.phpcgi_path, params=params)
+
+
+class APIDetails:
+ """\
+ Execute API lookup query.
+ """
+
+ @staticmethod
+ def add_args(parser):
+ group = parser.add_argument_group('Query arguments')
+ objs = group.add_mutually_exclusive_group(required=True)
+ objs.add_argument('--node', '-n', type=int,
+ help="Look up the OSM node with the given ID.")
+ objs.add_argument('--way', '-w', type=int,
+ help="Look up the OSM way with the given ID.")
+ objs.add_argument('--relation', '-r', type=int,
+ help="Look up the OSM relation with the given ID.")
+ objs.add_argument('--place_id', '-p', type=int,
+ help='Database internal identifier of the OSM object to look up.')
+ group.add_argument('--class', dest='object_class',
+ help="""Class type to disambiguated multiple entries
+ of the same object.""")
+
+ group = parser.add_argument_group('Output arguments')
+ for name, desc in DETAILS_SWITCHES:
+ group.add_argument('--' + name, action='store_true', help=desc)
+ group.add_argument('--lang', '--accept-language', metavar='LANGS',
+ help='Preferred language order for presenting search results')
+
+ @staticmethod
+ def run(args):
+ if args.node:
+ params = dict(osmtype='N', osmid=args.node)
+ elif args.way:
+ params = dict(osmtype='W', osmid=args.node)
+ elif args.relation:
+ params = dict(osmtype='R', osmid=args.node)
+ else:
+ params = dict(place_id=args.place_id)
+ if args.object_class:
+ params['class'] = args.object_class
+ for name, _ in DETAILS_SWITCHES:
+ params[name] = '1' if getattr(args, name) else '0'
+
+ return run_api_script('details', args.project_dir,
+ phpcgi_bin=args.phpcgi_path, params=params)
+
+
+class APIStatus:
+ """\
+ Execute API status query.
+ """
+
+ @staticmethod
+ def add_args(parser):
+ group = parser.add_argument_group('API parameters')
+ group.add_argument('--format', default='text', choices=['text', 'json'],
+ help='Format of result')
+
+ @staticmethod
+ def run(args):
+ return run_api_script('status', args.project_dir,
+ phpcgi_bin=args.phpcgi_path,
+ params=dict(format=args.format))