X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/1c6f4263635dce309434dc10e622552b1e70308b..82970e2b4f4c5aed5fdd9c3bfc1016ee41afd55f:/nominatim/clicmd/api.py diff --git a/nominatim/clicmd/api.py b/nominatim/clicmd/api.py index e8f1d233..3c5416fe 100644 --- a/nominatim/clicmd/api.py +++ b/nominatim/clicmd/api.py @@ -17,6 +17,7 @@ from nominatim.clicmd.args import NominatimArgs import nominatim.api as napi import nominatim.api.v1 as api_output from nominatim.api.v1.helpers import zoom_to_rank, deduplicate_results +from nominatim.api.v1.format import dispatch as formatting import nominatim.api.logging as loglib # Do not repeat documentation of subcommand classes. @@ -44,7 +45,7 @@ EXTRADATA_PARAMS = ( def _add_api_output_arguments(parser: argparse.ArgumentParser) -> None: group = parser.add_argument_group('Output arguments') group.add_argument('--format', default='jsonv2', - choices=['xml', 'json', 'jsonv2', 'geojson', 'geocodejson', 'debug'], + choices=formatting.list_formats(napi.SearchResults) + ['debug'], help='Format of result') for name, desc in EXTRADATA_PARAMS: group.add_argument('--' + name, action='store_true', help=desc) @@ -109,7 +110,8 @@ class APISearch: 'countries': args.countrycodes, 'excluded': args.exclude_place_ids, 'viewbox': args.viewbox, - 'bounded_viewbox': args.bounded + 'bounded_viewbox': args.bounded, + 'locales': args.get_locales(api.config.DEFAULT_LANGUAGE) } if args.query: @@ -124,9 +126,6 @@ class APISearch: country=args.country, **params) - for result in results: - result.localize(args.get_locales(api.config.DEFAULT_LANGUAGE)) - if args.dedupe and len(results) > 1: results = deduplicate_results(results, args.limit) @@ -187,14 +186,14 @@ class APIReverse: layers=args.get_layers(napi.DataLayer.ADDRESS | napi.DataLayer.POI), address_details=True, # needed for display name geometry_output=args.get_geometry_output(), - geometry_simplification=args.polygon_threshold) + geometry_simplification=args.polygon_threshold, + locales=args.get_locales(api.config.DEFAULT_LANGUAGE)) if args.format == 'debug': print(loglib.get_and_disable()) return 0 if result: - result.localize(args.get_locales(api.config.DEFAULT_LANGUAGE)) output = api_output.format_result( napi.ReverseResults([result]), args.format, @@ -249,10 +248,8 @@ class APILookup: results = api.lookup(places, address_details=True, # needed for display name geometry_output=args.get_geometry_output(), - geometry_simplification=args.polygon_threshold or 0.0) - - for result in results: - result.localize(args.get_locales(api.config.DEFAULT_LANGUAGE)) + geometry_simplification=args.polygon_threshold or 0.0, + locales=args.get_locales(api.config.DEFAULT_LANGUAGE)) output = api_output.format_result( results, @@ -326,6 +323,7 @@ class APIDetails: api = napi.NominatimAPI(args.project_dir) + locales = args.get_locales(api.config.DEFAULT_LANGUAGE) result = api.details(place, address_details=args.addressdetails, linked_places=args.linkedplaces, @@ -333,13 +331,11 @@ class APIDetails: keywords=args.keywords, geometry_output=napi.GeometryFormat.GEOJSON if args.polygon_geojson - else napi.GeometryFormat.NONE) + else napi.GeometryFormat.NONE, + locales=locales) if result: - locales = args.get_locales(api.config.DEFAULT_LANGUAGE) - result.localize(locales) - output = api_output.format_result( result, 'json',