From: Sarah Hoffmann Date: Wed, 27 Jun 2018 20:48:19 +0000 (+0200) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Tag: deploy~320 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/66adbf6a055c877a82fce52767bed7094d0f73a9?hp=77c75ebf0c822816a428da91db56e421796d499b Merge remote-tracking branch 'upstream/master' --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d532bf55..3f06d842 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ set(CUSTOMFILES utils/country_languages.php utils/imports.php utils/importWikipedia.php + utils/export.php utils/query.php utils/server_compare.php utils/setup.php diff --git a/sql/partition-functions.src.sql b/sql/partition-functions.src.sql index 9ae020e4..efb59542 100644 --- a/sql/partition-functions.src.sql +++ b/sql/partition-functions.src.sql @@ -125,7 +125,7 @@ BEGIN ST_Distance(centroid, point) as distance, null as isguess FROM search_name_-partition- WHERE name_vector && isin_token - AND ST_DWithin(centroid, point, 0.03) + AND ST_DWithin(centroid, point, 0.04) AND search_rank between 16 and 22 ORDER BY distance ASC limit 1 LOOP diff --git a/utils/export.php b/utils/export.php new file mode 100755 index 00000000..13f062d4 --- /dev/null +++ b/utils/export.php @@ -0,0 +1,176 @@ +#!/usr/bin/php -Cq + 1, + 'country' => 4, + 'state' => 8, + 'county' => 12, + 'city' => 16, + 'suburb' => 20, + 'street' => 26, + 'path' => 27 + ); + + $oDB =& getDB(); + + if (isset($aCMDResult['output-type'])) { + if (!isset($aRankmap[$aCMDResult['output-type']])) fail('unknown output-type: '.$aCMDResult['output-type']); + $iOutputRank = $aRankmap[$aCMDResult['output-type']]; + } else { + $iOutputRank = $aRankmap['street']; + } + + + // Preferred language + $oParams = new Nominatim\ParameterParser(); + if (!isset($aCMDResult['language'])) $aCMDResult['language'] = 'xx'; + $aLangPrefOrder = $oParams->getPreferredLanguages($aCMDResult['language']); + $sLanguagePrefArraySQL = 'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']'; + + // output formatting: build up a lookup table that maps address ranks to columns + $aColumnMapping = array(); + $iNumCol = 0; + if (!isset($aCMDResult['output-format'])) $aCMDResult['output-format'] = 'street;suburb;city;county;state;country'; + foreach (preg_split('/\s*;\s*/', $aCMDResult['output-format']) as $sColumn) { + $bHasData = false; + foreach (preg_split('/\s*,\s*/', $sColumn) as $sRank) { + if ($sRank == 'postcode' || $sRank == 'placeid') { + $aColumnMapping[$sRank] = $iNumCol; + $bHasData = true; + } elseif (isset($aRankmap[$sRank])) { + $iRank = $aRankmap[$sRank]; + if ($iRank <= $iOutputRank) { + $aColumnMapping[(string)$iRank] = $iNumCol; + $bHasData = true; + } + } + } + if ($bHasData) $iNumCol++; + } + + // build the query for objects + $sPlacexSQL = 'select min(place_id) as place_id, '; + $sPlacexSQL .= 'array_agg(place_id) as place_ids, '; + $sPlacexSQL .= 'country_code as cc, '; + $sPlacexSQL .= 'postcode, '; + // get the address places excluding postcodes + $sPlacexSQL .= 'array(select address_place_id from place_addressline a'; + $sPlacexSQL .= ' where a.place_id = placex.place_id and isaddress'; + $sPlacexSQL .= ' and address_place_id != placex.place_id'; + $sPlacexSQL .= ' and not cached_rank_address in (5,11)'; + $sPlacexSQL .= ' and cached_rank_address > 2 order by cached_rank_address)'; + $sPlacexSQL .= ' as address'; + $sPlacexSQL .= ' from placex where name is not null and linked_place_id is null'; + + $sPlacexSQL .= ' and rank_address = '.$iOutputRank; + + if (isset($aCMDResult['restrict-to-country'])) { + $sPlacexSQL .= ' and country_code = '.getDBQuoted($aCMDResult['restrict-to-country']); + } + + // restriction to parent place id + $sParentId = false; + $sOsmType = false; + + if (isset($aCMDResult['restrict-to-osm-node'])) { + $sOsmType = 'N'; + $sOsmId = $aCMDResult['restrict-to-osm-node']; + } + if (isset($aCMDResult['restrict-to-osm-way'])) { + $sOsmType = 'W'; + $sOsmId = $aCMDResult['restrict-to-osm-way']; + } + if (isset($aCMDResult['restrict-to-osm-relation'])) { + $sOsmType = 'R'; + $sOsmId = $aCMDResult['restrict-to-osm-relation']; + } + if ($sOsmType) { + $sSQL = 'select place_id from placex where'; + $sSQL .= ' osm_type = '.getDBQuoted($sOsmType); + $sSQL .= ' and osm_id = '.$sOsmId; + $sParentId = $oDB->getOne($sSQL); + if (PEAR::isError($sParentId)) fail(pg_last_error($oDB->connection)); + if (!$sParentId) fail('Could not find place '.$sOsmType.' '.$sOsmId); + } + if ($sParentId) { + $sPlacexSQL .= ' and place_id in (select place_id from place_addressline where address_place_id = '.$sParentId.' and isaddress)'; + } + + $sPlacexSQL .= " group by name->'name', address, postcode, country_code, placex.place_id"; + + // Iterate over placeids + // to get further hierarchical information + //var_dump($sPlacexSQL); + $aRes =& $oDB->query($sPlacexSQL); + if (PEAR::isError($aRes)) fail(pg_last_error($oDB->connection)); + $fOutstream = fopen('php://output', 'w'); + while ($aRes->fetchInto($aRow)) { + //var_dump($aRow); + $iPlaceID = $aRow['place_id']; + $sSQL = "select rank_address,get_name_by_language(name,$sLanguagePrefArraySQL) as localname from get_addressdata($iPlaceID, -1)"; + $sSQL .= ' WHERE isaddress'; + $sSQL .= ' order by rank_address desc,isaddress desc'; + $aAddressLines = $oDB->getAll($sSQL); + if (PEAR::IsError($aAddressLines)) fail(pg_last_error($oDB->connection)); + + + $aOutput = array_fill(0, $iNumCol, ''); + // output address parts + foreach ($aAddressLines as $aAddress) { + if (isset($aColumnMapping[$aAddress['rank_address']])) { + $aOutput[$aColumnMapping[$aAddress['rank_address']]] = $aAddress['localname']; + } + } + // output postcode + if (isset($aColumnMapping['postcode'])) { + if ($aCMDResult['output-all-postcodes']) { + $sSQL = 'select array_agg(px.postcode) from placex px join place_addressline pa '; + $sSQL .= 'on px.place_id = pa.address_place_id '; + $sSQL .= 'where pa.cached_rank_address in (5,11) '; + $sSQL .= 'and pa.place_id in (select place_id from place_addressline where address_place_id in ('.substr($aRow['place_ids'], 1, -1).')) '; + $sSQL .= 'group by postcode order by count(*) desc limit 1'; + $sRes = $oDB->getOne($sSQL); + if (PEAR::IsError($sRes)) fail(pg_last_error($oDB->connection)); + $aOutput[$aColumnMapping['postcode']] = substr($sRes, 1, -1); + } else { + $aOutput[$aColumnMapping['postcode']] = $aRow['postcode']; + } + } + if (isset($aColumnMapping['placeid'])) { + $aOutput[$aColumnMapping['placeid']] = substr($aRow['place_ids'], 1, -1); + } + fputcsv($fOutstream, $aOutput); + } + fclose($fOutstream); diff --git a/utils/setup.php b/utils/setup.php index 259ddf2d..a7f77e55 100755 --- a/utils/setup.php +++ b/utils/setup.php @@ -61,8 +61,8 @@ if ($aCMDResult['import-data'] || $aCMDResult['all']) { } -// This is a pretty hard core default - the number of processors in the box - 1 -$iInstances = isset($aCMDResult['threads'])?$aCMDResult['threads']:(getProcessorCount()-1); +// by default, use all but one processor, but never more than 15. +$iInstances = isset($aCMDResult['threads'])?$aCMDResult['threads']:(min(16,getProcessorCount())-1); if ($iInstances < 1) { $iInstances = 1; warn("resetting threads to $iInstances");