]> git.openstreetmap.org Git - nominatim.git/blob - utils/query.php
for search,details in format=HTML return geometry in geojson, not wkt. No longer...
[nominatim.git] / utils / query.php
1 #!/usr/bin/php -Cq
2 <?php
3
4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-cmd.php');
6 require_once(CONST_BasePath.'/lib/Geocode.php');
7 require_once(CONST_BasePath.'/lib/ParameterParser.php');
8 ini_set('memory_limit', '800M');
9
10 $aCMDOptions
11 = array(
12    "Query database from command line. Returns search result as JSON.",
13    array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
14    array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
15    array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
16
17    array('search', '', 0, 1, 1, 1, 'string', 'Search for given term or coordinate'),
18
19    array('accept-language', '', 0, 1, 1, 1, 'string', 'Preferred language order for showing search results'),
20    array('bounded', '', 0, 1, 0, 0, 'bool', 'Restrict results to given viewbox'),
21    array('nodedupe', '', 0, 1, 0, 0, 'bool', 'Do not remove duplicate results'),
22    array('limit', '', 0, 1, 1, 1, 'int', 'Maximum number of results returned (default: 10)'),
23    array('exclude_place_ids', '', 0, 1, 1, 1, 'string', 'Comma-separated list of place ids to exclude from results'),
24    array('featureType', '', 0, 1, 1, 1, 'string', 'Restrict results to certain features (country, state,city,settlement)'),
25    array('countrycodes', '', 0, 1, 1, 1, 'string', 'Comma-separated list of countries to restrict search to'),
26    array('viewbox', '', 0, 1, 1, 1, 'string', 'Prefer results in given view box')
27   );
28 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
29
30 $oDB =& getDB();
31 $oParams = new Nominatim\ParameterParser($aCMDResult);
32
33 if ($oParams->getBool('search')) {
34     if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false';
35
36     $oGeocode = new Nominatim\Geocode($oDB);
37
38     $oGeocode->setLanguagePreference($oParams->getPreferredLanguages(false));
39     $oGeocode->loadParamArray($oParams);
40     $oGeocode->setQuery($aCMDResult['search']);
41
42     $aSearchResults = $oGeocode->lookup();
43
44     if (version_compare(phpversion(), "5.4.0", '<')) {
45         echo json_encode($aSearchResults);
46     } else {
47         echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
48     }
49 } else {
50     showUsage($aCMDOptions, true);
51 }