3 require_once(CONST_BasePath.'/lib/init-cmd.php');
4 require_once(CONST_BasePath.'/lib/Geocode.php');
5 require_once(CONST_BasePath.'/lib/ParameterParser.php');
6 ini_set('memory_limit', '800M');
10 'Query database from command line. Returns search result as JSON.',
11 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
12 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
13 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
15 array('search', '', 0, 1, 1, 1, 'string', 'Search for given term or coordinate'),
17 array('accept-language', '', 0, 1, 1, 1, 'string', 'Preferred language order for showing search results'),
18 array('bounded', '', 0, 1, 0, 0, 'bool', 'Restrict results to given viewbox'),
19 array('nodedupe', '', 0, 1, 0, 0, 'bool', 'Do not remove duplicate results'),
20 array('limit', '', 0, 1, 1, 1, 'int', 'Maximum number of results returned (default: 10)'),
21 array('exclude_place_ids', '', 0, 1, 1, 1, 'string', 'Comma-separated list of place ids to exclude from results'),
22 array('featureType', '', 0, 1, 1, 1, 'string', 'Restrict results to certain features (country, state,city,settlement)'),
23 array('countrycodes', '', 0, 1, 1, 1, 'string', 'Comma-separated list of countries to restrict search to'),
24 array('viewbox', '', 0, 1, 1, 1, 'string', 'Prefer results in given view box')
26 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
29 $oParams = new Nominatim\ParameterParser($aCMDResult);
31 if ($oParams->getBool('search')) {
32 if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false';
34 $oGeocode = new Nominatim\Geocode($oDB);
36 $oGeocode->setLanguagePreference($oParams->getPreferredLanguages(false));
37 $oGeocode->loadParamArray($oParams);
38 $oGeocode->setQuery($aCMDResult['search']);
40 $aSearchResults = $oGeocode->lookup();
42 if (version_compare(phpversion(), '5.4.0', '<')) {
43 echo json_encode($aSearchResults);
45 echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
48 showUsage($aCMDOptions, true);