bracket spacing for if/else/for/foreach/while/switch according to PSR2 standard

This commit is contained in:
marc tobias
2016-09-08 02:16:22 +01:00
parent effd8e12af
commit f05ea577f4
30 changed files with 986 additions and 1505 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -11,8 +11,7 @@ class ParameterParser
function getBool($sName, $bDefault=false) function getBool($sName, $bDefault=false)
{ {
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
{
return $bDefault; return $bDefault;
} }
@@ -21,13 +20,11 @@ class ParameterParser
function getInt($sName, $bDefault=false) function getInt($sName, $bDefault=false)
{ {
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
{
return $bDefault; return $bDefault;
} }
if (!preg_match('/^[+-]?[0-9]+$/', $this->aParams[$sName])) if (!preg_match('/^[+-]?[0-9]+$/', $this->aParams[$sName])) {
{
userError("Integer number expected for parameter '$sName'"); userError("Integer number expected for parameter '$sName'");
} }
@@ -36,13 +33,11 @@ class ParameterParser
function getFloat($sName, $bDefault=false) function getFloat($sName, $bDefault=false)
{ {
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
{
return $bDefault; return $bDefault;
} }
if (!preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $this->aParams[$sName])) if (!preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $this->aParams[$sName])) {
{
userError("Floating-point number expected for parameter '$sName'"); userError("Floating-point number expected for parameter '$sName'");
} }
@@ -51,8 +46,7 @@ class ParameterParser
function getString($sName, $bDefault=false) function getString($sName, $bDefault=false)
{ {
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
{
return $bDefault; return $bDefault;
} }
@@ -61,13 +55,11 @@ class ParameterParser
function getSet($sName, $aValues, $sDefault=false) function getSet($sName, $aValues, $sDefault=false)
{ {
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
{
return $sDefault; return $sDefault;
} }
if (!in_array($this->aParams[$sName], $aValues)) if (!in_array($this->aParams[$sName], $aValues)) {
{
userError("Parameter '$sName' must be one of: ".join(', ', $aValues)); userError("Parameter '$sName' must be one of: ".join(', ', $aValues));
} }
@@ -78,8 +70,7 @@ class ParameterParser
{ {
$sValue = $this->getString($sName); $sValue = $this->getString($sName);
if ($sValue) if ($sValue) {
{
return explode(',', $sValue); return explode(',', $sValue);
} }
@@ -88,41 +79,34 @@ class ParameterParser
function getPreferredLanguages($sFallback=NULL) function getPreferredLanguages($sFallback=NULL)
{ {
if ($sFallback === NULL && isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) if ($sFallback === NULL && isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
{
$sFallback = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; $sFallback = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
} }
$aLanguages = array(); $aLanguages = array();
$sLangString = $this->getString('accept-language', $sFallback); $sLangString = $this->getString('accept-language', $sFallback);
if ($sLangString) if ($sLangString) {
{ if (preg_match_all('/(([a-z]{1,8})(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $sLangString, $aLanguagesParse, PREG_SET_ORDER)) {
if (preg_match_all('/(([a-z]{1,8})(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $sLangString, $aLanguagesParse, PREG_SET_ORDER)) foreach ($aLanguagesParse as $iLang => $aLanguage) {
{
foreach($aLanguagesParse as $iLang => $aLanguage)
{
$aLanguages[$aLanguage[1]] = isset($aLanguage[5])?(float)$aLanguage[5]:1 - ($iLang/100); $aLanguages[$aLanguage[1]] = isset($aLanguage[5])?(float)$aLanguage[5]:1 - ($iLang/100);
if (!isset($aLanguages[$aLanguage[2]])) $aLanguages[$aLanguage[2]] = $aLanguages[$aLanguage[1]]/10; if (!isset($aLanguages[$aLanguage[2]])) $aLanguages[$aLanguage[2]] = $aLanguages[$aLanguage[1]]/10;
} }
arsort($aLanguages); arsort($aLanguages);
} }
} }
if (!sizeof($aLanguages) && CONST_Default_Language) if (!sizeof($aLanguages) && CONST_Default_Language) {
{
$aLanguages[CONST_Default_Language] = 1; $aLanguages[CONST_Default_Language] = 1;
} }
foreach($aLanguages as $sLanguage => $fLanguagePref) foreach ($aLanguages as $sLanguage => $fLanguagePref) {
{
$aLangPrefOrder['short_name:'.$sLanguage] = 'short_name:'.$sLanguage; $aLangPrefOrder['short_name:'.$sLanguage] = 'short_name:'.$sLanguage;
$aLangPrefOrder['name:'.$sLanguage] = 'name:'.$sLanguage; $aLangPrefOrder['name:'.$sLanguage] = 'name:'.$sLanguage;
} }
$aLangPrefOrder['short_name'] = 'short_name'; $aLangPrefOrder['short_name'] = 'short_name';
$aLangPrefOrder['name'] = 'name'; $aLangPrefOrder['name'] = 'name';
$aLangPrefOrder['brand'] = 'brand'; $aLangPrefOrder['brand'] = 'brand';
foreach($aLanguages as $sLanguage => $fLanguagePref) foreach ($aLanguages as $sLanguage => $fLanguagePref) {
{
$aLangPrefOrder['official_name:'.$sLanguage] = 'official_name:'.$sLanguage; $aLangPrefOrder['official_name:'.$sLanguage] = 'official_name:'.$sLanguage;
} }
$aLangPrefOrder['official_name'] = 'official_name'; $aLangPrefOrder['official_name'] = 'official_name';

View File

@@ -100,8 +100,7 @@ class PlaceLookup
$bIsTiger = CONST_Use_US_Tiger_Data && $sType == 'tiger'; $bIsTiger = CONST_Use_US_Tiger_Data && $sType == 'tiger';
$bIsInterpolation = $sType == 'interpolation'; $bIsInterpolation = $sType == 'interpolation';
if ($bIsTiger) if ($bIsTiger) {
{
$sSQL = "select place_id,partition, 'T' as osm_type, place_id as osm_id, 'place' as class, 'house' as type, null as admin_level, housenumber, null as street, null as isin, postcode,"; $sSQL = "select place_id,partition, 'T' as osm_type, place_id as osm_id, 'place' as class, 'house' as type, null as admin_level, housenumber, null as street, null as isin, postcode,";
$sSQL .= " 'us' as country_code, parent_place_id, null as linked_place_id, 30 as rank_address, 30 as rank_search,"; $sSQL .= " 'us' as country_code, parent_place_id, null as linked_place_id, 30 as rank_address, 30 as rank_search,";
$sSQL .= " coalesce(null,0.75-(30::float/40)) as importance, null as indexed_status, null as indexed_date, null as wikipedia, 'us' as calculated_country_code, "; $sSQL .= " coalesce(null,0.75-(30::float/40)) as importance, null as indexed_status, null as indexed_date, null as wikipedia, 'us' as calculated_country_code, ";
@@ -117,9 +116,7 @@ class PlaceLookup
$sSQL .= " WHEN interpolationtype='all' THEN (".$fInterpolFraction."*(endnumber-startnumber)+startnumber)::int"; $sSQL .= " WHEN interpolationtype='all' THEN (".$fInterpolFraction."*(endnumber-startnumber)+startnumber)::int";
$sSQL .= " END as housenumber"; $sSQL .= " END as housenumber";
$sSQL .= " from location_property_tiger where place_id = ".$iPlaceID.") as blub1) as blub2"; $sSQL .= " from location_property_tiger where place_id = ".$iPlaceID.") as blub1) as blub2";
} } else if ($bIsInterpolation) {
else if ($bIsInterpolation)
{
$sSQL = "select place_id, partition, 'W' as osm_type, osm_id, 'place' as class, 'house' as type, null admin_level, housenumber, null as street, null as isin, postcode,"; $sSQL = "select place_id, partition, 'W' as osm_type, osm_id, 'place' as class, 'house' as type, null admin_level, housenumber, null as street, null as isin, postcode,";
$sSQL .= " calculated_country_code as country_code, parent_place_id, null as linked_place_id, 30 as rank_address, 30 as rank_search,"; $sSQL .= " calculated_country_code as country_code, parent_place_id, null as linked_place_id, 30 as rank_address, 30 as rank_search,";
$sSQL .= " (0.75-(30::float/40)) as importance, null as indexed_status, null as indexed_date, null as wikipedia, calculated_country_code, "; $sSQL .= " (0.75-(30::float/40)) as importance, null as indexed_status, null as indexed_date, null as wikipedia, calculated_country_code, ";
@@ -138,9 +135,7 @@ class PlaceLookup
// testcase: interpolationtype=odd, startnumber=1000, endnumber=1006, fInterpolFraction=1 => housenumber=1007 => error in st_lineinterpolatepoint // testcase: interpolationtype=odd, startnumber=1000, endnumber=1006, fInterpolFraction=1 => housenumber=1007 => error in st_lineinterpolatepoint
// but this will never happen, because if the searched point is that close to the endnumber, the endnumber house will be directly taken from placex (in ReverseGeocode.php line 220) // but this will never happen, because if the searched point is that close to the endnumber, the endnumber house will be directly taken from placex (in ReverseGeocode.php line 220)
// and not interpolated // and not interpolated
} } else {
else
{
$sSQL = "select placex.place_id, partition, osm_type, osm_id, class, type, admin_level, housenumber, street, isin, postcode, country_code, parent_place_id, linked_place_id, rank_address, rank_search, "; $sSQL = "select placex.place_id, partition, osm_type, osm_id, class, type, admin_level, housenumber, street, isin, postcode, country_code, parent_place_id, linked_place_id, rank_address, rank_search, ";
$sSQL .= " coalesce(importance,0.75-(rank_search::float/40)) as importance, indexed_status, indexed_date, wikipedia, calculated_country_code, "; $sSQL .= " coalesce(importance,0.75-(rank_search::float/40)) as importance, indexed_status, indexed_date, wikipedia, calculated_country_code, ";
$sSQL .= " get_address_by_language(place_id, -1, $sLanguagePrefArraySQL) as langaddress,"; $sSQL .= " get_address_by_language(place_id, -1, $sLanguagePrefArraySQL) as langaddress,";
@@ -157,34 +152,25 @@ class PlaceLookup
if (!$aPlace['place_id']) return null; if (!$aPlace['place_id']) return null;
if ($this->bAddressDetails) if ($this->bAddressDetails) {
{
// to get addressdetails for tiger data, the housenumber is needed // to get addressdetails for tiger data, the housenumber is needed
$iHousenumber = ($bIsTiger || $bIsInterpolation) ? $aPlace['housenumber'] : -1; $iHousenumber = ($bIsTiger || $bIsInterpolation) ? $aPlace['housenumber'] : -1;
$aPlace['aAddress'] = $this->getAddressNames($aPlace['place_id'], $aPlace['aAddress'] = $this->getAddressNames($aPlace['place_id'],
$iHousenumber); $iHousenumber);
} }
if ($this->bExtraTags) if ($this->bExtraTags) {
{ if ($aPlace['extra']) {
if ($aPlace['extra'])
{
$aPlace['sExtraTags'] = json_decode($aPlace['extra']); $aPlace['sExtraTags'] = json_decode($aPlace['extra']);
} } else {
else
{
$aPlace['sExtraTags'] = (object) array(); $aPlace['sExtraTags'] = (object) array();
} }
} }
if ($this->bNameDetails) if ($this->bNameDetails) {
{ if ($aPlace['names']) {
if ($aPlace['names'])
{
$aPlace['sNameDetails'] = json_decode($aPlace['names']); $aPlace['sNameDetails'] = json_decode($aPlace['names']);
} } else {
else
{
$aPlace['sNameDetails'] = (object) array(); $aPlace['sNameDetails'] = (object) array();
} }
} }
@@ -192,12 +178,9 @@ class PlaceLookup
$aClassType = getClassTypes(); $aClassType = getClassTypes();
$sAddressType = ''; $sAddressType = '';
$sClassType = $aPlace['class'].':'.$aPlace['type'].':'.$aPlace['admin_level']; $sClassType = $aPlace['class'].':'.$aPlace['type'].':'.$aPlace['admin_level'];
if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel'])) if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel'])) {
{
$sAddressType = $aClassType[$aClassType]['simplelabel']; $sAddressType = $aClassType[$aClassType]['simplelabel'];
} } else {
else
{
$sClassType = $aPlace['class'].':'.$aPlace['type']; $sClassType = $aPlace['class'].':'.$aPlace['type'];
if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel'])) if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel']))
$sAddressType = $aClassType[$sClassType]['simplelabel']; $sAddressType = $aClassType[$sClassType]['simplelabel'];
@@ -227,28 +210,24 @@ class PlaceLookup
$aAddress = array(); $aAddress = array();
$aFallback = array(); $aFallback = array();
$aClassType = getClassTypes(); $aClassType = getClassTypes();
foreach($aAddressLines as $aLine) foreach ($aAddressLines as $aLine) {
{
$bFallback = false; $bFallback = false;
$aTypeLabel = false; $aTypeLabel = false;
if (isset($aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']])) $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']]; if (isset($aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']])) {
elseif (isset($aClassType[$aLine['class'].':'.$aLine['type']])) $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type']]; $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']];
elseif (isset($aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))])) } elseif (isset($aClassType[$aLine['class'].':'.$aLine['type']])) {
{ $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type']];
} elseif (isset($aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))])) {
$aTypeLabel = $aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))]; $aTypeLabel = $aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))];
$bFallback = true; $bFallback = true;
} } else {
else
{
$aTypeLabel = array('simplelabel'=>'address'.$aLine['rank_address']); $aTypeLabel = array('simplelabel'=>'address'.$aLine['rank_address']);
$bFallback = true; $bFallback = true;
} }
if ($aTypeLabel && ((isset($aLine['localname']) && $aLine['localname']) || (isset($aLine['housenumber']) && $aLine['housenumber']))) if ($aTypeLabel && ((isset($aLine['localname']) && $aLine['localname']) || (isset($aLine['housenumber']) && $aLine['housenumber']))) {
{
$sTypeLabel = strtolower(isset($aTypeLabel['simplelabel'])?$aTypeLabel['simplelabel']:$aTypeLabel['label']); $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel'])?$aTypeLabel['simplelabel']:$aTypeLabel['label']);
$sTypeLabel = str_replace(' ','_',$sTypeLabel); $sTypeLabel = str_replace(' ','_',$sTypeLabel);
if (!isset($aAddress[$sTypeLabel]) || (isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel]) || $aLine['class'] == 'place') if (!isset($aAddress[$sTypeLabel]) || (isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel]) || $aLine['class'] == 'place') {
{
$aAddress[$sTypeLabel] = $aLine['localname']?$aLine['localname']:$aLine['housenumber']; $aAddress[$sTypeLabel] = $aLine['localname']?$aLine['localname']:$aLine['housenumber'];
} }
$aFallback[$sTypeLabel] = $bFallback; $aFallback[$sTypeLabel] = $bFallback;
@@ -274,8 +253,7 @@ class PlaceLookup
$aOutlineResult = array(); $aOutlineResult = array();
if (!$iPlaceID) return $aOutlineResult; if (!$iPlaceID) return $aOutlineResult;
if (CONST_Search_AreaPolygons) if (CONST_Search_AreaPolygons) {
{
// Get the bounding box and outline polygon // Get the bounding box and outline polygon
$sSQL = "select place_id,0 as numfeatures,st_area(geometry) as area,"; $sSQL = "select place_id,0 as numfeatures,st_area(geometry) as area,";
$sSQL .= "ST_Y(centroid) as centrelat,ST_X(centroid) as centrelon,"; $sSQL .= "ST_Y(centroid) as centrelat,ST_X(centroid) as centrelon,";
@@ -286,22 +264,17 @@ class PlaceLookup
if ($this->bIncludePolygonAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg"; if ($this->bIncludePolygonAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg";
if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ",ST_AsText(geometry) as astext"; if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ",ST_AsText(geometry) as astext";
$sFrom = " from placex where place_id = ".$iPlaceID; $sFrom = " from placex where place_id = ".$iPlaceID;
if ($this->fPolygonSimplificationThreshold > 0) if ($this->fPolygonSimplificationThreshold > 0) {
{
$sSQL .= " from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,".$this->fPolygonSimplificationThreshold.") as geometry".$sFrom.") as plx"; $sSQL .= " from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,".$this->fPolygonSimplificationThreshold.") as geometry".$sFrom.") as plx";
} } else {
else
{
$sSQL .= $sFrom; $sSQL .= $sFrom;
} }
$aPointPolygon = chksql($this->oDB->getRow($sSQL), $aPointPolygon = chksql($this->oDB->getRow($sSQL),
"Could not get outline"); "Could not get outline");
if ($aPointPolygon['place_id']) if ($aPointPolygon['place_id']) {
{ if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) {
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null )
{
$aOutlineResult['lat'] = $aPointPolygon['centrelat']; $aOutlineResult['lat'] = $aPointPolygon['centrelat'];
$aOutlineResult['lon'] = $aPointPolygon['centrelon']; $aOutlineResult['lon'] = $aPointPolygon['centrelon'];
} }
@@ -313,13 +286,12 @@ class PlaceLookup
if ($this->bIncludePolygonAsPoints) $aOutlineResult['aPolyPoints'] = geometryText2Points($aPointPolygon['astext'], $fRadius); if ($this->bIncludePolygonAsPoints) $aOutlineResult['aPolyPoints'] = geometryText2Points($aPointPolygon['astext'], $fRadius);
if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) {
{
$aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius; $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
$aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius; $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
} }
if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001)
{ if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) {
$aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius; $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
$aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius; $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
} }
@@ -334,11 +306,9 @@ class PlaceLookup
} // CONST_Search_AreaPolygons } // CONST_Search_AreaPolygons
// as a fallback we generate a bounding box without knowing the size of the geometry // as a fallback we generate a bounding box without knowing the size of the geometry
if ( (!isset($aOutlineResult['aBoundingBox'])) && isset($fLon) ) if ((!isset($aOutlineResult['aBoundingBox'])) && isset($fLon)) {
{ //
if ($this->bIncludePolygonAsPoints) {
if ($this->bIncludePolygonAsPoints)
{
$sGeometryText = 'POINT('.$fLon.','.$fLat.')'; $sGeometryText = 'POINT('.$fLon.','.$fLat.')';
$aOutlineResult['aPolyPoints'] = geometryText2Points($sGeometryText, $fRadius); $aOutlineResult['aPolyPoints'] = geometryText2Points($sGeometryText, $fRadius);
} }

View File

@@ -53,8 +53,7 @@ class ReverseGeocode
$bIsInUnitedStates = false; $bIsInUnitedStates = false;
$bPlaceIsTiger = false; $bPlaceIsTiger = false;
$bPlaceIsLine = false; $bPlaceIsLine = false;
while(!$iPlaceID && $fSearchDiam < $fMaxAreaDistance) while (!$iPlaceID && $fSearchDiam < $fMaxAreaDistance) {
{
$fSearchDiam = $fSearchDiam * 2; $fSearchDiam = $fSearchDiam * 2;
// If we have to expand the search area by a large amount then we need a larger feature // If we have to expand the search area by a large amount then we need a larger feature
@@ -86,8 +85,7 @@ class ReverseGeocode
$bIsInUnitedStates = ($aPlace['calculated_country_code'] == 'us'); $bIsInUnitedStates = ($aPlace['calculated_country_code'] == 'us');
} }
// if a street or house was found, look in interpolation lines table // if a street or house was found, look in interpolation lines table
if ($bDoInterpolation && $this->iMaxRank >= 28 && $aPlace && $aPlace['rank_search'] >= 26) if ($bDoInterpolation && $this->iMaxRank >= 28 && $aPlace && $aPlace['rank_search'] >= 26) {
{
// if a house was found, search the interpolation line that is at least as close as the house // if a house was found, search the interpolation line that is at least as close as the house
$sSQL = 'SELECT place_id, parent_place_id, 30 as rank_search, ST_line_locate_point(linegeo,'.$sPointSQL.') as fraction'; $sSQL = 'SELECT place_id, parent_place_id, 30 as rank_search, ST_line_locate_point(linegeo,'.$sPointSQL.') as fraction';
$sSQL .= ' FROM location_property_osmline'; $sSQL .= ' FROM location_property_osmline';
@@ -95,24 +93,20 @@ class ReverseGeocode
$sSQL .= ' and indexed_status = 0 '; $sSQL .= ' and indexed_status = 0 ';
$sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', linegeo) ASC limit 1'; $sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', linegeo) ASC limit 1';
if (CONST_Debug) if (CONST_Debug) {
{
$sSQL = preg_replace('/limit 1/', 'limit 100', $sSQL); $sSQL = preg_replace('/limit 1/', 'limit 100', $sSQL);
var_dump($sSQL); var_dump($sSQL);
$aAllHouses = chksql($this->oDB->getAll($sSQL)); $aAllHouses = chksql($this->oDB->getAll($sSQL));
foreach($aAllHouses as $i) foreach ($aAllHouses as $i) {
{
echo $i['housenumber'] . ' | ' . $i['distance'] * 1000 . ' | ' . $i['lat'] . ' | ' . $i['lon']. ' | '. "<br>\n"; echo $i['housenumber'] . ' | ' . $i['distance'] * 1000 . ' | ' . $i['lat'] . ' | ' . $i['lon']. ' | '. "<br>\n";
} }
} }
$aPlaceLine = chksql($this->oDB->getRow($sSQL), $aPlaceLine = chksql($this->oDB->getRow($sSQL),
"Could not determine closest housenumber on an osm interpolation line."); "Could not determine closest housenumber on an osm interpolation line.");
if ($aPlaceLine) if ($aPlaceLine) {
{
if (CONST_Debug) var_dump('found housenumber in interpolation lines table', $aPlaceLine); if (CONST_Debug) var_dump('found housenumber in interpolation lines table', $aPlaceLine);
if ($aPlace['rank_search'] == 30) if ($aPlace['rank_search'] == 30) {
{
// if a house was already found in placex, we have to find out, // if a house was already found in placex, we have to find out,
// if the placex house or the interpolated house are closer to the searched point // if the placex house or the interpolated house are closer to the searched point
// distance between point and placex house // distance between point and placex house
@@ -126,8 +120,7 @@ class ReverseGeocode
$aDistanceInterpolation = chksql($this->oDB->getRow($sSQL), $aDistanceInterpolation = chksql($this->oDB->getRow($sSQL),
"Could not determine distance between searched point and interpolated house."); "Could not determine distance between searched point and interpolated house.");
$fDistanceInterpolation = $aDistanceInterpolation['distance']; $fDistanceInterpolation = $aDistanceInterpolation['distance'];
if ($fDistanceInterpolation < $fDistancePlacex) if ($fDistanceInterpolation < $fDistancePlacex) {
{
// interpolation is closer to point than placex house // interpolation is closer to point than placex house
$bPlaceIsLine = true; $bPlaceIsLine = true;
$aPlace = $aPlaceLine; $aPlace = $aPlaceLine;
@@ -137,9 +130,7 @@ class ReverseGeocode
$iMaxRank = 30; $iMaxRank = 30;
} }
// else: nothing to do, take placex house from above // else: nothing to do, take placex house from above
} } else {
else
{
$bPlaceIsLine = true; $bPlaceIsLine = true;
$aPlace = $aPlaceLine; $aPlace = $aPlaceLine;
$iPlaceID = $aPlaceLine['place_id']; $iPlaceID = $aPlaceLine['place_id'];
@@ -151,8 +142,7 @@ class ReverseGeocode
} }
// Only street found? If it's in the US we can check TIGER data for nearest housenumber // Only street found? If it's in the US we can check TIGER data for nearest housenumber
if (CONST_Use_US_Tiger_Data && $bDoInterpolation && $bIsInUnitedStates && $this->iMaxRank >= 28 && $iPlaceID && ($aPlace['rank_search'] == 26 || $aPlace['rank_search'] == 27 )) if (CONST_Use_US_Tiger_Data && $bDoInterpolation && $bIsInUnitedStates && $this->iMaxRank >= 28 && $iPlaceID && ($aPlace['rank_search'] == 26 || $aPlace['rank_search'] == 27 )) {
{
$fSearchDiam = 0.001; $fSearchDiam = 0.001;
$sSQL = 'SELECT place_id,parent_place_id,30 as rank_search, ST_line_locate_point(linegeo,'.$sPointSQL.') as fraction'; $sSQL = 'SELECT place_id,parent_place_id,30 as rank_search, ST_line_locate_point(linegeo,'.$sPointSQL.') as fraction';
//if (CONST_Debug) { $sSQL .= ', housenumber, ST_distance('.$sPointSQL.', centroid) as distance, st_y(centroid) as lat, st_x(centroid) as lon'; } //if (CONST_Debug) { $sSQL .= ', housenumber, ST_distance('.$sPointSQL.', centroid) as distance, st_y(centroid) as lat, st_x(centroid) as lon'; }
@@ -160,22 +150,19 @@ class ReverseGeocode
$sSQL .= ' AND ST_DWithin('.$sPointSQL.', linegeo, '.$fSearchDiam.')'; //no centroid anymore in Tiger data, now we have lines $sSQL .= ' AND ST_DWithin('.$sPointSQL.', linegeo, '.$fSearchDiam.')'; //no centroid anymore in Tiger data, now we have lines
$sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', linegeo) ASC limit 1'; $sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', linegeo) ASC limit 1';
if (CONST_Debug) if (CONST_Debug) {
{
$sSQL = preg_replace('/limit 1/', 'limit 100', $sSQL); $sSQL = preg_replace('/limit 1/', 'limit 100', $sSQL);
var_dump($sSQL); var_dump($sSQL);
$aAllHouses = chksql($this->oDB->getAll($sSQL)); $aAllHouses = chksql($this->oDB->getAll($sSQL));
foreach($aAllHouses as $i) foreach ($aAllHouses as $i) {
{
echo $i['housenumber'] . ' | ' . $i['distance'] * 1000 . ' | ' . $i['lat'] . ' | ' . $i['lon']. ' | '. "<br>\n"; echo $i['housenumber'] . ' | ' . $i['distance'] * 1000 . ' | ' . $i['lat'] . ' | ' . $i['lon']. ' | '. "<br>\n";
} }
} }
$aPlaceTiger = chksql($this->oDB->getRow($sSQL), $aPlaceTiger = chksql($this->oDB->getRow($sSQL),
"Could not determine closest Tiger place."); "Could not determine closest Tiger place.");
if ($aPlaceTiger) if ($aPlaceTiger) {
{
if (CONST_Debug) var_dump('found Tiger housenumber', $aPlaceTiger); if (CONST_Debug) var_dump('found Tiger housenumber', $aPlaceTiger);
$bPlaceIsTiger = true; $bPlaceIsTiger = true;
$aPlace = $aPlaceTiger; $aPlace = $aPlaceTiger;
@@ -187,10 +174,8 @@ class ReverseGeocode
} }
// The point we found might be too small - use the address to find what it is a child of // The point we found might be too small - use the address to find what it is a child of
if ($iPlaceID && $iMaxRank < 28) if ($iPlaceID && $iMaxRank < 28) {
{ if (($aPlace['rank_search'] > 28 || $bPlaceIsTiger || $bPlaceIsLine) && $iParentPlaceID) {
if (($aPlace['rank_search'] > 28 || $bPlaceIsTiger || $bPlaceIsLine) && $iParentPlaceID)
{
$iPlaceID = $iParentPlaceID; $iPlaceID = $iParentPlaceID;
} }
$sSQL = 'select address_place_id'; $sSQL = 'select address_place_id';
@@ -200,8 +185,7 @@ class ReverseGeocode
$sSQL .= ' LIMIT 1'; $sSQL .= ' LIMIT 1';
$iPlaceID = chksql($this->oDB->getOne($sSQL), $iPlaceID = chksql($this->oDB->getOne($sSQL),
"Could not get parent for place."); "Could not get parent for place.");
if (!$iPlaceID) if (!$iPlaceID) {
{
$iPlaceID = $aPlace['place_id']; $iPlaceID = $aPlace['place_id'];
} }
} }

View File

@@ -5,10 +5,8 @@ function getCmdOpt($aArg, $aSpec, &$aResult, $bExitOnError = false, $bExitOnUnkn
$aQuick = array(); $aQuick = array();
$aCounts = array(); $aCounts = array();
foreach($aSpec as $aLine) foreach ($aSpec as $aLine) {
{ if (is_array($aLine)) {
if (is_array($aLine))
{
if ($aLine[0]) $aQuick['--'.$aLine[0]] = $aLine; if ($aLine[0]) $aQuick['--'.$aLine[0]] = $aLine;
if ($aLine[1]) $aQuick['-'.$aLine[1]] = $aLine; if ($aLine[1]) $aQuick['-'.$aLine[1]] = $aLine;
$aCounts[$aLine[0]] = 0; $aCounts[$aLine[0]] = 0;
@@ -18,73 +16,59 @@ function getCmdOpt($aArg, $aSpec, &$aResult, $bExitOnError = false, $bExitOnUnkn
$aResult = array(); $aResult = array();
$bUnknown = false; $bUnknown = false;
$iSize = sizeof($aArg); $iSize = sizeof($aArg);
for ($i = 1; $i < $iSize; $i++) for ($i = 1; $i < $iSize; $i++) {
{ if (isset($aQuick[$aArg[$i]])) {
if (isset($aQuick[$aArg[$i]]))
{
$aLine = $aQuick[$aArg[$i]]; $aLine = $aQuick[$aArg[$i]];
$aCounts[$aLine[0]]++; $aCounts[$aLine[0]]++;
$xVal = null; $xVal = null;
if ($aLine[4] == $aLine[5]) if ($aLine[4] == $aLine[5]) {
{ if ($aLine[4]) {
if ($aLine[4])
{
$xVal = array(); $xVal = array();
for($n = $aLine[4]; $i < $iSize && $n; $n--) for ($n = $aLine[4]; $i < $iSize && $n; $n--) {
{
$i++; $i++;
if ($i >= $iSize || $aArg[$i][0] == '-') showUsage($aSpec, $bExitOnError, 'Parameter of \''.$aLine[0].'\' is missing'); if ($i >= $iSize || $aArg[$i][0] == '-') showUsage($aSpec, $bExitOnError, 'Parameter of \''.$aLine[0].'\' is missing');
switch ($aLine[6]) switch ($aLine[6]) {
{ case 'realpath':
case 'realpath': $xVal[] = realpath($aArg[$i]);
$xVal[] = realpath($aArg[$i]); break;
break; case 'realdir':
case 'realdir': $sPath = realpath(dirname($aArg[$i]));
$sPath = realpath(dirname($aArg[$i])); if ($sPath) {
if ($sPath) $xVal[] = $sPath . '/' . basename($aArg[$i]);
$xVal[] = $sPath . '/' . basename($aArg[$i]); } else {
else $xVal[] = $sPath;
$xVal[] = $sPath; }
break; break;
case 'bool': case 'bool':
$xVal[] = (bool)$aArg[$i]; $xVal[] = (bool)$aArg[$i];
break; break;
case 'int': case 'int':
$xVal[] = (int)$aArg[$i]; $xVal[] = (int)$aArg[$i];
break; break;
case 'float': case 'float':
$xVal[] = (float)$aArg[$i]; $xVal[] = (float)$aArg[$i];
break; break;
default: default:
$xVal[] = $aArg[$i]; $xVal[] = $aArg[$i];
break; break;
} }
} }
if ($aLine[4] == 1) $xVal = $xVal[0]; if ($aLine[4] == 1) $xVal = $xVal[0];
} } else {
else
{
$xVal = true; $xVal = true;
} }
} } else {
else
{
fail('Variable numbers of params not yet supported'); fail('Variable numbers of params not yet supported');
} }
if ($aLine[3] > 1) if ($aLine[3] > 1) {
{
if (!array_key_exists($aLine[0], $aResult)) $aResult[$aLine[0]] = array(); if (!array_key_exists($aLine[0], $aResult)) $aResult[$aLine[0]] = array();
$aResult[$aLine[0]][] = $xVal; $aResult[$aLine[0]][] = $xVal;
} } else {
else
{
$aResult[$aLine[0]] = $xVal; $aResult[$aLine[0]] = $xVal;
} }
} } else {
else
{
$bUnknown = $aArg[$i]; $bUnknown = $aArg[$i];
} }
} }
@@ -92,18 +76,15 @@ function getCmdOpt($aArg, $aSpec, &$aResult, $bExitOnError = false, $bExitOnUnkn
if (array_key_exists('help', $aResult)) showUsage($aSpec); if (array_key_exists('help', $aResult)) showUsage($aSpec);
if ($bUnknown && $bExitOnUnknown) showUsage($aSpec, $bExitOnError, 'Unknown option \''.$bUnknown.'\''); if ($bUnknown && $bExitOnUnknown) showUsage($aSpec, $bExitOnError, 'Unknown option \''.$bUnknown.'\'');
foreach($aSpec as $aLine) foreach ($aSpec as $aLine) {
{ if (is_array($aLine)) {
if (is_array($aLine))
{
if ($aCounts[$aLine[0]] < $aLine[2]) showUsage($aSpec, $bExitOnError, 'Option \''.$aLine[0].'\' is missing'); if ($aCounts[$aLine[0]] < $aLine[2]) showUsage($aSpec, $bExitOnError, 'Option \''.$aLine[0].'\' is missing');
if ($aCounts[$aLine[0]] > $aLine[3]) showUsage($aSpec, $bExitOnError, 'Option \''.$aLine[0].'\' is pressent too many times'); if ($aCounts[$aLine[0]] > $aLine[3]) showUsage($aSpec, $bExitOnError, 'Option \''.$aLine[0].'\' is pressent too many times');
switch ($aLine[6]) switch ($aLine[6]) {
{ case 'bool':
case 'bool': if (!array_key_exists($aLine[0], $aResult))
if (!array_key_exists($aLine[0], $aResult)) $aResult[$aLine[0]] = false;
$aResult[$aLine[0]] = false; break;
break;
} }
} }
} }
@@ -112,20 +93,16 @@ function getCmdOpt($aArg, $aSpec, &$aResult, $bExitOnError = false, $bExitOnUnkn
function showUsage($aSpec, $bExit = false, $sError = false) function showUsage($aSpec, $bExit = false, $sError = false)
{ {
if ($sError) if ($sError) {
{
echo basename($_SERVER['argv'][0]).': '.$sError."\n"; echo basename($_SERVER['argv'][0]).': '.$sError."\n";
echo 'Try `'.basename($_SERVER['argv'][0]).' --help` for more information.'."\n"; echo 'Try `'.basename($_SERVER['argv'][0]).' --help` for more information.'."\n";
exit; exit;
} }
echo "Usage: ".basename($_SERVER['argv'][0])."\n"; echo "Usage: ".basename($_SERVER['argv'][0])."\n";
$bFirst = true; $bFirst = true;
foreach($aSpec as $aLine) foreach ($aSpec as $aLine) {
{ if (is_array($aLine)) {
if (is_array($aLine)) if ($bFirst) {
{
if ($bFirst)
{
$bFirst = false; $bFirst = false;
echo "\n"; echo "\n";
} }
@@ -134,9 +111,7 @@ function showUsage($aSpec, $bExit = false, $sError = false)
if ($aLine[0]) $aNames[] = '--'.$aLine[0]; if ($aLine[0]) $aNames[] = '--'.$aLine[0];
$sName = join(', ',$aNames); $sName = join(', ',$aNames);
echo ' '.$sName.str_repeat(' ',30-strlen($sName)).$aLine[7]."\n"; echo ' '.$sName.str_repeat(' ',30-strlen($sName)).$aLine[7]."\n";
} } else {
else
{
echo $aLine."\n"; echo $aLine."\n";
} }
} }
@@ -146,8 +121,7 @@ function showUsage($aSpec, $bExit = false, $sError = false)
function chksql($oSql, $sMsg = false) function chksql($oSql, $sMsg = false)
{ {
if (PEAR::isError($oSql)) if (PEAR::isError($oSql)) {
{
fail($sMsg || $oSql->getMessage(), $oSql->userinfo); fail($sMsg || $oSql->getMessage(), $oSql->userinfo);
} }

View File

@@ -7,7 +7,7 @@ require_once('cmd.php');
if (CONST_HTTP_Proxy) { if (CONST_HTTP_Proxy) {
$proxy = 'tcp://' . CONST_HTTP_Proxy_Host . ':' . CONST_HTTP_Proxy_Port; $proxy = 'tcp://' . CONST_HTTP_Proxy_Host . ':' . CONST_HTTP_Proxy_Port;
$aHeaders = array(); $aHeaders = array();
if(CONST_HTTP_Proxy_Login != null && CONST_HTTP_Proxy_Login != '' && CONST_HTTP_Proxy_Password != null && CONST_HTTP_Proxy_Password != '') { if (CONST_HTTP_Proxy_Login != null && CONST_HTTP_Proxy_Login != '' && CONST_HTTP_Proxy_Password != null && CONST_HTTP_Proxy_Password != '') {
$auth = base64_encode(CONST_HTTP_Proxy_Login . ':' . CONST_HTTP_Proxy_Password); $auth = base64_encode(CONST_HTTP_Proxy_Login . ':' . CONST_HTTP_Proxy_Password);
$aHeaders = array("Proxy-Authorization: Basic $auth"); $aHeaders = array("Proxy-Authorization: Basic $auth");
} }

View File

@@ -34,12 +34,9 @@ function chksql($oSql, $sMsg = "Database request failed")
<p><b>Details:</b> <pre> <p><b>Details:</b> <pre>
INTERNALFAIL; INTERNALFAIL;
if (CONST_Debug) if (CONST_Debug) {
{
var_dump($oSql); var_dump($oSql);
} } else {
else
{
echo "<pre>\n".$oSql->getUserInfo()."</pre>"; echo "<pre>\n".$oSql->getUserInfo()."</pre>";
} }
@@ -55,15 +52,12 @@ function failInternalError($sError, $sSQL = false, $vDumpVar = false)
echo '<p>Nominatim has encountered an internal error while processing your request. This is most likely because of a bug in the software.</p>'; echo '<p>Nominatim has encountered an internal error while processing your request. This is most likely because of a bug in the software.</p>';
echo "<p><b>Details:</b> ".$sError,"</p>"; echo "<p><b>Details:</b> ".$sError,"</p>";
echo '<p>Feel free to file an issue on <a href="https://github.com/twain47/Nominatim/issues">Github</a>. Please include the error message above and the URL you used.</p>'; echo '<p>Feel free to file an issue on <a href="https://github.com/twain47/Nominatim/issues">Github</a>. Please include the error message above and the URL you used.</p>';
if (CONST_Debug) if (CONST_Debug) {
{
echo "<hr><h2>Debugging Information</h2><br>"; echo "<hr><h2>Debugging Information</h2><br>";
if ($sSQL) if ($sSQL) {
{
echo "<h3>SQL query</h3><code>".$sSQL."</code>"; echo "<h3>SQL query</h3><code>".$sSQL."</code>";
} }
if ($vDumpVar) if ($vDumpVar) {
{
echo "<h3>Result</h3> <code>"; echo "<h3>Result</h3> <code>";
var_dump($vDumpVar); var_dump($vDumpVar);
echo "</code>"; echo "</code>";
@@ -91,12 +85,10 @@ function userError($sError)
* HTTP Reply header setup * HTTP Reply header setup
*/ */
if (CONST_NoAccessControl) if (CONST_NoAccessControl) {
{
header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: OPTIONS,GET"); header("Access-Control-Allow-Methods: OPTIONS,GET");
if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
{
header("Access-Control-Allow-Headers: ".$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']); header("Access-Control-Allow-Headers: ".$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
} }
} }

View File

@@ -3,8 +3,7 @@
require_once(CONST_BasePath.'/lib/lib.php'); require_once(CONST_BasePath.'/lib/lib.php');
require_once(CONST_BasePath.'/lib/db.php'); require_once(CONST_BasePath.'/lib/db.php');
if (get_magic_quotes_gpc()) if (get_magic_quotes_gpc()) {
{
echo "Please disable magic quotes in your php.ini configuration\n"; echo "Please disable magic quotes in your php.ini configuration\n";
exit; exit;
} }

View File

@@ -55,13 +55,11 @@ function getWordSets($aWords, $iDepth)
$aResult = array(array(join(' ',$aWords))); $aResult = array(array(join(' ',$aWords)));
$sFirstToken = ''; $sFirstToken = '';
if ($iDepth < 8) { if ($iDepth < 8) {
while(sizeof($aWords) > 1) while (sizeof($aWords) > 1) {
{
$sWord = array_shift($aWords); $sWord = array_shift($aWords);
$sFirstToken .= ($sFirstToken?' ':'').$sWord; $sFirstToken .= ($sFirstToken?' ':'').$sWord;
$aRest = getWordSets($aWords, $iDepth+1); $aRest = getWordSets($aWords, $iDepth+1);
foreach($aRest as $aSet) foreach ($aRest as $aSet) {
{
$aResult[] = array_merge(array($sFirstToken),$aSet); $aResult[] = array_merge(array($sFirstToken),$aSet);
} }
} }
@@ -73,15 +71,12 @@ function getInverseWordSets($aWords, $iDepth)
{ {
$aResult = array(array(join(' ',$aWords))); $aResult = array(array(join(' ',$aWords)));
$sFirstToken = ''; $sFirstToken = '';
if ($iDepth < 8) if ($iDepth < 8) {
{ while (sizeof($aWords) > 1) {
while(sizeof($aWords) > 1)
{
$sWord = array_pop($aWords); $sWord = array_pop($aWords);
$sFirstToken = $sWord.($sFirstToken?' ':'').$sFirstToken; $sFirstToken = $sWord.($sFirstToken?' ':'').$sFirstToken;
$aRest = getInverseWordSets($aWords, $iDepth+1); $aRest = getInverseWordSets($aWords, $iDepth+1);
foreach($aRest as $aSet) foreach ($aRest as $aSet) {
{
$aResult[] = array_merge(array($sFirstToken),$aSet); $aResult[] = array_merge(array($sFirstToken),$aSet);
} }
} }
@@ -93,10 +88,8 @@ function getInverseWordSets($aWords, $iDepth)
function getTokensFromSets($aSets) function getTokensFromSets($aSets)
{ {
$aTokens = array(); $aTokens = array();
foreach($aSets as $aSet) foreach ($aSets as $aSet) {
{ foreach ($aSet as $sWord) {
foreach($aSet as $sWord)
{
$aTokens[' '.$sWord] = ' '.$sWord; $aTokens[' '.$sWord] = ' '.$sWord;
$aTokens[$sWord] = $sWord; $aTokens[$sWord] = $sWord;
} }
@@ -115,11 +108,9 @@ function gbPostcodeCalculate($sPostcode, $sPostcodeSector, $sPostcodeEnd, &$oDB)
$sSQL = 'select \'AA\', ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from gb_postcode where postcode = \''.$sPostcode.'\''; $sSQL = 'select \'AA\', ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from gb_postcode where postcode = \''.$sPostcode.'\'';
$aNearPostcodes = chksql($oDB->getAll($sSQL)); $aNearPostcodes = chksql($oDB->getAll($sSQL));
if (sizeof($aNearPostcodes)) if (sizeof($aNearPostcodes)) {
{
$aPostcodes = array(); $aPostcodes = array();
foreach($aNearPostcodes as $aPostcode) foreach ($aNearPostcodes as $aPostcode) {
{
$aPostcodes[] = array('lat' => $aPostcode['lat'], 'lon' => $aPostcode['lon'], 'radius' => 0.005); $aPostcodes[] = array('lat' => $aPostcode['lat'], 'lon' => $aPostcode['lon'], 'radius' => 0.005);
} }
@@ -442,8 +433,7 @@ function getClassTypesWithImportance()
{ {
$aOrders = getClassTypes(); $aOrders = getClassTypes();
$i = 1; $i = 1;
foreach($aOrders as $sID => $a) foreach ($aOrders as $sID => $a) {
{
$aOrders[$sID]['importance'] = $i++; $aOrders[$sID]['importance'] = $i++;
} }
return $aOrders; return $aOrders;
@@ -456,18 +446,17 @@ function getResultDiameter($aResult)
$fDiameter = 0.0001; $fDiameter = 0.0001;
if (isset($aResult['class']) if (isset($aResult['class'])
&& isset($aResult['type']) && isset($aResult['type'])
&& isset($aResult['admin_level']) && isset($aResult['admin_level'])
&& isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']) && isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter'])
&& $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']) && $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']
{ ) {
$fDiameter = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']; $fDiameter = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter'];
} } elseif (isset($aResult['class'])
elseif (isset($aResult['class']) && isset($aResult['type'])
&& isset($aResult['type']) && isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
&& isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']) && $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']
&& $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']) ) {
{
$fDiameter = $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']; $fDiameter = $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'];
} }
@@ -481,19 +470,14 @@ function javascript_renderData($xVal, $iOptions = 0)
$iOptions |= JSON_UNESCAPED_UNICODE; $iOptions |= JSON_UNESCAPED_UNICODE;
$jsonout = json_encode($xVal, $iOptions); $jsonout = json_encode($xVal, $iOptions);
if( ! isset($_GET['json_callback'])) if (! isset($_GET['json_callback'])) {
{
header("Content-Type: application/json; charset=UTF-8"); header("Content-Type: application/json; charset=UTF-8");
echo $jsonout; echo $jsonout;
} else } else {
{ if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u',$_GET['json_callback'])) {
if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u',$_GET['json_callback']))
{
header("Content-Type: application/javascript; charset=UTF-8"); header("Content-Type: application/javascript; charset=UTF-8");
echo $_GET['json_callback'].'('.$jsonout.')'; echo $_GET['json_callback'].'('.$jsonout.')';
} } else {
else
{
header('HTTP/1.0 400 Bad Request'); header('HTTP/1.0 400 Bad Request');
} }
} }
@@ -503,14 +487,10 @@ function javascript_renderData($xVal, $iOptions = 0)
function _debugDumpGroupedSearches($aData, $aTokens) function _debugDumpGroupedSearches($aData, $aTokens)
{ {
$aWordsIDs = array(); $aWordsIDs = array();
if ($aTokens) if ($aTokens) {
{ foreach ($aTokens as $sToken => $aWords) {
foreach($aTokens as $sToken => $aWords) if ($aWords) {
{ foreach ($aWords as $aToken) {
if ($aWords)
{
foreach($aWords as $aToken)
{
$aWordsIDs[$aToken['word_id']] = $sToken.'('.$aToken['word_id'].')'; $aWordsIDs[$aToken['word_id']] = $sToken.'('.$aToken['word_id'].')';
} }
} }
@@ -518,17 +498,14 @@ function _debugDumpGroupedSearches($aData, $aTokens)
} }
echo "<table border=\"1\">"; echo "<table border=\"1\">";
echo "<tr><th>rank</th><th>Name Tokens</th><th>Name Not</th><th>Address Tokens</th><th>Address Not</th><th>country</th><th>operator</th><th>class</th><th>type</th><th>house#</th><th>Lat</th><th>Lon</th><th>Radius</th></tr>"; echo "<tr><th>rank</th><th>Name Tokens</th><th>Name Not</th><th>Address Tokens</th><th>Address Not</th><th>country</th><th>operator</th><th>class</th><th>type</th><th>house#</th><th>Lat</th><th>Lon</th><th>Radius</th></tr>";
foreach($aData as $iRank => $aRankedSet) foreach ($aData as $iRank => $aRankedSet) {
{ foreach ($aRankedSet as $aRow) {
foreach($aRankedSet as $aRow)
{
echo "<tr>"; echo "<tr>";
echo "<td>$iRank</td>"; echo "<td>$iRank</td>";
echo "<td>"; echo "<td>";
$sSep = ''; $sSep = '';
foreach($aRow['aName'] as $iWordID) foreach ($aRow['aName'] as $iWordID) {
{
echo $sSep.'#'.$aWordsIDs[$iWordID].'#'; echo $sSep.'#'.$aWordsIDs[$iWordID].'#';
$sSep = ', '; $sSep = ', ';
} }
@@ -536,8 +513,7 @@ function _debugDumpGroupedSearches($aData, $aTokens)
echo "<td>"; echo "<td>";
$sSep = ''; $sSep = '';
foreach($aRow['aNameNonSearch'] as $iWordID) foreach ($aRow['aNameNonSearch'] as $iWordID) {
{
echo $sSep.'#'.$aWordsIDs[$iWordID].'#'; echo $sSep.'#'.$aWordsIDs[$iWordID].'#';
$sSep = ', '; $sSep = ', ';
} }
@@ -545,8 +521,7 @@ function _debugDumpGroupedSearches($aData, $aTokens)
echo "<td>"; echo "<td>";
$sSep = ''; $sSep = '';
foreach($aRow['aAddress'] as $iWordID) foreach ($aRow['aAddress'] as $iWordID) {
{
echo $sSep.'#'.$aWordsIDs[$iWordID].'#'; echo $sSep.'#'.$aWordsIDs[$iWordID].'#';
$sSep = ', '; $sSep = ', ';
} }
@@ -554,8 +529,7 @@ function _debugDumpGroupedSearches($aData, $aTokens)
echo "<td>"; echo "<td>";
$sSep = ''; $sSep = '';
foreach($aRow['aAddressNonSearch'] as $iWordID) foreach ($aRow['aAddressNonSearch'] as $iWordID) {
{
echo $sSep.'#'.$aWordsIDs[$iWordID].'#'; echo $sSep.'#'.$aWordsIDs[$iWordID].'#';
$sSep = ', '; $sSep = ', ';
} }
@@ -593,28 +567,24 @@ function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCo
$aAddress = array(); $aAddress = array();
$aFallback = array(); $aFallback = array();
$aClassType = getClassTypes(); $aClassType = getClassTypes();
foreach($aAddressLines as $aLine) foreach ($aAddressLines as $aLine) {
{
$bFallback = false; $bFallback = false;
$aTypeLabel = false; $aTypeLabel = false;
if (isset($aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']])) $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']]; if (isset($aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']])) {
elseif (isset($aClassType[$aLine['class'].':'.$aLine['type']])) $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type']]; $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']];
elseif (isset($aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))])) } elseif (isset($aClassType[$aLine['class'].':'.$aLine['type']])) {
{ $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type']];
} elseif (isset($aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))])) {
$aTypeLabel = $aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))]; $aTypeLabel = $aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))];
$bFallback = true; $bFallback = true;
} } else {
else
{
$aTypeLabel = array('simplelabel'=>'address'.$aLine['rank_address']); $aTypeLabel = array('simplelabel'=>'address'.$aLine['rank_address']);
$bFallback = true; $bFallback = true;
} }
if ($aTypeLabel && ((isset($aLine['localname']) && $aLine['localname']) || (isset($aLine['housenumber']) && $aLine['housenumber']))) if ($aTypeLabel && ((isset($aLine['localname']) && $aLine['localname']) || (isset($aLine['housenumber']) && $aLine['housenumber']))) {
{
$sTypeLabel = strtolower(isset($aTypeLabel['simplelabel'])?$aTypeLabel['simplelabel']:$aTypeLabel['label']); $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel'])?$aTypeLabel['simplelabel']:$aTypeLabel['label']);
$sTypeLabel = str_replace(' ','_',$sTypeLabel); $sTypeLabel = str_replace(' ','_',$sTypeLabel);
if (!isset($aAddress[$sTypeLabel]) || (isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel]) || $aLine['class'] == 'place') if (!isset($aAddress[$sTypeLabel]) || (isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel]) || $aLine['class'] == 'place') {
{
$aAddress[$sTypeLabel] = $aLine['localname']?$aLine['localname']:$aLine['housenumber']; $aAddress[$sTypeLabel] = $aLine['localname']?$aLine['localname']:$aLine['housenumber'];
} }
$aFallback[$sTypeLabel] = $bFallback; $aFallback[$sTypeLabel] = $bFallback;
@@ -644,70 +614,57 @@ function looksLikeLatLonPair($sQuery)
$fQueryLat = null; $fQueryLat = null;
$fQueryLon = null; $fQueryLon = null;
// degrees decimal minutes if (preg_match('/\\b([NS])[ ]+([0-9]+[0-9.]*)[° ]+([0-9.]+)?[\']*[, ]+([EW])[ ]+([0-9]+)[° ]+([0-9]+[0-9.]*)[\']*?\\b/', $sQuery, $aData)) {
// N 40 26.767, W 79 58.933 // 1 2 3 4 5 6
// N 40°26.767, W 79°58.933 // degrees decimal minutes
// 1 2 3 4 5 6 // N 40 26.767, W 79 58.933
if (preg_match('/\\b([NS])[ ]+([0-9]+[0-9.]*)[° ]+([0-9.]+)?[\']*[, ]+([EW])[ ]+([0-9]+)[° ]+([0-9]+[0-9.]*)[\']*?\\b/', $sQuery, $aData)) // N 40°26.767, W 79°58.933
{
$sFound = $aData[0]; $sFound = $aData[0];
$fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2] + $aData[3]/60); $fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2] + $aData[3]/60);
$fQueryLon = ($aData[4]=='E'?1:-1) * ($aData[5] + $aData[6]/60); $fQueryLon = ($aData[4]=='E'?1:-1) * ($aData[5] + $aData[6]/60);
} } elseif (preg_match('/\\b([0-9]+)[° ]+([0-9]+[0-9.]*)?[\']*[ ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+[0-9.]*)?[\' ]+([EW])\\b/', $sQuery, $aData)) {
// degrees decimal minutes // 1 2 3 4 5 6
// 40 26.767 N, 79 58.933 W // degrees decimal minutes
// 40° 26.767 N 79° 58.933 W // 40 26.767 N, 79 58.933 W
// 1 2 3 4 5 6 // 40° 26.767 N 79° 58.933 W
elseif (preg_match('/\\b([0-9]+)[° ]+([0-9]+[0-9.]*)?[\']*[ ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+[0-9.]*)?[\' ]+([EW])\\b/', $sQuery, $aData))
{
$sFound = $aData[0]; $sFound = $aData[0];
$fQueryLat = ($aData[3]=='N'?1:-1) * ($aData[1] + $aData[2]/60); $fQueryLat = ($aData[3]=='N'?1:-1) * ($aData[1] + $aData[2]/60);
$fQueryLon = ($aData[6]=='E'?1:-1) * ($aData[4] + $aData[5]/60); $fQueryLon = ($aData[6]=='E'?1:-1) * ($aData[4] + $aData[5]/60);
} } elseif (preg_match('/\\b([NS])[ ]([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″"]*[, ]+([EW])[ ]([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″"]*\\b/', $sQuery, $aData)) {
// degrees decimal seconds // 1 2 3 4 5 6 7 8
// N 40 26 46 W 79 58 56 // degrees decimal seconds
// N 40° 26 46″, W 79° 58 56 // N 40 26 46 W 79 58 56
// 1 2 3 4 5 6 7 8 // N 40° 26 46″, W 79° 58 56″
elseif (preg_match('/\\b([NS])[ ]([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″"]*[, ]+([EW])[ ]([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″"]*\\b/', $sQuery, $aData))
{
$sFound = $aData[0]; $sFound = $aData[0];
$fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2] + $aData[3]/60 + $aData[4]/3600); $fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2] + $aData[3]/60 + $aData[4]/3600);
$fQueryLon = ($aData[5]=='E'?1:-1) * ($aData[6] + $aData[7]/60 + $aData[8]/3600); $fQueryLon = ($aData[5]=='E'?1:-1) * ($aData[6] + $aData[7]/60 + $aData[8]/3600);
} } elseif (preg_match('/\\b([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″" ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″" ]+([EW])\\b/', $sQuery, $aData)) {
// degrees decimal seconds // 1 2 3 4 5 6 7 8
// 40 26 46 N 79 58 56 W // degrees decimal seconds
// 40° 26 46 N, 79° 58 56 W // 40 26 46 N 79 58 56 W
// 1 2 3 4 5 6 7 8 // 40° 26 46″ N, 79° 58 56″ W
elseif (preg_match('/\\b([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″" ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″" ]+([EW])\\b/', $sQuery, $aData))
{
$sFound = $aData[0]; $sFound = $aData[0];
$fQueryLat = ($aData[4]=='N'?1:-1) * ($aData[1] + $aData[2]/60 + $aData[3]/3600); $fQueryLat = ($aData[4]=='N'?1:-1) * ($aData[1] + $aData[2]/60 + $aData[3]/3600);
$fQueryLon = ($aData[8]=='E'?1:-1) * ($aData[5] + $aData[6]/60 + $aData[7]/3600); $fQueryLon = ($aData[8]=='E'?1:-1) * ($aData[5] + $aData[6]/60 + $aData[7]/3600);
} } elseif (preg_match('/\\b([NS])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*[, ]+([EW])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*\\b/', $sQuery, $aData)) {
// degrees decimal // 1 2 3 4
// N 40.446° W 79.982° // degrees decimal
// 1 2 3 4 // N 40.446° W 79.982°
elseif (preg_match('/\\b([NS])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*[, ]+([EW])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*\\b/', $sQuery, $aData))
{
$sFound = $aData[0]; $sFound = $aData[0];
$fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2]); $fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2]);
$fQueryLon = ($aData[3]=='E'?1:-1) * ($aData[4]); $fQueryLon = ($aData[3]=='E'?1:-1) * ($aData[4]);
} } elseif (preg_match('/\\b([0-9]+[0-9]*\\.[0-9]+)[° ]+([NS])[, ]+([0-9]+[0-9]*\\.[0-9]+)[° ]+([EW])\\b/', $sQuery, $aData)) {
// degrees decimal // 1 2 3 4
// 40.446° N 79.982° W // degrees decimal
// 1 2 3 4 // 40.446° N 79.982° W
elseif (preg_match('/\\b([0-9]+[0-9]*\\.[0-9]+)[° ]+([NS])[, ]+([0-9]+[0-9]*\\.[0-9]+)[° ]+([EW])\\b/', $sQuery, $aData))
{
$sFound = $aData[0]; $sFound = $aData[0];
$fQueryLat = ($aData[2]=='N'?1:-1) * ($aData[1]); $fQueryLat = ($aData[2]=='N'?1:-1) * ($aData[1]);
$fQueryLon = ($aData[4]=='E'?1:-1) * ($aData[3]); $fQueryLon = ($aData[4]=='E'?1:-1) * ($aData[3]);
} } elseif (preg_match('/(\\[|^|\\b)(-?[0-9]+[0-9]*\\.[0-9]+)[, ]+(-?[0-9]+[0-9]*\\.[0-9]+)(\\]|$|\\b)/', $sQuery, $aData)) {
// degrees decimal // 1 2 3 4
// 12.34, 56.78 // degrees decimal
// [12.456,-78.90] // 12.34, 56.78
// 1 2 3 4 // [12.456,-78.90]
elseif (preg_match('/(\\[|^|\\b)(-?[0-9]+[0-9]*\\.[0-9]+)[, ]+(-?[0-9]+[0-9]*\\.[0-9]+)(\\]|$|\\b)/', $sQuery, $aData))
{
$sFound = $aData[0]; $sFound = $aData[0];
$fQueryLat = $aData[2]; $fQueryLat = $aData[2];
$fQueryLon = $aData[3]; $fQueryLon = $aData[3];
@@ -723,28 +680,27 @@ function looksLikeLatLonPair($sQuery)
function geometryText2Points($geometry_as_text, $fRadius) function geometryText2Points($geometry_as_text, $fRadius)
{ {
$aPolyPoints = NULL; $aPolyPoints = NULL;
if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
{ //
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER); preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
} //
elseif (preg_match('#LINESTRING\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) } elseif (preg_match('#LINESTRING\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
{ //
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER); preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
} //
elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) } elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
{ //
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER); preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
} //
elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#', $geometry_as_text, $aMatch)) } elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#', $geometry_as_text, $aMatch)) {
{ //
$aPolyPoints = createPointsAroundCenter($aMatch[1], $aMatch[2], $fRadius); $aPolyPoints = createPointsAroundCenter($aMatch[1], $aMatch[2], $fRadius);
//
} }
if (isset($aPolyPoints)) if (isset($aPolyPoints)) {
{
$aResultPoints = array(); $aResultPoints = array();
foreach($aPolyPoints as $aPoint) foreach ($aPolyPoints as $aPoint) {
{
$aResultPoints[] = array($aPoint[1], $aPoint[2]); $aResultPoints[] = array($aPoint[1], $aPoint[2]);
} }
return $aResultPoints; return $aResultPoints;
@@ -755,12 +711,11 @@ function geometryText2Points($geometry_as_text, $fRadius)
function createPointsAroundCenter($fLon, $fLat, $fRadius) function createPointsAroundCenter($fLon, $fLat, $fRadius)
{ {
$iSteps = max(8, min(100, ($fRadius * 40000)^2)); $iSteps = max(8, min(100, ($fRadius * 40000)^2));
$fStepSize = (2*pi())/$iSteps; $fStepSize = (2*pi())/$iSteps;
$aPolyPoints = array(); $aPolyPoints = array();
for($f = 0; $f < 2*pi(); $f += $fStepSize) for ($f = 0; $f < 2*pi(); $f += $fStepSize) {
{ $aPolyPoints[] = array('', $fLon+($fRadius*sin($f)), $fLat+($fRadius*cos($f)) );
$aPolyPoints[] = array('', $fLon+($fRadius*sin($f)), $fLat+($fRadius*cos($f)) ); }
} return $aPolyPoints;
return $aPolyPoints;
} }

View File

@@ -9,14 +9,13 @@ function logStart(&$oDB, $sType = '', $sQuery = '', $aLanguageList = array())
$sOutputFormat = ''; $sOutputFormat = '';
if (isset($_GET['format'])) $sOutputFormat = $_GET['format']; if (isset($_GET['format'])) $sOutputFormat = $_GET['format'];
if ($sType == 'reverse') if ($sType == 'reverse') {
{
$sOutQuery = (isset($_GET['lat'])?$_GET['lat']:'').'/'; $sOutQuery = (isset($_GET['lat'])?$_GET['lat']:'').'/';
if (isset($_GET['lon'])) $sOutQuery .= $_GET['lon']; if (isset($_GET['lon'])) $sOutQuery .= $_GET['lon'];
if (isset($_GET['zoom'])) $sOutQuery .= '/'.$_GET['zoom']; if (isset($_GET['zoom'])) $sOutQuery .= '/'.$_GET['zoom'];
} } else {
else
$sOutQuery = $sQuery; $sOutQuery = $sQuery;
}
$hLog = array( $hLog = array(
date('Y-m-d H:i:s',$aStartTime[0]).'.'.$aStartTime[1], date('Y-m-d H:i:s',$aStartTime[0]).'.'.$aStartTime[1],
@@ -27,16 +26,14 @@ function logStart(&$oDB, $sType = '', $sQuery = '', $aLanguageList = array())
$fStartTime $fStartTime
); );
if (CONST_Log_DB) if (CONST_Log_DB) {
{
if (isset($_GET['email'])) if (isset($_GET['email']))
$sUserAgent = $_GET['email']; $sUserAgent = $_GET['email'];
elseif (isset($_SERVER['HTTP_REFERER'])) elseif (isset($_SERVER['HTTP_REFERER']))
$sUserAgent = $_SERVER['HTTP_REFERER']; $sUserAgent = $_SERVER['HTTP_REFERER'];
elseif (isset($_SERVER['HTTP_USER_AGENT'])) elseif (isset($_SERVER['HTTP_USER_AGENT']))
$sUserAgent = $_SERVER['HTTP_USER_AGENT']; $sUserAgent = $_SERVER['HTTP_USER_AGENT'];
else else $sUserAgent = '';
$sUserAgent = '';
$sSQL = 'insert into new_query_log (type,starttime,query,ipaddress,useragent,language,format,searchterm)'; $sSQL = 'insert into new_query_log (type,starttime,query,ipaddress,useragent,language,format,searchterm)';
$sSQL .= ' values ('.getDBQuoted($sType).','.getDBQuoted($hLog[0]).','.getDBQuoted($hLog[2]); $sSQL .= ' values ('.getDBQuoted($sType).','.getDBQuoted($hLog[0]).','.getDBQuoted($hLog[2]);
$sSQL .= ','.getDBQuoted($hLog[1]).','.getDBQuoted($sUserAgent).','.getDBQuoted(join(',',$aLanguageList)).','.getDBQuoted($sOutputFormat).','.getDBQuoted($hLog[3]).')'; $sSQL .= ','.getDBQuoted($hLog[1]).','.getDBQuoted($sUserAgent).','.getDBQuoted(join(',',$aLanguageList)).','.getDBQuoted($sOutputFormat).','.getDBQuoted($hLog[3]).')';
@@ -50,8 +47,7 @@ function logEnd(&$oDB, $hLog, $iNumResults)
{ {
$fEndTime = microtime(true); $fEndTime = microtime(true);
if (CONST_Log_DB) if (CONST_Log_DB) {
{
$aEndTime = explode('.', $fEndTime); $aEndTime = explode('.', $fEndTime);
if (!$aEndTime[1]) $aEndTime[1] = '0'; if (!$aEndTime[1]) $aEndTime[1] = '0';
$sEndTime = date('Y-m-d H:i:s',$aEndTime[0]).'.'.$aEndTime[1]; $sEndTime = date('Y-m-d H:i:s',$aEndTime[0]).'.'.$aEndTime[1];
@@ -63,8 +59,7 @@ function logEnd(&$oDB, $hLog, $iNumResults)
$oDB->query($sSQL); $oDB->query($sSQL);
} }
if (CONST_Log_File) if (CONST_Log_File) {
{
$aOutdata = sprintf("[%s] %.4f %d %s \"%s\"\n", $aOutdata = sprintf("[%s] %.4f %d %s \"%s\"\n",
$hLog[0], $fEndTime-$hLog[5], $iNumResults, $hLog[0], $fEndTime-$hLog[5], $iNumResults,
$hLog[4], $hLog[2]); $hLog[4], $hLog[2]);

View File

@@ -17,8 +17,7 @@ function formatOSMType($sType, $bIncludeExternal=true)
function osmLink($aFeature, $sRefText=false) function osmLink($aFeature, $sRefText=false)
{ {
$sOSMType = formatOSMType($aFeature['osm_type'], false); $sOSMType = formatOSMType($aFeature['osm_type'], false);
if ($sOSMType) if ($sOSMType) {
{
return '<a href="//www.openstreetmap.org/'.$sOSMType.'/'.$aFeature['osm_id'].'">'.$sOSMType.' '.($sRefText?$sRefText:$aFeature['osm_id']).'</a>'; return '<a href="//www.openstreetmap.org/'.$sOSMType.'/'.$aFeature['osm_id'].'">'.$sOSMType.' '.($sRefText?$sRefText:$aFeature['osm_id']).'</a>';
} }
return ''; return '';
@@ -26,8 +25,7 @@ function osmLink($aFeature, $sRefText=false)
function wikipediaLink($aFeature) function wikipediaLink($aFeature)
{ {
if ($aFeature['wikipedia']) if ($aFeature['wikipedia']) {
{
list($sLanguage, $sArticle) = explode(':',$aFeature['wikipedia']); list($sLanguage, $sArticle) = explode(':',$aFeature['wikipedia']);
return '<a href="https://'.$sLanguage.'.wikipedia.org/wiki/'.urlencode($sArticle).'" target="_blank">'.$aFeature['wikipedia'].'</a>'; return '<a href="https://'.$sLanguage.'.wikipedia.org/wiki/'.urlencode($sArticle).'" target="_blank">'.$aFeature['wikipedia'].'</a>';
} }

176
php-lint-rules.xml Normal file
View File

@@ -0,0 +1,176 @@
<?xml version="1.0"?>
<ruleset name="Nominatim Standard">
<description>Nominatim coding standard</description>
<!-- based on another standard, you can find it here -->
<!-- /usr/share/php/PHP/CodeSniffer/Standards/PSR2/ruleset.xml -->
<!-- https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/ruleset.xml -->
<rule ref="PSR2"/>
<!-- currently 300 warnings, we set a limit later -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="9999"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
<!-- **************************************************************
DOCUMENTATION
************************************************************** -->
<rule ref="PEAR.Commenting.FileComment.Missing">
<severity>0</severity>
</rule>
<rule ref="PEAR.Commenting.ClassComment.Missing">
<severity>0</severity>
</rule>
<rule ref="PEAR.Commenting.FunctionComment.Missing">
<severity>0</severity>
</rule>
<!-- **************************************************************
COMMENTS
************************************************************** -->
<!-- We allow comments after statements -->
<rule ref="Squiz.Commenting.PostStatementComment.Found">
<severity>0</severity>
</rule>
<!-- ... even without space e.g. //some words -->
<rule ref="Squiz.Commenting.InlineComment.NoSpaceBefore">
<severity>0</severity>
</rule>
<!-- Comments don't have to start uppercase -->
<rule ref="Squiz.Commenting.InlineComment.NotCapital">
<severity>0</severity>
</rule>
<!-- Comments don't have to end with one of .!? -->
<rule ref="Squiz.Commenting.InlineComment.InvalidEndChar">
<severity>0</severity>
</rule>
<!-- we don't need '} // functionname()' at end of large blocks -->
<rule ref="Squiz.Commenting.ClosingDeclarationComment.Missing">
<severity>0</severity>
</rule>
<!-- .. same for conditions -->
<rule ref="Squiz.Commenting.LongConditionClosingComment.Missing">
<severity>0</severity>
</rule>
<!-- **************************************************************
INDENTATION, SPACING
************************************************************** -->
<!-- We use tabs -->
<rule ref="Generic.WhiteSpace.DisallowTabIndent.TabsUsed">
<severity>0</severity>
</rule>
<!-- We don't need 2 blank lines after function -->
<rule ref="Squiz.WhiteSpace.FunctionSpacing.After">
<severity>0</severity>
</rule>
<!-- Aligned looks nicer, but causes too many warnings currently -->
<rule ref="Generic.Formatting.MultipleStatementAlignment.NotSame">
<severity>0</severity>
</rule>
<!-- Aligned looks nicer, but causes too many warnings currently -->
<rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned">
<severity>0</severity>
</rule>
<!-- **************************************************************
VARIABLES
************************************************************** -->
<!-- CONST_this_var is fine, we don't need ConstThisVar -->
<rule ref="Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase">
<severity>0</severity>
</rule>
<!-- simply disagree with "Each line in an array declaration must end in a comma" -->
<rule ref="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.NoComma">
<severity>0</severity>
</rule>
<!-- We allow "$abc = array($aPoint[1], $aPoint[2])" -->
<rule ref="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed">
<severity>0</severity>
</rule>
<!-- **************************************************************
CONTROL STRUCTURES
************************************************************** -->
<!-- we allow "if (a) echo 'b'" without brackets -->
<rule ref="Generic.ControlStructures.InlineControlStructure.NotAllowed">
<severity>0</severity>
</rule>
<rule ref="Generic.ControlStructures.InlineControlStructure.Discouraged">
<severity>0</severity>
</rule>
<rule ref="Squiz.PHP.DisallowInlineIf.Found">
<severity>0</severity>
</rule>
<!-- We allow "if (a)". No need for "if (a === TRUE)" -->
<rule ref="Squiz.Operators.ComparisonOperatorUsage.ImplicitTrue">
<severity>0</severity>
</rule>
<!-- ... same for "if (!a)" -->
<rule ref="Squiz.Operators.ComparisonOperatorUsage.NotAllowed">
<severity>0</severity>
</rule>
<!-- We allow
if (a)
{
-->
<rule ref="PEAR.ControlStructures.MultiLineCondition.NewlineBeforeOpenBrace">
<severity>0</severity>
</rule>
<!-- ... same -->
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing.NoLineAfterClose">
<severity>0</severity>
</rule>
<!-- ... same for foreach/while etc -->
<rule ref="PEAR.ControlStructures.ControlSignature">
<severity>0</severity>
</rule>
<!-- ... same -->
<rule ref="Squiz.WhiteSpace.FunctionClosingBraceSpace.SpacingBeforeClose">
<severity>0</severity>
</rule>
</ruleset>

View File

@@ -17,14 +17,12 @@ $aCMDOptions = array(
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
$m = getBucketMemcache(); $m = getBucketMemcache();
if (!$m) if (!$m) {
{
echo "ERROR: Bucket memcache is not configured\n"; echo "ERROR: Bucket memcache is not configured\n";
exit; exit;
} }
if ($aResult['list']) if ($aResult['list']) {
{
$iCurrentSleeping = $m->get('sleepCounter'); $iCurrentSleeping = $m->get('sleepCounter');
echo "\n Sleeping blocks count: $iCurrentSleeping\n"; echo "\n Sleeping blocks count: $iCurrentSleeping\n";
@@ -32,8 +30,7 @@ if ($aResult['list'])
echo "\n"; echo "\n";
printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", "Key", "Total Blocks", "Current", "Still Blocked", "Last Block Time", "Sleeping"); printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", "Key", "Total Blocks", "Current", "Still Blocked", "Last Block Time", "Sleeping");
printf(" %'--40s-|-%'-12s-|-%'-7s-|-%'-13s-|-%'-31s-|-%'-8s\n", "", "", "", "", "", ""); printf(" %'--40s-|-%'-12s-|-%'-7s-|-%'-13s-|-%'-31s-|-%'-8s\n", "", "", "", "", "", "");
foreach($aBlocks as $sKey => $aDetails) foreach ($aBlocks as $sKey => $aDetails) {
{
printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", $sKey, $aDetails['totalBlocks'], printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", $sKey, $aDetails['totalBlocks'],
(int)$aDetails['currentBucketSize'], $aDetails['currentlyBlocked']?'Y':'N', (int)$aDetails['currentBucketSize'], $aDetails['currentlyBlocked']?'Y':'N',
date("r", $aDetails['lastBlockTimestamp']), $aDetails['isSleeping']?'Y':'N'); date("r", $aDetails['lastBlockTimestamp']), $aDetails['isSleeping']?'Y':'N');
@@ -41,13 +38,11 @@ if ($aResult['list'])
echo "\n"; echo "\n";
} }
if ($aResult['delete']) if ($aResult['delete']) {
{
$m->set('sleepCounter', 0); $m->set('sleepCounter', 0);
clearBucketBlocks(); clearBucketBlocks();
} }
if ($aResult['flush']) if ($aResult['flush']) {
{
$m->flush(); $m->flush();
} }

View File

@@ -17,17 +17,13 @@ require_once(CONST_BasePath.'/lib/init-cmd.php');
include(CONST_InstallPath.'/settings/phrase_settings.php'); include(CONST_InstallPath.'/settings/phrase_settings.php');
if (true) if (true) {
{
$sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Country_Codes'; $sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Country_Codes';
$sWikiPageXML = file_get_contents($sURL); $sWikiPageXML = file_get_contents($sURL);
if (preg_match_all('#\\| ([a-z]{2}) \\|\\| [^|]+\\|\\| ([a-z,]+)#', $sWikiPageXML, $aMatches, PREG_SET_ORDER)) if (preg_match_all('#\\| ([a-z]{2}) \\|\\| [^|]+\\|\\| ([a-z,]+)#', $sWikiPageXML, $aMatches, PREG_SET_ORDER)) {
{ foreach ($aMatches as $aMatch) {
foreach($aMatches as $aMatch)
{
$aLanguages = explode(',', $aMatch[2]); $aLanguages = explode(',', $aMatch[2]);
foreach($aLanguages as $i => $s) foreach ($aLanguages as $i => $s) {
{
$aLanguages[$i] = '"'.pg_escape_string($s).'"'; $aLanguages[$i] = '"'.pg_escape_string($s).'"';
} }
echo "UPDATE country_name set country_default_language_codes = '{".join(',',$aLanguages)."}' where country_code = '".pg_escape_string($aMatch[1])."';\n"; echo "UPDATE country_name set country_default_language_codes = '{".join(',',$aLanguages)."}' where country_code = '".pg_escape_string($aMatch[1])."';\n";

View File

@@ -58,8 +58,7 @@ exit;
} }
*/ */
if ($aCMDResult['create-tables']) if ($aCMDResult['create-tables']) {
{
$sSQL = <<<'EOD' $sSQL = <<<'EOD'
CREATE TABLE wikipedia_article ( CREATE TABLE wikipedia_article (
language text NOT NULL, language text NOT NULL,
@@ -111,22 +110,18 @@ function _parseWikipediaContent($sPageText)
$aTemplateStack = array(); $aTemplateStack = array();
$aState = array('body'); $aState = array('body');
foreach($aPageText as $i => $sPart) foreach ($aPageText as $i => $sPart) {
{ switch ($sPart) {
switch($sPart)
{
case '{{': case '{{':
array_unshift($aTemplateStack, array('', array())); array_unshift($aTemplateStack, array('', array()));
array_unshift($aState, 'template'); array_unshift($aState, 'template');
break; break;
case '}}': case '}}':
if ($aState[0] == 'template' || $aState[0] == 'templateparam') if ($aState[0] == 'template' || $aState[0] == 'templateparam') {
{
$aTemplate = array_shift($aTemplateStack); $aTemplate = array_shift($aTemplateStack);
array_shift($aState); array_shift($aState);
$aTemplates[] = $aTemplate; $aTemplates[] = $aTemplate;
} }
break; break;
case '[[': case '[[':
@@ -135,16 +130,14 @@ function _parseWikipediaContent($sPageText)
array_unshift($aState, 'link'); array_unshift($aState, 'link');
break; break;
case ']]': case ']]':
if ($aState[0] == 'link' || $aState[0] == 'linksynonim') if ($aState[0] == 'link' || $aState[0] == 'linksynonim') {
{
if (!$sLinkSyn) $sLinkSyn = $sLinkPage; if (!$sLinkSyn) $sLinkSyn = $sLinkPage;
if (substr($sLinkPage, 0, 6) == 'Image:') $sLinkSyn = substr($sLinkPage, 6); if (substr($sLinkPage, 0, 6) == 'Image:') $sLinkSyn = substr($sLinkPage, 6);
$aLinks[] = array($sLinkPage, $sLinkSyn); $aLinks[] = array($sLinkPage, $sLinkSyn);
array_shift($aState); array_shift($aState);
switch($aState[0]) switch ($aState[0]) {
{
case 'template': case 'template':
$aTemplateStack[0][0] .= trim($sPart); $aTemplateStack[0][0] .= trim($sPart);
break; break;
@@ -167,8 +160,7 @@ function _parseWikipediaContent($sPageText)
} }
break; break;
case '|': case '|':
if ($aState[0] == 'template' || $aState[0] == 'templateparam') if ($aState[0] == 'template' || $aState[0] == 'templateparam') {
{
// Create a new template paramater // Create a new template paramater
$aState[0] = 'templateparam'; $aState[0] = 'templateparam';
array_unshift($aTemplateStack[0][1], ''); array_unshift($aTemplateStack[0][1], '');
@@ -176,8 +168,7 @@ function _parseWikipediaContent($sPageText)
if ($aState[0] == 'link') $aState[0] = 'linksynonim'; if ($aState[0] == 'link') $aState[0] = 'linksynonim';
break; break;
default: default:
switch($aState[0]) switch ($aState[0]) {
{
case 'template': case 'template':
$aTemplateStack[0][0] .= trim($sPart); $aTemplateStack[0][0] .= trim($sPart);
break; break;
@@ -206,181 +197,139 @@ function _parseWikipediaContent($sPageText)
function _templatesToProperties($aTemplates) function _templatesToProperties($aTemplates)
{ {
$aPageProperties = array(); $aPageProperties = array();
foreach($aTemplates as $iTemplate => $aTemplate) foreach ($aTemplates as $iTemplate => $aTemplate) {
{
$aParams = array(); $aParams = array();
foreach(array_reverse($aTemplate[1]) as $iParam => $sParam) foreach (array_reverse($aTemplate[1]) as $iParam => $sParam) {
{ if (($iPos = strpos($sParam, '=')) === FALSE) {
if (($iPos = strpos($sParam, '=')) === FALSE)
{
$aParams[] = trim($sParam); $aParams[] = trim($sParam);
} } else {
else
{
$aParams[trim(substr($sParam, 0, $iPos))] = trim(substr($sParam, $iPos+1)); $aParams[trim(substr($sParam, 0, $iPos))] = trim(substr($sParam, $iPos+1));
} }
} }
$aTemplates[$iTemplate][1] = $aParams; $aTemplates[$iTemplate][1] = $aParams;
if (!isset($aPageProperties['sOfficialName']) && isset($aParams['official_name']) && $aParams['official_name']) $aPageProperties['sOfficialName'] = $aParams['official_name']; if (!isset($aPageProperties['sOfficialName']) && isset($aParams['official_name']) && $aParams['official_name']) $aPageProperties['sOfficialName'] = $aParams['official_name'];
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population']) && $aParams['population'] && preg_match('#^[0-9.,]+#', $aParams['population'])) if (!isset($aPageProperties['iPopulation']) && isset($aParams['population']) && $aParams['population'] && preg_match('#^[0-9.,]+#', $aParams['population'])) {
{
$aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population']); $aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population']);
} }
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_total']) && $aParams['population_total'] && preg_match('#^[0-9.,]+#', $aParams['population_total'])) if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_total']) && $aParams['population_total'] && preg_match('#^[0-9.,]+#', $aParams['population_total'])) {
{
$aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population_total']); $aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population_total']);
} }
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_urban']) && $aParams['population_urban'] && preg_match('#^[0-9.,]+#', $aParams['population_urban'])) if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_urban']) && $aParams['population_urban'] && preg_match('#^[0-9.,]+#', $aParams['population_urban'])) {
{
$aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population_urban']); $aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population_urban']);
} }
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_estimate']) && $aParams['population_estimate'] && preg_match('#^[0-9.,]+#', $aParams['population_estimate'])) if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_estimate']) && $aParams['population_estimate'] && preg_match('#^[0-9.,]+#', $aParams['population_estimate'])) {
{
$aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population_estimate']); $aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population_estimate']);
} }
if (!isset($aPageProperties['sWebsite']) && isset($aParams['website']) && $aParams['website']) if (!isset($aPageProperties['sWebsite']) && isset($aParams['website']) && $aParams['website']) {
{ if (preg_match('#^\\[?([^ \\]]+)[^\\]]*\\]?$#', $aParams['website'], $aMatch)) {
if (preg_match('#^\\[?([^ \\]]+)[^\\]]*\\]?$#', $aParams['website'], $aMatch))
{
$aPageProperties['sWebsite'] = $aMatch[1]; $aPageProperties['sWebsite'] = $aMatch[1];
if (strpos($aPageProperties['sWebsite'],':/'.'/') === FALSE) if (strpos($aPageProperties['sWebsite'],':/'.'/') === FALSE) {
{
$aPageProperties['sWebsite'] = 'http:/'.'/'.$aPageProperties['sWebsite']; $aPageProperties['sWebsite'] = 'http:/'.'/'.$aPageProperties['sWebsite'];
} }
} }
} }
if (!isset($aPageProperties['sTopLevelDomain']) && isset($aParams['cctld']) && $aParams['cctld']) if (!isset($aPageProperties['sTopLevelDomain']) && isset($aParams['cctld']) && $aParams['cctld']) {
{
$aPageProperties['sTopLevelDomain'] = str_replace(array('[',']','.'),'', $aParams['cctld']); $aPageProperties['sTopLevelDomain'] = str_replace(array('[',']','.'),'', $aParams['cctld']);
} }
if (!isset($aPageProperties['sInfoboxType']) && strtolower(substr($aTemplate[0],0,7)) == 'infobox') if (!isset($aPageProperties['sInfoboxType']) && strtolower(substr($aTemplate[0],0,7)) == 'infobox') {
{
$aPageProperties['sInfoboxType'] = trim(substr($aTemplate[0],8)); $aPageProperties['sInfoboxType'] = trim(substr($aTemplate[0],8));
// $aPageProperties['aInfoboxParams'] = $aParams; // $aPageProperties['aInfoboxParams'] = $aParams;
} }
// Assume the first template with lots of params is the type (fallback for infobox) // Assume the first template with lots of params is the type (fallback for infobox)
if (!isset($aPageProperties['sPossibleInfoboxType']) && sizeof($aParams) > 10) if (!isset($aPageProperties['sPossibleInfoboxType']) && sizeof($aParams) > 10) {
{
$aPageProperties['sPossibleInfoboxType'] = trim($aTemplate[0]); $aPageProperties['sPossibleInfoboxType'] = trim($aTemplate[0]);
// $aPageProperties['aInfoboxParams'] = $aParams; // $aPageProperties['aInfoboxParams'] = $aParams;
} }
// do we have a lat/lon // do we have a lat/lon
if (!isset($aPageProperties['fLat'])) if (!isset($aPageProperties['fLat'])) {
{ if (isset($aParams['latd']) && isset($aParams['longd'])) {
if (isset($aParams['latd']) && isset($aParams['longd']))
{
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams['latd'], @$aParams['latm'], @$aParams['lats'], @$aParams['latNS']); $aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams['latd'], @$aParams['latm'], @$aParams['lats'], @$aParams['latNS']);
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams['longd'], @$aParams['longm'], @$aParams['longs'], @$aParams['longEW']); $aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams['longd'], @$aParams['longm'], @$aParams['longs'], @$aParams['longEW']);
} }
if (isset($aParams['lat_degrees']) && isset($aParams['lat_degrees'])) if (isset($aParams['lat_degrees']) && isset($aParams['lat_degrees'])) {
{
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams['lat_degrees'], @$aParams['lat_minutes'], @$aParams['lat_seconds'], @$aParams['lat_direction']); $aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams['lat_degrees'], @$aParams['lat_minutes'], @$aParams['lat_seconds'], @$aParams['lat_direction']);
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams['long_degrees'], @$aParams['long_minutes'], @$aParams['long_seconds'], @$aParams['long_direction']); $aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams['long_degrees'], @$aParams['long_minutes'], @$aParams['long_seconds'], @$aParams['long_direction']);
} }
if (isset($aParams['latitude']) && isset($aParams['longitude'])) if (isset($aParams['latitude']) && isset($aParams['longitude'])) {
{ if (preg_match('#[0-9.]+#', $aParams['latitude']) && preg_match('#[0-9.]+#', $aParams['longitude'])) {
if (preg_match('#[0-9.]+#', $aParams['latitude']) && preg_match('#[0-9.]+#', $aParams['longitude']))
{
$aPageProperties['fLat'] = (float)$aParams['latitude']; $aPageProperties['fLat'] = (float)$aParams['latitude'];
$aPageProperties['fLon'] = (float)$aParams['longitude']; $aPageProperties['fLon'] = (float)$aParams['longitude'];
} }
} }
if (strtolower($aTemplate[0]) == 'coord') if (strtolower($aTemplate[0]) == 'coord') {
{ if (isset($aParams[3]) && (strtoupper($aParams[3]) == 'N' || strtoupper($aParams[3]) == 'S')) {
if (isset($aParams[3]) && (strtoupper($aParams[3]) == 'N' || strtoupper($aParams[3]) == 'S'))
{
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams[0], $aParams[1], $aParams[2], $aParams[3]); $aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams[0], $aParams[1], $aParams[2], $aParams[3]);
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams[4], $aParams[5], $aParams[6], $aParams[7]); $aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams[4], $aParams[5], $aParams[6], $aParams[7]);
} } elseif (isset($aParams[0]) && isset($aParams[1]) && isset($aParams[2]) && (strtoupper($aParams[2]) == 'N' || strtoupper($aParams[2]) == 'S')) {
elseif (isset($aParams[0]) && isset($aParams[1]) && isset($aParams[2]) && (strtoupper($aParams[2]) == 'N' || strtoupper($aParams[2]) == 'S'))
{
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams[0], $aParams[1], 0, $aParams[2]); $aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams[0], $aParams[1], 0, $aParams[2]);
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams[3], $aParams[4], 0, $aParams[5]); $aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams[3], $aParams[4], 0, $aParams[5]);
} } else if (isset($aParams[0]) && isset($aParams[1]) && (strtoupper($aParams[1]) == 'N' || strtoupper($aParams[1]) == 'S')) {
else if (isset($aParams[0]) && isset($aParams[1]) && (strtoupper($aParams[1]) == 'N' || strtoupper($aParams[1]) == 'S'))
{
$aPageProperties['fLat'] = (strtoupper($aParams[1]) == 'N'?1:-1) * (float)$aParams[0]; $aPageProperties['fLat'] = (strtoupper($aParams[1]) == 'N'?1:-1) * (float)$aParams[0];
$aPageProperties['fLon'] = (strtoupper($aParams[3]) == 'E'?1:-1) * (float)$aParams[2]; $aPageProperties['fLon'] = (strtoupper($aParams[3]) == 'E'?1:-1) * (float)$aParams[2];
} } else if (isset($aParams[0]) && is_numeric($aParams[0]) && isset($aParams[1]) && is_numeric($aParams[1])) {
else if (isset($aParams[0]) && is_numeric($aParams[0]) && isset($aParams[1]) && is_numeric($aParams[1]))
{
$aPageProperties['fLat'] = (float)$aParams[0]; $aPageProperties['fLat'] = (float)$aParams[0];
$aPageProperties['fLon'] = (float)$aParams[1]; $aPageProperties['fLon'] = (float)$aParams[1];
} }
} }
if (isset($aParams['Latitude']) && isset($aParams['Longitude'])) if (isset($aParams['Latitude']) && isset($aParams['Longitude'])) {
{
$aParams['Latitude'] = str_replace('&nbsp;',' ',$aParams['Latitude']); $aParams['Latitude'] = str_replace('&nbsp;',' ',$aParams['Latitude']);
$aParams['Longitude'] = str_replace('&nbsp;',' ',$aParams['Longitude']); $aParams['Longitude'] = str_replace('&nbsp;',' ',$aParams['Longitude']);
if (preg_match('#^([0-9]+)°(([0-9]+))? ([NS]) to ([0-9]+)°(([0-9]+))? ([NS])#', $aParams['Latitude'], $aMatch)) if (preg_match('#^([0-9]+)°(([0-9]+))? ([NS]) to ([0-9]+)°(([0-9]+))? ([NS])#', $aParams['Latitude'], $aMatch)) {
{
$aPageProperties['fLat'] = $aPageProperties['fLat'] =
(degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]) (degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4])
+degreesAndMinutesToDecimal($aMatch[5], $aMatch[7], 0, $aMatch[8])) / 2; +degreesAndMinutesToDecimal($aMatch[5], $aMatch[7], 0, $aMatch[8])) / 2;
} } else if (preg_match('#^([0-9]+)°(([0-9]+))? ([NS])#', $aParams['Latitude'], $aMatch)) {
else if (preg_match('#^([0-9]+)°(([0-9]+))? ([NS])#', $aParams['Latitude'], $aMatch))
{
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]); $aPageProperties['fLat'] = degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]);
} }
if (preg_match('#^([0-9]+)°(([0-9]+))? ([EW]) to ([0-9]+)°(([0-9]+))? ([EW])#', $aParams['Longitude'], $aMatch)) if (preg_match('#^([0-9]+)°(([0-9]+))? ([EW]) to ([0-9]+)°(([0-9]+))? ([EW])#', $aParams['Longitude'], $aMatch)) {
{
$aPageProperties['fLon'] = $aPageProperties['fLon'] =
(degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]) (degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4])
+degreesAndMinutesToDecimal($aMatch[5], $aMatch[7], 0, $aMatch[8])) / 2; +degreesAndMinutesToDecimal($aMatch[5], $aMatch[7], 0, $aMatch[8])) / 2;
} } else if (preg_match('#^([0-9]+)°(([0-9]+))? ([EW])#', $aParams['Longitude'], $aMatch)) {
else if (preg_match('#^([0-9]+)°(([0-9]+))? ([EW])#', $aParams['Longitude'], $aMatch))
{
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]); $aPageProperties['fLon'] = degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]);
} }
} }
} }
} }
if (isset($aPageProperties['sPossibleInfoboxType'])) if (isset($aPageProperties['sPossibleInfoboxType'])) {
{
if (!isset($aPageProperties['sInfoboxType'])) $aPageProperties['sInfoboxType'] = '#'.$aPageProperties['sPossibleInfoboxType']; if (!isset($aPageProperties['sInfoboxType'])) $aPageProperties['sInfoboxType'] = '#'.$aPageProperties['sPossibleInfoboxType'];
unset($aPageProperties['sPossibleInfoboxType']); unset($aPageProperties['sPossibleInfoboxType']);
} }
return $aPageProperties; return $aPageProperties;
} }
if (isset($aCMDResult['parse-wikipedia'])) if (isset($aCMDResult['parse-wikipedia'])) {
{
$oDB =& getDB(); $oDB =& getDB();
$aArticleNames = $oDB->getCol('select page_title from content where page_namespace = 0 and page_id %10 = '.$aCMDResult['parse-wikipedia'].' and (page_content ilike \'%{{Coord%\' or (page_content ilike \'%lat%\' and page_content ilike \'%lon%\'))'); $aArticleNames = $oDB->getCol('select page_title from content where page_namespace = 0 and page_id %10 = '.$aCMDResult['parse-wikipedia'].' and (page_content ilike \'%{{Coord%\' or (page_content ilike \'%lat%\' and page_content ilike \'%lon%\'))');
// $aArticleNames = $oDB->getCol($sSQL = 'select page_title from content where page_namespace = 0 and (page_content ilike \'%{{Coord%\' or (page_content ilike \'%lat%\' and page_content ilike \'%lon%\')) and page_title in (\'Virginia\')'); // $aArticleNames = $oDB->getCol($sSQL = 'select page_title from content where page_namespace = 0 and (page_content ilike \'%{{Coord%\' or (page_content ilike \'%lat%\' and page_content ilike \'%lon%\')) and page_title in (\'Virginia\')');
foreach($aArticleNames as $sArticleName) foreach ($aArticleNames as $sArticleName) {
{
$sPageText = $oDB->getOne('select page_content from content where page_namespace = 0 and page_title = \''.pg_escape_string($sArticleName).'\''); $sPageText = $oDB->getOne('select page_content from content where page_namespace = 0 and page_title = \''.pg_escape_string($sArticleName).'\'');
$aP = _templatesToProperties(_parseWikipediaContent($sPageText)); $aP = _templatesToProperties(_parseWikipediaContent($sPageText));
if (isset($aP['sInfoboxType'])) if (isset($aP['sInfoboxType'])) {
{
$aP['sInfoboxType'] = preg_replace('#\\s+#',' ',$aP['sInfoboxType']); $aP['sInfoboxType'] = preg_replace('#\\s+#',' ',$aP['sInfoboxType']);
$sSQL = 'update wikipedia_article set '; $sSQL = 'update wikipedia_article set ';
$sSQL .= 'infobox_type = \''.pg_escape_string($aP['sInfoboxType']).'\''; $sSQL .= 'infobox_type = \''.pg_escape_string($aP['sInfoboxType']).'\'';
$sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';'; $sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';';
$oDB->query($sSQL); $oDB->query($sSQL);
} }
if (isset($aP['iPopulation'])) if (isset($aP['iPopulation'])) {
{
$sSQL = 'update wikipedia_article set '; $sSQL = 'update wikipedia_article set ';
$sSQL .= 'population = \''.pg_escape_string($aP['iPopulation']).'\''; $sSQL .= 'population = \''.pg_escape_string($aP['iPopulation']).'\'';
$sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';'; $sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';';
$oDB->query($sSQL); $oDB->query($sSQL);
} }
if (isset($aP['sWebsite'])) if (isset($aP['sWebsite'])) {
{
$sSQL = 'update wikipedia_article set '; $sSQL = 'update wikipedia_article set ';
$sSQL .= 'website = \''.pg_escape_string($aP['sWebsite']).'\''; $sSQL .= 'website = \''.pg_escape_string($aP['sWebsite']).'\'';
$sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';'; $sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';';
$oDB->query($sSQL); $oDB->query($sSQL);
} }
if (isset($aP['fLat']) && ($aP['fLat']!='-0' || $aP['fLon']!='-0')) if (isset($aP['fLat']) && ($aP['fLat']!='-0' || $aP['fLon']!='-0')) {
{
if (!isset($aP['sInfoboxType'])) $aP['sInfoboxType'] = ''; if (!isset($aP['sInfoboxType'])) $aP['sInfoboxType'] = '';
echo $sArticleName.'|'.$aP['sInfoboxType'].'|'.$aP['fLat'].'|'.$aP['fLon'] ."\n"; echo $sArticleName.'|'.$aP['sInfoboxType'].'|'.$aP['fLat'].'|'.$aP['fLon'] ."\n";
$sSQL = 'update wikipedia_article set '; $sSQL = 'update wikipedia_article set ';
@@ -395,8 +344,7 @@ if (isset($aCMDResult['parse-wikipedia']))
function nominatimXMLStart($hParser, $sName, $aAttr) function nominatimXMLStart($hParser, $sName, $aAttr)
{ {
global $aNominatRecords; global $aNominatRecords;
switch($sName) switch ($sName) {
{
case 'PLACE': case 'PLACE':
$aNominatRecords[] = $aAttr; $aNominatRecords[] = $aAttr;
break; break;
@@ -408,16 +356,14 @@ function nominatimXMLEnd($hParser, $sName)
} }
if (isset($aCMDResult['link'])) if (isset($aCMDResult['link'])) {
{
$oDB =& getDB(); $oDB =& getDB();
$aWikiArticles = $oDB->getAll("select * from wikipedia_article where language = 'en' and lat is not null and osm_type is null and totalcount < 31 order by importance desc limit 200000"); $aWikiArticles = $oDB->getAll("select * from wikipedia_article where language = 'en' and lat is not null and osm_type is null and totalcount < 31 order by importance desc limit 200000");
// If you point this script at production OSM you will be blocked // If you point this script at production OSM you will be blocked
$sNominatimBaseURL = 'http://SEVERNAME/search.php'; $sNominatimBaseURL = 'http://SEVERNAME/search.php';
foreach($aWikiArticles as $aRecord) foreach ($aWikiArticles as $aRecord) {
{
$aRecord['name'] = str_replace('_',' ',$aRecord['title']); $aRecord['name'] = str_replace('_',' ',$aRecord['title']);
$sURL = $sNominatimBaseURL.'?format=xml&accept-language=en'; $sURL = $sNominatimBaseURL.'?format=xml&accept-language=en';
@@ -425,8 +371,7 @@ if (isset($aCMDResult['link']))
echo "\n-- ".$aRecord['name'].", ".$aRecord['infobox_type']."\n"; echo "\n-- ".$aRecord['name'].", ".$aRecord['infobox_type']."\n";
$fMaxDist = 0.0000001; $fMaxDist = 0.0000001;
$bUnknown = false; $bUnknown = false;
switch(strtolower($aRecord['infobox_type'])) switch (strtolower($aRecord['infobox_type'])) {
{
case 'former country': case 'former country':
continue 2; continue 2;
case 'sea': case 'sea':
@@ -535,11 +480,9 @@ if (isset($aCMDResult['link']))
xml_parse($hXMLParser, $sXML, true); xml_parse($hXMLParser, $sXML, true);
xml_parser_free($hXMLParser); xml_parser_free($hXMLParser);
if (!isset($aNominatRecords[0])) if (!isset($aNominatRecords[0])) {
{
$aNameParts = preg_split('#[(,]#',$aRecord['name']); $aNameParts = preg_split('#[(,]#',$aRecord['name']);
if (sizeof($aNameParts) > 1) if (sizeof($aNameParts) > 1) {
{
$sNameURL = $sURL.'&q='.urlencode(trim($aNameParts[0])); $sNameURL = $sURL.'&q='.urlencode(trim($aNameParts[0]));
var_Dump($sNameURL); var_Dump($sNameURL);
$sXML = file_get_contents($sNameURL); $sXML = file_get_contents($sNameURL);
@@ -553,8 +496,7 @@ if (isset($aCMDResult['link']))
} }
// assume first is best/right // assume first is best/right
for($i = 0; $i < sizeof($aNominatRecords); $i++) for ($i = 0; $i < sizeof($aNominatRecords); $i++) {
{
$fDiff = ($aRecord['lat']-$aNominatRecords[$i]['LAT']) * ($aRecord['lat']-$aNominatRecords[$i]['LAT']); $fDiff = ($aRecord['lat']-$aNominatRecords[$i]['LAT']) * ($aRecord['lat']-$aNominatRecords[$i]['LAT']);
$fDiff += ($aRecord['lon']-$aNominatRecords[$i]['LON']) * ($aRecord['lon']-$aNominatRecords[$i]['LON']); $fDiff += ($aRecord['lon']-$aNominatRecords[$i]['LON']) * ($aRecord['lon']-$aNominatRecords[$i]['LON']);
$fDiff = sqrt($fDiff); $fDiff = sqrt($fDiff);
@@ -572,15 +514,11 @@ if (isset($aCMDResult['link']))
else $fMaxDist = 0.001; else $fMaxDist = 0.001;
} }
echo "-- FOUND \"".substr($aNominatRecords[$i]['DISPLAY_NAME'],0,50)."\", ".$aNominatRecords[$i]['CLASS'].", ".$aNominatRecords[$i]['TYPE'].", ".$aNominatRecords[$i]['PLACE_RANK'].", ".$aNominatRecords[$i]['OSM_TYPE']." (dist:$fDiff, max:$fMaxDist)\n"; echo "-- FOUND \"".substr($aNominatRecords[$i]['DISPLAY_NAME'],0,50)."\", ".$aNominatRecords[$i]['CLASS'].", ".$aNominatRecords[$i]['TYPE'].", ".$aNominatRecords[$i]['PLACE_RANK'].", ".$aNominatRecords[$i]['OSM_TYPE']." (dist:$fDiff, max:$fMaxDist)\n";
if ($fDiff > $fMaxDist) if ($fDiff > $fMaxDist) {
{
echo "-- Diff too big $fDiff (max: $fMaxDist)".$aRecord['lat'].','.$aNominatRecords[$i]['LAT'].' & '.$aRecord['lon'].','.$aNominatRecords[$i]['LON']." \n"; echo "-- Diff too big $fDiff (max: $fMaxDist)".$aRecord['lat'].','.$aNominatRecords[$i]['LAT'].' & '.$aRecord['lon'].','.$aNominatRecords[$i]['LON']." \n";
} } else {
else
{
$sSQL = "update wikipedia_article set osm_type="; $sSQL = "update wikipedia_article set osm_type=";
switch($aNominatRecords[$i]['OSM_TYPE']) switch ($aNominatRecords[$i]['OSM_TYPE']) {
{
case 'relation': $sSQL .= "'R'"; break; case 'relation': $sSQL .= "'R'"; break;
case 'way': $sSQL .= "'W'"; break; case 'way': $sSQL .= "'W'"; break;
case 'node': $sSQL .= "'N'"; break; case 'node': $sSQL .= "'N'"; break;

View File

@@ -16,16 +16,14 @@ $aCMDOptions = array(
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
if (isset($aCMDResult['parse-tiger'])) if (isset($aCMDResult['parse-tiger'])) {
{
if (!file_exists(CONST_Tiger_Data_Path)) mkdir(CONST_Tiger_Data_Path); if (!file_exists(CONST_Tiger_Data_Path)) mkdir(CONST_Tiger_Data_Path);
$sTempDir = tempnam('/tmp', 'tiger'); $sTempDir = tempnam('/tmp', 'tiger');
unlink($sTempDir); unlink($sTempDir);
mkdir($sTempDir); mkdir($sTempDir);
foreach(glob($aCMDResult['parse-tiger'].'/tl_20??_?????_edges.zip', 0) as $sImportFile) foreach (glob($aCMDResult['parse-tiger'].'/tl_20??_?????_edges.zip', 0) as $sImportFile) {
{
set_time_limit(30); set_time_limit(30);
preg_match('#([0-9]{5})_(.*)#',basename($sImportFile), $aMatch); preg_match('#([0-9]{5})_(.*)#',basename($sImportFile), $aMatch);
$sCountyID = $aMatch[1]; $sCountyID = $aMatch[1];
@@ -33,29 +31,21 @@ if (isset($aCMDResult['parse-tiger']))
$sUnzipCmd = "unzip -d $sTempDir $sImportFile"; $sUnzipCmd = "unzip -d $sTempDir $sImportFile";
exec($sUnzipCmd); exec($sUnzipCmd);
$sShapeFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.shp'; $sShapeFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.shp';
if (!file_exists($sShapeFile)) if (!file_exists($sShapeFile)) {
{
echo "Failed unzip ($sImportFile)\n"; echo "Failed unzip ($sImportFile)\n";
} } else {
else
{
$sParseCmd = CONST_BasePath.'/utils/tigerAddressImport.py '.$sShapeFile; $sParseCmd = CONST_BasePath.'/utils/tigerAddressImport.py '.$sShapeFile;
exec($sParseCmd); exec($sParseCmd);
$sOsmFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.osm1.osm'; $sOsmFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.osm1.osm';
if (!file_exists($sOsmFile)) if (!file_exists($sOsmFile)) {
{
echo "Failed parse ($sImportFile)\n"; echo "Failed parse ($sImportFile)\n";
} } else {
else
{
copy($sOsmFile, CONST_Tiger_Data_Path.'/'.$sCountyID.'.sql'); copy($sOsmFile, CONST_Tiger_Data_Path.'/'.$sCountyID.'.sql');
} }
} }
// Cleanup // Cleanup
foreach(glob($sTempDir.'/*') as $sTmpFile) foreach (glob($sTempDir.'/*') as $sTmpFile) {
{
unlink($sTmpFile); unlink($sTmpFile);
} }
} }
} }

View File

@@ -29,8 +29,7 @@ getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
$oDB =& getDB(); $oDB =& getDB();
$oParams = new ParameterParser($aCMDResult); $oParams = new ParameterParser($aCMDResult);
if ($oParams->getBool('search')) if ($oParams->getBool('search')) {
{
if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false'; if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false';
$oGeocode = new Geocode($oDB); $oGeocode = new Geocode($oDB);
@@ -41,12 +40,11 @@ if ($oParams->getBool('search'))
$aSearchResults = $oGeocode->lookup(); $aSearchResults = $oGeocode->lookup();
if (version_compare(phpversion(), "5.4.0", '<')) if (version_compare(phpversion(), "5.4.0", '<')) {
echo json_encode($aSearchResults); echo json_encode($aSearchResults);
else } else {
echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n"; echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
} }
else } else {
{
showUsage($aCMDOptions, true); showUsage($aCMDOptions, true);
} }

View File

@@ -13,27 +13,23 @@ $sHost2Escaped = str_replace('/', '\\/', $sHost2);
$aToDo = array(251, 293, 328, 399.1, 455.1, 479, 496, 499, 574, 609, 702, 790, 846, 865, 878, 894, 902, 961, 980); $aToDo = array(251, 293, 328, 399.1, 455.1, 479, 496, 499, 574, 609, 702, 790, 846, 865, 878, 894, 902, 961, 980);
$hFile = @fopen($sFile, "r"); $hFile = @fopen($sFile, "r");
if (!$hFile) if (!$hFile) {
{
echo "Unable to open file: $sFile\n"; echo "Unable to open file: $sFile\n";
exit; exit;
} }
$i = 0; $i = 0;
while (($sLine = fgets($hFile, 10000)) !== false) while (($sLine = fgets($hFile, 10000)) !== false) {
{
$i++; $i++;
if (!in_array($i, $aToDo)) continue; if (!in_array($i, $aToDo)) continue;
if (preg_match('#"GET (.*) HTTP/1.[01]"#', $sLine, $aResult)) if (preg_match('#"GET (.*) HTTP/1.[01]"#', $sLine, $aResult)) {
{
$sURL1 = $sHost1.$aResult[1]; $sURL1 = $sHost1.$aResult[1];
$sURL2 = $sHost2.$aResult[1]; $sURL2 = $sHost2.$aResult[1];
$sRes1 = ''; $sRes1 = '';
$k = 0; $k = 0;
while(!$sRes1 && $k < 10) while (!$sRes1 && $k < 10) {
{
$sRes1 = file_get_contents($sURL1); $sRes1 = file_get_contents($sURL1);
$k++; $k++;
if (!$sRes1) sleep(10); if (!$sRes1) sleep(10);
@@ -48,29 +44,24 @@ while (($sLine = fgets($hFile, 10000)) !== false)
$sRes2 = str_replace($sHost2, '', $sRes2); $sRes2 = str_replace($sHost2, '', $sRes2);
$sRes2 = str_replace($sHost2Escaped, '', $sRes2); $sRes2 = str_replace($sHost2Escaped, '', $sRes2);
if ($sRes1 != $sRes2) if ($sRes1 != $sRes2) {
{
echo "$i:\n"; echo "$i:\n";
var_dump($sURL1, $sURL2); var_dump($sURL1, $sURL2);
$sRes = $sURL1.":\n"; $sRes = $sURL1.":\n";
for ($j = 0; $j < strlen($sRes1); $j+=40) for ($j = 0; $j < strlen($sRes1); $j+=40) {
{
$sRes .= substr($sRes1, $j, 40)."\n"; $sRes .= substr($sRes1, $j, 40)."\n";
} }
file_put_contents('log/'.$i.'.1', $sRes); file_put_contents('log/'.$i.'.1', $sRes);
$sRes = $sURL2.":\n"; $sRes = $sURL2.":\n";
for ($j = 0; $j < strlen($sRes2); $j+=40) for ($j = 0; $j < strlen($sRes2); $j+=40) {
{
$sRes .= substr($sRes2, $j, 40)."\n"; $sRes .= substr($sRes2, $j, 40)."\n";
} }
file_put_contents('log/'.$i.'.2', $sRes); file_put_contents('log/'.$i.'.2', $sRes);
} }
echo ".\n"; echo ".\n";
} } else {
else
{
var_dump($sLine); var_dump($sLine);
} }
} }

View File

@@ -44,20 +44,16 @@ getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
$bDidSomething = false; $bDidSomething = false;
// Check if osm-file is set and points to a valid file if --all or --import-data is given // Check if osm-file is set and points to a valid file if --all or --import-data is given
if ($aCMDResult['import-data'] || $aCMDResult['all']) if ($aCMDResult['import-data'] || $aCMDResult['all']) {
{ if (!isset($aCMDResult['osm-file'])) {
if (!isset($aCMDResult['osm-file']))
{
fail('missing --osm-file for data import'); fail('missing --osm-file for data import');
} }
if (!file_exists($aCMDResult['osm-file'])) if (!file_exists($aCMDResult['osm-file'])) {
{
fail('the path supplied to --osm-file does not exist'); fail('the path supplied to --osm-file does not exist');
} }
if (!is_readable($aCMDResult['osm-file'])) if (!is_readable($aCMDResult['osm-file'])) {
{
fail('osm-file "'.$aCMDResult['osm-file'].'" not readable'); fail('osm-file "'.$aCMDResult['osm-file'].'" not readable');
} }
} }
@@ -65,44 +61,36 @@ if ($aCMDResult['import-data'] || $aCMDResult['all'])
// This is a pretty hard core default - the number of processors in the box - 1 // This is a pretty hard core default - the number of processors in the box - 1
$iInstances = isset($aCMDResult['threads'])?$aCMDResult['threads']:(getProcessorCount()-1); $iInstances = isset($aCMDResult['threads'])?$aCMDResult['threads']:(getProcessorCount()-1);
if ($iInstances < 1) if ($iInstances < 1) {
{
$iInstances = 1; $iInstances = 1;
echo "WARNING: resetting threads to $iInstances\n"; echo "WARNING: resetting threads to $iInstances\n";
} }
if ($iInstances > getProcessorCount()) if ($iInstances > getProcessorCount()) {
{
$iInstances = getProcessorCount(); $iInstances = getProcessorCount();
echo "WARNING: resetting threads to $iInstances\n"; echo "WARNING: resetting threads to $iInstances\n";
} }
// Assume we can steal all the cache memory in the box (unless told otherwise) // Assume we can steal all the cache memory in the box (unless told otherwise)
if (isset($aCMDResult['osm2pgsql-cache'])) if (isset($aCMDResult['osm2pgsql-cache'])) {
{
$iCacheMemory = $aCMDResult['osm2pgsql-cache']; $iCacheMemory = $aCMDResult['osm2pgsql-cache'];
} } else {
else
{
$iCacheMemory = getCacheMemoryMB(); $iCacheMemory = getCacheMemoryMB();
} }
$aDSNInfo = DB::parseDSN(CONST_Database_DSN); $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432; if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
if ($aCMDResult['create-db'] || $aCMDResult['all']) if ($aCMDResult['create-db'] || $aCMDResult['all']) {
{
echo "Create DB\n"; echo "Create DB\n";
$bDidSomething = true; $bDidSomething = true;
$oDB = DB::connect(CONST_Database_DSN, false); $oDB = DB::connect(CONST_Database_DSN, false);
if (!PEAR::isError($oDB)) if (!PEAR::isError($oDB)) {
{
fail('database already exists ('.CONST_Database_DSN.')'); fail('database already exists ('.CONST_Database_DSN.')');
} }
passthruCheckReturn('createdb -E UTF-8 -p '.$aDSNInfo['port'].' '.$aDSNInfo['database']); passthruCheckReturn('createdb -E UTF-8 -p '.$aDSNInfo['port'].' '.$aDSNInfo['database']);
} }
if ($aCMDResult['setup-db'] || $aCMDResult['all']) if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
{
echo "Setup DB\n"; echo "Setup DB\n";
$bDidSomething = true; $bDidSomething = true;
// TODO: path detection, detection memory, etc. // TODO: path detection, detection memory, etc.
@@ -112,8 +100,7 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
$fPostgresVersion = getPostgresVersion($oDB); $fPostgresVersion = getPostgresVersion($oDB);
echo 'Postgres version found: '.$fPostgresVersion."\n"; echo 'Postgres version found: '.$fPostgresVersion."\n";
if ($fPostgresVersion < 9.1) if ($fPostgresVersion < 9.1) {
{
fail("Minimum supported version of Postgresql is 9.1."); fail("Minimum supported version of Postgresql is 9.1.");
} }
@@ -125,8 +112,7 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
// versions add a dummy function that returns nothing. // versions add a dummy function that returns nothing.
$iNumFunc = chksql($oDB->getOne("select count(*) from pg_proc where proname = 'hstore_to_json'")); $iNumFunc = chksql($oDB->getOne("select count(*) from pg_proc where proname = 'hstore_to_json'"));
if ($iNumFunc == 0) if ($iNumFunc == 0) {
{
pgsqlRunScript("create function hstore_to_json(dummy hstore) returns text AS 'select null::text' language sql immutable"); pgsqlRunScript("create function hstore_to_json(dummy hstore) returns text AS 'select null::text' language sql immutable");
echo "WARNING: Postgresql is too old. extratags and namedetails API not available."; echo "WARNING: Postgresql is too old. extratags and namedetails API not available.";
} }
@@ -134,8 +120,7 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
$fPostgisVersion = getPostgisVersion($oDB); $fPostgisVersion = getPostgisVersion($oDB);
echo 'Postgis version found: '.$fPostgisVersion."\n"; echo 'Postgis version found: '.$fPostgisVersion."\n";
if ($fPostgisVersion < 2.1) if ($fPostgisVersion < 2.1) {
{
// Function was renamed in 2.1 and throws an annoying deprecation warning // Function was renamed in 2.1 and throws an annoying deprecation warning
pgsqlRunScript('ALTER FUNCTION st_line_interpolate_point(geometry, double precision) RENAME TO ST_LineInterpolatePoint'); pgsqlRunScript('ALTER FUNCTION st_line_interpolate_point(geometry, double precision) RENAME TO ST_LineInterpolatePoint');
} }
@@ -144,21 +129,16 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
pgsqlRunScriptFile(CONST_BasePath.'/data/country_naturalearthdata.sql'); pgsqlRunScriptFile(CONST_BasePath.'/data/country_naturalearthdata.sql');
pgsqlRunScriptFile(CONST_BasePath.'/data/country_osm_grid.sql'); pgsqlRunScriptFile(CONST_BasePath.'/data/country_osm_grid.sql');
pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_table.sql'); pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_table.sql');
if (file_exists(CONST_BasePath.'/data/gb_postcode_data.sql.gz')) if (file_exists(CONST_BasePath.'/data/gb_postcode_data.sql.gz')) {
{
pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_data.sql.gz'); pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_data.sql.gz');
} } else {
else
{
echo "WARNING: external UK postcode table not found.\n"; echo "WARNING: external UK postcode table not found.\n";
} }
if (CONST_Use_Extra_US_Postcodes) if (CONST_Use_Extra_US_Postcodes) {
{
pgsqlRunScriptFile(CONST_BasePath.'/data/us_postcode.sql'); pgsqlRunScriptFile(CONST_BasePath.'/data/us_postcode.sql');
} }
if ($aCMDResult['no-partitions']) if ($aCMDResult['no-partitions']) {
{
pgsqlRunScript('update country_name set partition = 0'); pgsqlRunScript('update country_name set partition = 0');
} }
@@ -170,20 +150,17 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
pgsqlRunScript('create type wikipedia_article_match as ()'); pgsqlRunScript('create type wikipedia_article_match as ()');
} }
if ($aCMDResult['import-data'] || $aCMDResult['all']) if ($aCMDResult['import-data'] || $aCMDResult['all']) {
{
echo "Import\n"; echo "Import\n";
$bDidSomething = true; $bDidSomething = true;
$osm2pgsql = CONST_Osm2pgsql_Binary; $osm2pgsql = CONST_Osm2pgsql_Binary;
if (!file_exists($osm2pgsql)) if (!file_exists($osm2pgsql)) {
{
echo "Please download and build osm2pgsql.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n"; echo "Please download and build osm2pgsql.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n";
fail("osm2pgsql not found in '$osm2pgsql'"); fail("osm2pgsql not found in '$osm2pgsql'");
} }
if (!is_null(CONST_Osm2pgsql_Flatnode_File)) if (!is_null(CONST_Osm2pgsql_Flatnode_File)) {
{
$osm2pgsql .= ' --flat-nodes '.CONST_Osm2pgsql_Flatnode_File; $osm2pgsql .= ' --flat-nodes '.CONST_Osm2pgsql_Flatnode_File;
} }
if (CONST_Tablespace_Osm2pgsql_Data) if (CONST_Tablespace_Osm2pgsql_Data)
@@ -201,22 +178,19 @@ if ($aCMDResult['import-data'] || $aCMDResult['all'])
passthruCheckReturn($osm2pgsql); passthruCheckReturn($osm2pgsql);
$oDB =& getDB(); $oDB =& getDB();
if (!chksql($oDB->getRow('select * from place limit 1'))) if (!chksql($oDB->getRow('select * from place limit 1'))) {
{
fail('No Data'); fail('No Data');
} }
} }
if ($aCMDResult['create-functions'] || $aCMDResult['all']) if ($aCMDResult['create-functions'] || $aCMDResult['all']) {
{
echo "Functions\n"; echo "Functions\n";
$bDidSomething = true; $bDidSomething = true;
if (!file_exists(CONST_InstallPath.'/module/nominatim.so')) fail("nominatim module not built"); if (!file_exists(CONST_InstallPath.'/module/nominatim.so')) fail("nominatim module not built");
create_sql_functions($aCMDResult); create_sql_functions($aCMDResult);
} }
if ($aCMDResult['create-tables'] || $aCMDResult['all']) if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
{
$bDidSomething = true; $bDidSomething = true;
echo "Tables\n"; echo "Tables\n";
@@ -241,8 +215,7 @@ if ($aCMDResult['create-tables'] || $aCMDResult['all'])
create_sql_functions($aCMDResult); create_sql_functions($aCMDResult);
} }
if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) {
{
echo "Partition Tables\n"; echo "Partition Tables\n";
$bDidSomething = true; $bDidSomething = true;
@@ -264,8 +237,7 @@ if ($aCMDResult['create-partition-tables'] || $aCMDResult['all'])
} }
if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) {
{
echo "Partition Functions\n"; echo "Partition Functions\n";
$bDidSomething = true; $bDidSomething = true;
@@ -274,36 +246,28 @@ if ($aCMDResult['create-partition-functions'] || $aCMDResult['all'])
pgsqlRunPartitionScript($sTemplate); pgsqlRunPartitionScript($sTemplate);
} }
if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) {
{
$bDidSomething = true; $bDidSomething = true;
$sWikiArticlesFile = CONST_BasePath.'/data/wikipedia_article.sql.bin'; $sWikiArticlesFile = CONST_BasePath.'/data/wikipedia_article.sql.bin';
$sWikiRedirectsFile = CONST_BasePath.'/data/wikipedia_redirect.sql.bin'; $sWikiRedirectsFile = CONST_BasePath.'/data/wikipedia_redirect.sql.bin';
if (file_exists($sWikiArticlesFile)) if (file_exists($sWikiArticlesFile)) {
{
echo "Importing wikipedia articles..."; echo "Importing wikipedia articles...";
pgsqlRunDropAndRestore($sWikiArticlesFile); pgsqlRunDropAndRestore($sWikiArticlesFile);
echo "...done\n"; echo "...done\n";
} } else {
else
{
echo "WARNING: wikipedia article dump file not found - places will have default importance\n"; echo "WARNING: wikipedia article dump file not found - places will have default importance\n";
} }
if (file_exists($sWikiRedirectsFile)) if (file_exists($sWikiRedirectsFile)) {
{
echo "Importing wikipedia redirects..."; echo "Importing wikipedia redirects...";
pgsqlRunDropAndRestore($sWikiRedirectsFile); pgsqlRunDropAndRestore($sWikiRedirectsFile);
echo "...done\n"; echo "...done\n";
} } else {
else
{
echo "WARNING: wikipedia redirect dump file not found - some place importance values may be missing\n"; echo "WARNING: wikipedia redirect dump file not found - some place importance values may be missing\n";
} }
} }
if ($aCMDResult['load-data'] || $aCMDResult['all']) if ($aCMDResult['load-data'] || $aCMDResult['all']) {
{
echo "Drop old Data\n"; echo "Drop old Data\n";
$bDidSomething = true; $bDidSomething = true;
@@ -332,8 +296,7 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
$sSQL = 'select distinct partition from country_name'; $sSQL = 'select distinct partition from country_name';
$aPartitions = chksql($oDB->getCol($sSQL)); $aPartitions = chksql($oDB->getCol($sSQL));
if (!$aCMDResult['no-partitions']) $aPartitions[] = 0; if (!$aCMDResult['no-partitions']) $aPartitions[] = 0;
foreach($aPartitions as $sPartition) foreach ($aPartitions as $sPartition) {
{
if (!pg_query($oDB->connection, 'TRUNCATE location_road_'.$sPartition)) fail(pg_last_error($oDB->connection)); if (!pg_query($oDB->connection, 'TRUNCATE location_road_'.$sPartition)) fail(pg_last_error($oDB->connection));
echo '.'; echo '.';
} }
@@ -343,8 +306,7 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
echo ".\n"; echo ".\n";
// pre-create the word list // pre-create the word list
if (!$aCMDResult['disable-token-precalc']) if (!$aCMDResult['disable-token-precalc']) {
{
echo "Loading word list\n"; echo "Loading word list\n";
pgsqlRunScriptFile(CONST_BasePath.'/data/words.sql'); pgsqlRunScriptFile(CONST_BasePath.'/data/words.sql');
} }
@@ -352,8 +314,7 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
echo "Load Data\n"; echo "Load Data\n";
$aDBInstances = array(); $aDBInstances = array();
$iLoadThreads = max(1, $iInstances - 1); $iLoadThreads = max(1, $iInstances - 1);
for($i = 0; $i < $iLoadThreads; $i++) for ($i = 0; $i < $iLoadThreads; $i++) {
{
$aDBInstances[$i] =& getDB(true); $aDBInstances[$i] =& getDB(true);
$sSQL = 'insert into placex (osm_type, osm_id, class, type, name, admin_level, '; $sSQL = 'insert into placex (osm_type, osm_id, class, type, name, admin_level, ';
$sSQL .= 'housenumber, street, addr_place, isin, postcode, country_code, extratags, '; $sSQL .= 'housenumber, street, addr_place, isin, postcode, country_code, extratags, ';
@@ -371,11 +332,9 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection)); if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection));
$bAnyBusy = true; $bAnyBusy = true;
while($bAnyBusy) while ($bAnyBusy) {
{
$bAnyBusy = false; $bAnyBusy = false;
for($i = 0; $i <= $iLoadThreads; $i++) for ($i = 0; $i <= $iLoadThreads; $i++) {
{
if (pg_connection_busy($aDBInstances[$i]->connection)) $bAnyBusy = true; if (pg_connection_busy($aDBInstances[$i]->connection)) $bAnyBusy = true;
} }
sleep(1); sleep(1);
@@ -386,8 +345,7 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
pgsqlRunScript('ANALYSE'); pgsqlRunScript('ANALYSE');
} }
if ($aCMDResult['import-tiger-data']) if ($aCMDResult['import-tiger-data']) {
{
$bDidSomething = true; $bDidSomething = true;
$sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_start.sql'); $sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_start.sql');
@@ -399,31 +357,25 @@ if ($aCMDResult['import-tiger-data'])
pgsqlRunScript($sTemplate, false); pgsqlRunScript($sTemplate, false);
$aDBInstances = array(); $aDBInstances = array();
for($i = 0; $i < $iInstances; $i++) for ($i = 0; $i < $iInstances; $i++) {
{
$aDBInstances[$i] =& getDB(true); $aDBInstances[$i] =& getDB(true);
} }
foreach(glob(CONST_Tiger_Data_Path.'/*.sql') as $sFile) foreach (glob(CONST_Tiger_Data_Path.'/*.sql') as $sFile) {
{
echo $sFile.': '; echo $sFile.': ';
$hFile = fopen($sFile, "r"); $hFile = fopen($sFile, "r");
$sSQL = fgets($hFile, 100000); $sSQL = fgets($hFile, 100000);
$iLines = 0; $iLines = 0;
while(true) while (true) {
{ for ($i = 0; $i < $iInstances; $i++) {
for($i = 0; $i < $iInstances; $i++) if (!pg_connection_busy($aDBInstances[$i]->connection)) {
{ while (pg_get_result($aDBInstances[$i]->connection));
if (!pg_connection_busy($aDBInstances[$i]->connection))
{
while(pg_get_result($aDBInstances[$i]->connection));
$sSQL = fgets($hFile, 100000); $sSQL = fgets($hFile, 100000);
if (!$sSQL) break 2; if (!$sSQL) break 2;
if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection)); if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection));
$iLines++; $iLines++;
if ($iLines == 1000) if ($iLines == 1000) {
{
echo "."; echo ".";
$iLines = 0; $iLines = 0;
} }
@@ -435,11 +387,9 @@ if ($aCMDResult['import-tiger-data'])
fclose($hFile); fclose($hFile);
$bAnyBusy = true; $bAnyBusy = true;
while($bAnyBusy) while ($bAnyBusy) {
{
$bAnyBusy = false; $bAnyBusy = false;
for($i = 0; $i < $iInstances; $i++) for ($i = 0; $i < $iInstances; $i++) {
{
if (pg_connection_busy($aDBInstances[$i]->connection)) $bAnyBusy = true; if (pg_connection_busy($aDBInstances[$i]->connection)) $bAnyBusy = true;
} }
usleep(10); usleep(10);
@@ -457,8 +407,7 @@ if ($aCMDResult['import-tiger-data'])
pgsqlRunScript($sTemplate, false); pgsqlRunScript($sTemplate, false);
} }
if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
{
$bDidSomething = true; $bDidSomething = true;
$oDB =& getDB(); $oDB =& getDB();
if (!pg_query($oDB->connection, 'DELETE from placex where osm_type=\'P\'')) fail(pg_last_error($oDB->connection)); if (!pg_query($oDB->connection, 'DELETE from placex where osm_type=\'P\'')) fail(pg_last_error($oDB->connection));
@@ -469,8 +418,7 @@ if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all'])
$sSQL .= "from placex where postcode is not null group by calculated_country_code,postcode) as x"; $sSQL .= "from placex where postcode is not null group by calculated_country_code,postcode) as x";
if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection)); if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection));
if (CONST_Use_Extra_US_Postcodes) if (CONST_Use_Extra_US_Postcodes) {
{
$sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,calculated_country_code,geometry) "; $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,calculated_country_code,geometry) ";
$sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,'us',"; $sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,'us',";
$sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from us_postcode"; $sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from us_postcode";
@@ -478,27 +426,19 @@ if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all'])
} }
} }
if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop'])) // no use doing osmosis-init when dropping update tables if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop'])) { // no use doing osmosis-init when dropping update tables
{
$bDidSomething = true; $bDidSomething = true;
$oDB =& getDB(); $oDB =& getDB();
if (!file_exists(CONST_Osmosis_Binary)) if (!file_exists(CONST_Osmosis_Binary)) {
{
echo "Please download osmosis.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n"; echo "Please download osmosis.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n";
if (!$aCMDResult['all']) if (!$aCMDResult['all']) {
{
fail("osmosis not found in '".CONST_Osmosis_Binary."'"); fail("osmosis not found in '".CONST_Osmosis_Binary."'");
} }
} } else {
else if (file_exists(CONST_InstallPath.'/settings/configuration.txt')) {
{
if (file_exists(CONST_InstallPath.'/settings/configuration.txt'))
{
echo "settings/configuration.txt already exists\n"; echo "settings/configuration.txt already exists\n";
} } else {
else
{
passthru(CONST_Osmosis_Binary.' --read-replication-interval-init '.CONST_InstallPath.'/settings'); passthru(CONST_Osmosis_Binary.' --read-replication-interval-init '.CONST_InstallPath.'/settings');
// update osmosis configuration.txt with our settings // update osmosis configuration.txt with our settings
passthru("sed -i 's!baseUrl=.*!baseUrl=".CONST_Replication_Url."!' ".CONST_InstallPath.'/settings/configuration.txt'); passthru("sed -i 's!baseUrl=.*!baseUrl=".CONST_Replication_Url."!' ".CONST_InstallPath.'/settings/configuration.txt');
@@ -520,11 +460,9 @@ if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop']))
// download.geofabrik.de: <a href="000/">000/</a></td><td align="right">26-Feb-2013 11:53 </td> // download.geofabrik.de: <a href="000/">000/</a></td><td align="right">26-Feb-2013 11:53 </td>
// planet.openstreetmap.org: <a href="273/">273/</a> 2013-03-11 07:41 - // planet.openstreetmap.org: <a href="273/">273/</a> 2013-03-11 07:41 -
preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a>\s*([-0-9a-zA-Z]+ [0-9]{2}:[0-9]{2})#', $sRep, $aRepMatches, PREG_SET_ORDER); preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a>\s*([-0-9a-zA-Z]+ [0-9]{2}:[0-9]{2})#', $sRep, $aRepMatches, PREG_SET_ORDER);
if ($aRepMatches) if ($aRepMatches) {
{
$aPrevRepMatch = false; $aPrevRepMatch = false;
foreach($aRepMatches as $aRepMatch) foreach ($aRepMatches as $aRepMatch) {
{
if (strtotime($aRepMatch[2]) < $iLastNodeTimestamp) break; if (strtotime($aRepMatch[2]) < $iLastNodeTimestamp) break;
$aPrevRepMatch = $aRepMatch; $aPrevRepMatch = $aRepMatch;
} }
@@ -534,8 +472,7 @@ if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop']))
$sRep = file_get_contents($sRepURL."?C=M;O=D;F=1"); $sRep = file_get_contents($sRepURL."?C=M;O=D;F=1");
preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a>\s*([-0-9a-zA-Z]+ [0-9]{2}:[0-9]{2})#', $sRep, $aRepMatches, PREG_SET_ORDER); preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a>\s*([-0-9a-zA-Z]+ [0-9]{2}:[0-9]{2})#', $sRep, $aRepMatches, PREG_SET_ORDER);
$aPrevRepMatch = false; $aPrevRepMatch = false;
foreach($aRepMatches as $aRepMatch) foreach ($aRepMatches as $aRepMatch) {
{
if (strtotime($aRepMatch[2]) < $iLastNodeTimestamp) break; if (strtotime($aRepMatch[2]) < $iLastNodeTimestamp) break;
$aPrevRepMatch = $aRepMatch; $aPrevRepMatch = $aRepMatch;
} }
@@ -545,8 +482,7 @@ if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop']))
$sRep = file_get_contents($sRepURL."?C=M;O=D;F=1"); $sRep = file_get_contents($sRepURL."?C=M;O=D;F=1");
preg_match_all('#<a href="[0-9]{3}.state.txt">([0-9]{3}).state.txt</a>\s*([-0-9a-zA-Z]+ [0-9]{2}:[0-9]{2})#', $sRep, $aRepMatches, PREG_SET_ORDER); preg_match_all('#<a href="[0-9]{3}.state.txt">([0-9]{3}).state.txt</a>\s*([-0-9a-zA-Z]+ [0-9]{2}:[0-9]{2})#', $sRep, $aRepMatches, PREG_SET_ORDER);
$aPrevRepMatch = false; $aPrevRepMatch = false;
foreach($aRepMatches as $aRepMatch) foreach ($aRepMatches as $aRepMatch) {
{
if (strtotime($aRepMatch[2]) < $iLastNodeTimestamp) break; if (strtotime($aRepMatch[2]) < $iLastNodeTimestamp) break;
$aPrevRepMatch = $aRepMatch; $aPrevRepMatch = $aRepMatch;
} }
@@ -561,19 +497,15 @@ if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop']))
pg_query($oDB->connection, 'TRUNCATE import_status'); pg_query($oDB->connection, 'TRUNCATE import_status');
$sSQL = "INSERT INTO import_status VALUES('".$aRepMatch[2]."')"; $sSQL = "INSERT INTO import_status VALUES('".$aRepMatch[2]."')";
pg_query($oDB->connection, $sSQL); pg_query($oDB->connection, $sSQL);
} } else {
else if (!$aCMDResult['all']) {
{
if (!$aCMDResult['all'])
{
fail("Cannot read state file directory."); fail("Cannot read state file directory.");
} }
} }
} }
} }
if ($aCMDResult['index'] || $aCMDResult['all']) if ($aCMDResult['index'] || $aCMDResult['all']) {
{
$bDidSomething = true; $bDidSomething = true;
$sOutputFile = ''; $sOutputFile = '';
$sBaseCmd = CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$iInstances.$sOutputFile; $sBaseCmd = CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$iInstances.$sOutputFile;
@@ -584,8 +516,7 @@ if ($aCMDResult['index'] || $aCMDResult['all'])
passthruCheckReturn($sBaseCmd.' -r 26'); passthruCheckReturn($sBaseCmd.' -r 26');
} }
if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) {
{
echo "Search indices\n"; echo "Search indices\n";
$bDidSomething = true; $bDidSomething = true;
@@ -600,8 +531,7 @@ if ($aCMDResult['create-search-indices'] || $aCMDResult['all'])
pgsqlRunScript($sTemplate); pgsqlRunScript($sTemplate);
} }
if ($aCMDResult['drop']) if ($aCMDResult['drop']) {
{
// The implementation is potentially a bit dangerous because it uses // The implementation is potentially a bit dangerous because it uses
// a positive selection of tables to keep, and deletes everything else. // a positive selection of tables to keep, and deletes everything else.
// Including any tables that the unsuspecting user might have manually // Including any tables that the unsuspecting user might have manually
@@ -631,13 +561,10 @@ if ($aCMDResult['drop'])
$aDropTables = array(); $aDropTables = array();
$aHaveTables = chksql($oDB->getCol("SELECT tablename FROM pg_tables WHERE schemaname='public'")); $aHaveTables = chksql($oDB->getCol("SELECT tablename FROM pg_tables WHERE schemaname='public'"));
foreach($aHaveTables as $sTable) foreach ($aHaveTables as $sTable) {
{
$bFound = false; $bFound = false;
foreach ($aKeepTables as $sKeep) foreach ($aKeepTables as $sKeep) {
{ if (fnmatch($sKeep, $sTable)) {
if (fnmatch($sKeep, $sTable))
{
$bFound = true; $bFound = true;
break; break;
} }
@@ -645,27 +572,22 @@ if ($aCMDResult['drop'])
if (!$bFound) array_push($aDropTables, $sTable); if (!$bFound) array_push($aDropTables, $sTable);
} }
foreach ($aDropTables as $sDrop) foreach ($aDropTables as $sDrop) {
{
if ($aCMDResult['verbose']) echo "dropping table $sDrop\n"; if ($aCMDResult['verbose']) echo "dropping table $sDrop\n";
@pg_query($oDB->connection, "DROP TABLE $sDrop CASCADE"); @pg_query($oDB->connection, "DROP TABLE $sDrop CASCADE");
// ignore warnings/errors as they might be caused by a table having // ignore warnings/errors as they might be caused by a table having
// been deleted already by CASCADE // been deleted already by CASCADE
} }
if (!is_null(CONST_Osm2pgsql_Flatnode_File)) if (!is_null(CONST_Osm2pgsql_Flatnode_File)) {
{
if ($aCMDResult['verbose']) echo "deleting ".CONST_Osm2pgsql_Flatnode_File."\n"; if ($aCMDResult['verbose']) echo "deleting ".CONST_Osm2pgsql_Flatnode_File."\n";
unlink(CONST_Osm2pgsql_Flatnode_File); unlink(CONST_Osm2pgsql_Flatnode_File);
} }
} }
if (!$bDidSomething) if (!$bDidSomething) {
{
showUsage($aCMDOptions, true); showUsage($aCMDOptions, true);
} } else {
else
{
echo "Setup finished.\n"; echo "Setup finished.\n";
} }
@@ -679,8 +601,7 @@ function pgsqlRunScriptFile($sFilename)
$sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database']; $sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'];
$ahGzipPipes = null; $ahGzipPipes = null;
if (preg_match('/\\.gz$/', $sFilename)) if (preg_match('/\\.gz$/', $sFilename)) {
{
$aDescriptors = array( $aDescriptors = array(
0 => array('pipe', 'r'), 0 => array('pipe', 'r'),
1 => array('pipe', 'w'), 1 => array('pipe', 'w'),
@@ -690,9 +611,7 @@ function pgsqlRunScriptFile($sFilename)
if (!is_resource($hGzipProcess)) fail('unable to start zcat'); if (!is_resource($hGzipProcess)) fail('unable to start zcat');
$aReadPipe = $ahGzipPipes[1]; $aReadPipe = $ahGzipPipes[1];
fclose($ahGzipPipes[0]); fclose($ahGzipPipes[0]);
} } else {
else
{
$sCMD .= ' -f '.$sFilename; $sCMD .= ' -f '.$sFilename;
$aReadPipe = array('pipe', 'r'); $aReadPipe = array('pipe', 'r');
} }
@@ -708,19 +627,16 @@ function pgsqlRunScriptFile($sFilename)
// TODO: error checking // TODO: error checking
while(!feof($ahPipes[1])) while (!feof($ahPipes[1])) {
{
echo fread($ahPipes[1], 4096); echo fread($ahPipes[1], 4096);
} }
fclose($ahPipes[1]); fclose($ahPipes[1]);
$iReturn = proc_close($hProcess); $iReturn = proc_close($hProcess);
if ($iReturn > 0) if ($iReturn > 0) {
{
fail("pgsql returned with error code ($iReturn)"); fail("pgsql returned with error code ($iReturn)");
} }
if ($ahGzipPipes) if ($ahGzipPipes) {
{
fclose($ahGzipPipes[1]); fclose($ahGzipPipes[1]);
proc_close($hGzipProcess); proc_close($hGzipProcess);
} }
@@ -745,16 +661,14 @@ function pgsqlRunScript($sScript, $bfatal = true)
$hProcess = @proc_open($sCMD, $aDescriptors, $ahPipes); $hProcess = @proc_open($sCMD, $aDescriptors, $ahPipes);
if (!is_resource($hProcess)) fail('unable to start pgsql'); if (!is_resource($hProcess)) fail('unable to start pgsql');
while(strlen($sScript)) while (strlen($sScript)) {
{
$written = fwrite($ahPipes[0], $sScript); $written = fwrite($ahPipes[0], $sScript);
if ($written <= 0) break; if ($written <= 0) break;
$sScript = substr($sScript, $written); $sScript = substr($sScript, $written);
} }
fclose($ahPipes[0]); fclose($ahPipes[0]);
$iReturn = proc_close($hProcess); $iReturn = proc_close($hProcess);
if ($bfatal && $iReturn > 0) if ($bfatal && $iReturn > 0) {
{
fail("pgsql returned with error code ($iReturn)"); fail("pgsql returned with error code ($iReturn)");
} }
} }
@@ -769,11 +683,9 @@ function pgsqlRunPartitionScript($sTemplate)
if (!$aCMDResult['no-partitions']) $aPartitions[] = 0; if (!$aCMDResult['no-partitions']) $aPartitions[] = 0;
preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER); preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER);
foreach($aMatches as $aMatch) foreach ($aMatches as $aMatch) {
{
$sResult = ''; $sResult = '';
foreach($aPartitions as $sPartitionName) foreach ($aPartitions as $sPartitionName) {
{
$sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]); $sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]);
} }
$sTemplate = str_replace($aMatch[0], $sResult, $sTemplate); $sTemplate = str_replace($aMatch[0], $sResult, $sTemplate);
@@ -801,8 +713,7 @@ function pgsqlRunRestoreData($sDumpFile)
fclose($ahPipes[0]); fclose($ahPipes[0]);
// TODO: error checking // TODO: error checking
while(!feof($ahPipes[1])) while (!feof($ahPipes[1])) {
{
echo fread($ahPipes[1], 4096); echo fread($ahPipes[1], 4096);
} }
fclose($ahPipes[1]); fclose($ahPipes[1]);
@@ -829,8 +740,7 @@ function pgsqlRunDropAndRestore($sDumpFile)
fclose($ahPipes[0]); fclose($ahPipes[0]);
// TODO: error checking // TODO: error checking
while(!feof($ahPipes[1])) while (!feof($ahPipes[1])) {
{
echo fread($ahPipes[1], 4096); echo fread($ahPipes[1], 4096);
} }
fclose($ahPipes[1]); fclose($ahPipes[1]);
@@ -847,11 +757,12 @@ function passthruCheckReturn($cmd)
function replace_tablespace($sTemplate, $sTablespace, $sSql) function replace_tablespace($sTemplate, $sTablespace, $sSql)
{ {
if ($sTablespace) if ($sTablespace) {
$sSql = str_replace($sTemplate, 'TABLESPACE "'.$sTablespace.'"', $sSql = str_replace($sTemplate, 'TABLESPACE "'.$sTablespace.'"',
$sSql); $sSql);
else } else {
$sSql = str_replace($sTemplate, '', $sSql); $sSql = str_replace($sTemplate, '', $sSql);
}
return $sSql; return $sSql;
} }
@@ -860,24 +771,19 @@ function create_sql_functions($aCMDResult)
{ {
$sTemplate = file_get_contents(CONST_BasePath.'/sql/functions.sql'); $sTemplate = file_get_contents(CONST_BasePath.'/sql/functions.sql');
$sTemplate = str_replace('{modulepath}', CONST_InstallPath.'/module', $sTemplate); $sTemplate = str_replace('{modulepath}', CONST_InstallPath.'/module', $sTemplate);
if ($aCMDResult['enable-diff-updates']) if ($aCMDResult['enable-diff-updates']) {
{
$sTemplate = str_replace('RETURN NEW; -- %DIFFUPDATES%', '--', $sTemplate); $sTemplate = str_replace('RETURN NEW; -- %DIFFUPDATES%', '--', $sTemplate);
} }
if ($aCMDResult['enable-debug-statements']) if ($aCMDResult['enable-debug-statements']) {
{
$sTemplate = str_replace('--DEBUG:', '', $sTemplate); $sTemplate = str_replace('--DEBUG:', '', $sTemplate);
} }
if (CONST_Limit_Reindexing) if (CONST_Limit_Reindexing) {
{
$sTemplate = str_replace('--LIMIT INDEXING:', '', $sTemplate); $sTemplate = str_replace('--LIMIT INDEXING:', '', $sTemplate);
} }
if (!CONST_Use_US_Tiger_Data) if (!CONST_Use_US_Tiger_Data) {
{
$sTemplate = str_replace('-- %NOTIGERDATA% ', '', $sTemplate); $sTemplate = str_replace('-- %NOTIGERDATA% ', '', $sTemplate);
} }
if (!CONST_Use_Aux_Location_data) if (!CONST_Use_Aux_Location_data) {
{
$sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate); $sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate);
} }
pgsqlRunScript($sTemplate); pgsqlRunScript($sTemplate);

View File

@@ -6,17 +6,17 @@ require_once(CONST_BasePath.'/lib/init-cmd.php');
ini_set('memory_limit', '800M'); ini_set('memory_limit', '800M');
ini_set('display_errors', 'stderr'); ini_set('display_errors', 'stderr');
$aCMDOptions = array( $aCMDOptions = array(
"Import and export special phrases", "Import and export special phrases",
array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
array('countries', '', 0, 1, 0, 0, 'bool', 'Create import script for country codes and names'), array('countries', '', 0, 1, 0, 0, 'bool', 'Create import script for country codes and names'),
array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '), array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '),
); );
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
include(CONST_InstallPath.'/settings/phrase_settings.php'); include(CONST_InstallPath.'/settings/phrase_settings.php');
if ($aCMDResult['countries']) { if ($aCMDResult['countries']) {
@@ -25,24 +25,19 @@ if ($aCMDResult['countries']) {
echo "select count(*) from (select getorcreate_country(make_standard_name(country_code), country_code) from country_name where country_code is not null) as x;\n"; echo "select count(*) from (select getorcreate_country(make_standard_name(country_code), country_code) from country_name where country_code is not null) as x;\n";
echo "select count(*) from (select getorcreate_country(make_standard_name(get_name_by_language(country_name.name,ARRAY['name'])), country_code) from country_name where get_name_by_language(country_name.name, ARRAY['name']) is not null) as x;\n"; echo "select count(*) from (select getorcreate_country(make_standard_name(get_name_by_language(country_name.name,ARRAY['name'])), country_code) from country_name where get_name_by_language(country_name.name, ARRAY['name']) is not null) as x;\n";
foreach($aLanguageIn as $sLanguage) foreach ($aLanguageIn as $sLanguage) {
{
echo "select count(*) from (select getorcreate_country(make_standard_name(get_name_by_language(country_name.name,ARRAY['name:".$sLanguage."'])), country_code) from country_name where get_name_by_language(country_name.name, ARRAY['name:".$sLanguage."']) is not null) as x;\n"; echo "select count(*) from (select getorcreate_country(make_standard_name(get_name_by_language(country_name.name,ARRAY['name:".$sLanguage."'])), country_code) from country_name where get_name_by_language(country_name.name, ARRAY['name:".$sLanguage."']) is not null) as x;\n";
} }
} }
if ($aCMDResult['wiki-import']) if ($aCMDResult['wiki-import']) {
{
$aPairs = array(); $aPairs = array();
foreach($aLanguageIn as $sLanguage) foreach ($aLanguageIn as $sLanguage) {
{
$sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage); $sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
$sWikiPageXML = file_get_contents($sURL); $sWikiPageXML = file_get_contents($sURL);
if (preg_match_all('#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#', $sWikiPageXML, $aMatches, PREG_SET_ORDER)) if (preg_match_all('#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#', $sWikiPageXML, $aMatches, PREG_SET_ORDER)) {
{ foreach ($aMatches as $aMatch) {
foreach($aMatches as $aMatch)
{
$sLabel = trim($aMatch[1]); $sLabel = trim($aMatch[1]);
$sClass = trim($aMatch[2]); $sClass = trim($aMatch[2]);
$sType = trim($aMatch[3]); $sType = trim($aMatch[3]);
@@ -67,17 +62,16 @@ if ($aCMDResult['wiki-import'])
} }
$aPairs[$sClass.'|'.$sType] = array($sClass, $sType); $aPairs[$sClass.'|'.$sType] = array($sClass, $sType);
switch(trim($aMatch[4])) switch (trim($aMatch[4])) {
{ case 'near':
case 'near': echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'near');\n";
echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'near');\n"; break;
break; case 'in':
case 'in': echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'in');\n";
echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'in');\n"; break;
break; default:
default: echo "select getorcreate_amenity(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType');\n";
echo "select getorcreate_amenity(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType');\n"; break;
break;
} }
} }
} }
@@ -85,8 +79,7 @@ if ($aCMDResult['wiki-import'])
echo "create index idx_placex_classtype on placex (class, type);"; echo "create index idx_placex_classtype on placex (class, type);";
foreach($aPairs as $aPair) foreach ($aPairs as $aPair) {
{
echo "create table place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]); echo "create table place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]);
if (CONST_Tablespace_Aux_Data) if (CONST_Tablespace_Aux_Data)
echo " tablespace ".CONST_Tablespace_Aux_Data; echo " tablespace ".CONST_Tablespace_Aux_Data;
@@ -107,7 +100,6 @@ if ($aCMDResult['wiki-import'])
echo ";\n"; echo ";\n";
echo "GRANT SELECT ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]).' TO "'.CONST_Database_Web_User."\";\n"; echo "GRANT SELECT ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]).' TO "'.CONST_Database_Web_User."\";\n";
} }
echo "drop index idx_placex_classtype;"; echo "drop index idx_placex_classtype;";

View File

@@ -47,24 +47,20 @@ if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
// cache memory to be used by osm2pgsql, should not be more than the available memory // cache memory to be used by osm2pgsql, should not be more than the available memory
$iCacheMemory = (isset($aResult['osm2pgsql-cache'])?$aResult['osm2pgsql-cache']:2000); $iCacheMemory = (isset($aResult['osm2pgsql-cache'])?$aResult['osm2pgsql-cache']:2000);
if ($iCacheMemory + 500 > getTotalMemoryMB()) if ($iCacheMemory + 500 > getTotalMemoryMB()) {
{
$iCacheMemory = getCacheMemoryMB(); $iCacheMemory = getCacheMemoryMB();
echo "WARNING: resetting cache memory to $iCacheMemory\n"; echo "WARNING: resetting cache memory to $iCacheMemory\n";
} }
$sOsm2pgsqlCmd = CONST_Osm2pgsql_Binary.' -klas --number-processes 1 -C '.$iCacheMemory.' -O gazetteer -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port']; $sOsm2pgsqlCmd = CONST_Osm2pgsql_Binary.' -klas --number-processes 1 -C '.$iCacheMemory.' -O gazetteer -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'];
if (!is_null(CONST_Osm2pgsql_Flatnode_File)) if (!is_null(CONST_Osm2pgsql_Flatnode_File)) {
{
$sOsm2pgsqlCmd .= ' --flat-nodes '.CONST_Osm2pgsql_Flatnode_File; $sOsm2pgsqlCmd .= ' --flat-nodes '.CONST_Osm2pgsql_Flatnode_File;
} }
if (isset($aResult['import-diff'])) if (isset($aResult['import-diff'])) {
{
// import diff directly (e.g. from osmosis --rri) // import diff directly (e.g. from osmosis --rri)
$sNextFile = $aResult['import-diff']; $sNextFile = $aResult['import-diff'];
if (!file_exists($sNextFile)) if (!file_exists($sNextFile)) {
{
fail("Cannot open $sNextFile\n"); fail("Cannot open $sNextFile\n");
} }
@@ -73,8 +69,7 @@ if (isset($aResult['import-diff']))
echo $sCMD."\n"; echo $sCMD."\n";
exec($sCMD, $sJunk, $iErrorLevel); exec($sCMD, $sJunk, $iErrorLevel);
if ($iErrorLevel) if ($iErrorLevel) {
{
fail("Error from osm2pgsql, $iErrorLevel\n"); fail("Error from osm2pgsql, $iErrorLevel\n");
} }
@@ -83,55 +78,43 @@ if (isset($aResult['import-diff']))
$sTemporaryFile = CONST_BasePath.'/data/osmosischange.osc'; $sTemporaryFile = CONST_BasePath.'/data/osmosischange.osc';
$bHaveDiff = false; $bHaveDiff = false;
if (isset($aResult['import-file']) && $aResult['import-file']) if (isset($aResult['import-file']) && $aResult['import-file']) {
{
$bHaveDiff = true; $bHaveDiff = true;
$sCMD = CONST_Osmosis_Binary.' --read-xml \''.$aResult['import-file'].'\' --read-empty --derive-change --write-xml-change '.$sTemporaryFile; $sCMD = CONST_Osmosis_Binary.' --read-xml \''.$aResult['import-file'].'\' --read-empty --derive-change --write-xml-change '.$sTemporaryFile;
echo $sCMD."\n"; echo $sCMD."\n";
exec($sCMD, $sJunk, $iErrorLevel); exec($sCMD, $sJunk, $iErrorLevel);
if ($iErrorLevel) if ($iErrorLevel) {
{
fail("Error converting osm to osc, osmosis returned: $iErrorLevel\n"); fail("Error converting osm to osc, osmosis returned: $iErrorLevel\n");
} }
} }
$bUseOSMApi = isset($aResult['import-from-main-api']) && $aResult['import-from-main-api']; $bUseOSMApi = isset($aResult['import-from-main-api']) && $aResult['import-from-main-api'];
$sContentURL = ''; $sContentURL = '';
if (isset($aResult['import-node']) && $aResult['import-node']) if (isset($aResult['import-node']) && $aResult['import-node']) {
{ if ($bUseOSMApi) {
if ($bUseOSMApi)
{
$sContentURL = 'http://www.openstreetmap.org/api/0.6/node/'.$aResult['import-node']; $sContentURL = 'http://www.openstreetmap.org/api/0.6/node/'.$aResult['import-node'];
} } else {
else
{
$sContentURL = 'http://overpass-api.de/api/interpreter?data=node('.$aResult['import-node'].');out%20meta;'; $sContentURL = 'http://overpass-api.de/api/interpreter?data=node('.$aResult['import-node'].');out%20meta;';
} }
} }
if (isset($aResult['import-way']) && $aResult['import-way'])
{ if (isset($aResult['import-way']) && $aResult['import-way']) {
if ($bUseOSMApi) if ($bUseOSMApi) {
{
$sContentURL = 'http://www.openstreetmap.org/api/0.6/way/'.$aResult['import-way'].'/full'; $sContentURL = 'http://www.openstreetmap.org/api/0.6/way/'.$aResult['import-way'].'/full';
} } else {
else
{
$sContentURL = 'http://overpass-api.de/api/interpreter?data=(way('.$aResult['import-way'].');node(w););out%20meta;'; $sContentURL = 'http://overpass-api.de/api/interpreter?data=(way('.$aResult['import-way'].');node(w););out%20meta;';
} }
} }
if (isset($aResult['import-relation']) && $aResult['import-relation'])
{ if (isset($aResult['import-relation']) && $aResult['import-relation']) {
if ($bUseOSMApi) if ($bUseOSMApi) {
{
$sContentURLsModifyXMLstr = 'http://www.openstreetmap.org/api/0.6/relation/'.$aResult['import-relation'].'/full'; $sContentURLsModifyXMLstr = 'http://www.openstreetmap.org/api/0.6/relation/'.$aResult['import-relation'].'/full';
} } else {
else
{
$sContentURL = 'http://overpass-api.de/api/interpreter?data=((rel('.$aResult['import-relation'].');way(r);node(w));node(r));out%20meta;'; $sContentURL = 'http://overpass-api.de/api/interpreter?data=((rel('.$aResult['import-relation'].');way(r);node(w));node(r));out%20meta;';
} }
} }
if ($sContentURL)
{ if ($sContentURL) {
$sModifyXMLstr = file_get_contents($sContentURL); $sModifyXMLstr = file_get_contents($sContentURL);
$bHaveDiff = true; $bHaveDiff = true;
@@ -143,8 +126,7 @@ if ($sContentURL)
$sCMD = CONST_Osmosis_Binary.' --read-xml - --read-empty --derive-change --write-xml-change '.$sTemporaryFile; $sCMD = CONST_Osmosis_Binary.' --read-xml - --read-empty --derive-change --write-xml-change '.$sTemporaryFile;
echo $sCMD."\n"; echo $sCMD."\n";
$hProc = proc_open($sCMD, $aSpec, $aPipes); $hProc = proc_open($sCMD, $aSpec, $aPipes);
if (!is_resource($hProc)) if (!is_resource($hProc)) {
{
fail("Error converting osm to osc, osmosis failed\n"); fail("Error converting osm to osc, osmosis failed\n");
} }
fwrite($aPipes[0], $sModifyXMLstr); fwrite($aPipes[0], $sModifyXMLstr);
@@ -155,31 +137,26 @@ if ($sContentURL)
$sErrors = stream_get_contents($aPipes[2]); $sErrors = stream_get_contents($aPipes[2]);
if ($aResult['verbose']) echo $sErrors; if ($aResult['verbose']) echo $sErrors;
fclose($aPipes[2]); fclose($aPipes[2]);
if ($iError = proc_close($hProc)) if ($iError = proc_close($hProc)) {
{
echo $sOut; echo $sOut;
echo $sErrors; echo $sErrors;
fail("Error converting osm to osc, osmosis returned: $iError\n"); fail("Error converting osm to osc, osmosis returned: $iError\n");
} }
} }
if ($bHaveDiff) if ($bHaveDiff) {
{
// import generated change file // import generated change file
$sCMD = $sOsm2pgsqlCmd.' '.$sTemporaryFile; $sCMD = $sOsm2pgsqlCmd.' '.$sTemporaryFile;
echo $sCMD."\n"; echo $sCMD."\n";
exec($sCMD, $sJunk, $iErrorLevel); exec($sCMD, $sJunk, $iErrorLevel);
if ($iErrorLevel) if ($iErrorLevel) {
{
fail("osm2pgsql exited with error level $iErrorLevel\n"); fail("osm2pgsql exited with error level $iErrorLevel\n");
} }
} }
if ($aResult['deduplicate']) if ($aResult['deduplicate']) {
{ //
if (getPostgresVersion() < 9.3) {
if (getPostgresVersion() < 9.3)
{
fail("ERROR: deduplicate is only currently supported in postgresql 9.3"); fail("ERROR: deduplicate is only currently supported in postgresql 9.3");
} }
@@ -190,8 +167,7 @@ if ($aResult['deduplicate'])
$sSQL = "select word_token,count(*) from word where substr(word_token, 1, 1) = ' ' and class is null and type is null and country_code is null group by word_token having count(*) > 1 order by word_token"; $sSQL = "select word_token,count(*) from word where substr(word_token, 1, 1) = ' ' and class is null and type is null and country_code is null group by word_token having count(*) > 1 order by word_token";
$aDuplicateTokens = chksql($oDB->getAll($sSQL)); $aDuplicateTokens = chksql($oDB->getAll($sSQL));
foreach($aDuplicateTokens as $aToken) foreach ($aDuplicateTokens as $aToken) {
{
if (trim($aToken['word_token']) == '' || trim($aToken['word_token']) == '-') continue; if (trim($aToken['word_token']) == '' || trim($aToken['word_token']) == '-') continue;
echo "Deduping ".$aToken['word_token']."\n"; echo "Deduping ".$aToken['word_token']."\n";
$sSQL = "select word_id,(select count(*) from search_name where nameaddress_vector @> ARRAY[word_id]) as num from word where word_token = '".$aToken['word_token']."' and class is null and type is null and country_code is null order by num desc"; $sSQL = "select word_id,(select count(*) from search_name where nameaddress_vector @> ARRAY[word_id]) as num from word where word_token = '".$aToken['word_token']."' and class is null and type is null and country_code is null order by num desc";
@@ -200,8 +176,7 @@ if ($aResult['deduplicate'])
$aKeep = array_shift($aTokenSet); $aKeep = array_shift($aTokenSet);
$iKeepID = $aKeep['word_id']; $iKeepID = $aKeep['word_id'];
foreach($aTokenSet as $aRemove) foreach ($aTokenSet as $aRemove) {
{
$sSQL = "update search_name set"; $sSQL = "update search_name set";
$sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID."),"; $sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID."),";
$sSQL .= " nameaddress_vector = array_replace(nameaddress_vector,".$aRemove['word_id'].",".$iKeepID.")"; $sSQL .= " nameaddress_vector = array_replace(nameaddress_vector,".$aRemove['word_id'].",".$iKeepID.")";
@@ -218,8 +193,7 @@ if ($aResult['deduplicate'])
$sSQL .= " where keywords @> ARRAY[".$aRemove['word_id']."]"; $sSQL .= " where keywords @> ARRAY[".$aRemove['word_id']."]";
chksql($oDB->query($sSQL)); chksql($oDB->query($sSQL));
foreach ($aPartitions as $sPartition) foreach ($aPartitions as $sPartition) {
{
$sSQL = "update search_name_".$sPartition." set"; $sSQL = "update search_name_".$sPartition." set";
$sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID.")"; $sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID.")";
$sSQL .= " where name_vector @> ARRAY[".$aRemove['word_id']."]"; $sSQL .= " where name_vector @> ARRAY[".$aRemove['word_id']."]";
@@ -237,14 +211,12 @@ if ($aResult['deduplicate'])
} }
} }
if ($aResult['index']) if ($aResult['index']) {
{
passthru(CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$aResult['index-instances'].' -r '.$aResult['index-rank']); passthru(CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$aResult['index-instances'].' -r '.$aResult['index-rank']);
} }
if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) {
{ //
if (strpos(CONST_Replication_Url, 'download.geofabrik.de') !== false && CONST_Replication_Update_Interval < 86400) { if (strpos(CONST_Replication_Url, 'download.geofabrik.de') !== false && CONST_Replication_Update_Interval < 86400) {
fail("Error: Update interval too low for download.geofabrik.de. Please check install documentation (http://wiki.openstreetmap.org/wiki/Nominatim/Installation#Updates)\n"); fail("Error: Update interval too low for download.geofabrik.de. Please check install documentation (http://wiki.openstreetmap.org/wiki/Nominatim/Installation#Updates)\n");
} }
@@ -256,28 +228,20 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
$sCMDImport = $sOsm2pgsqlCmd.' '.$sImportFile; $sCMDImport = $sOsm2pgsqlCmd.' '.$sImportFile;
$sCMDIndex = CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$aResult['index-instances']; $sCMDIndex = CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$aResult['index-instances'];
while(true) while (true) {
{
$fStartTime = time(); $fStartTime = time();
$iFileSize = 1001; $iFileSize = 1001;
if (!file_exists($sImportFile)) if (!file_exists($sImportFile)) {
{
// First check if there are new updates published (except for minutelies - there's always new diffs to process) // First check if there are new updates published (except for minutelies - there's always new diffs to process)
if ( CONST_Replication_Update_Interval > 60 ) if (CONST_Replication_Update_Interval > 60) {
{
unset($aReplicationLag); unset($aReplicationLag);
exec($sCMDCheckReplicationLag, $aReplicationLag, $iErrorLevel); exec($sCMDCheckReplicationLag, $aReplicationLag, $iErrorLevel);
while ($iErrorLevel > 0 || $aReplicationLag[0] < 1) while ($iErrorLevel > 0 || $aReplicationLag[0] < 1) {
{ if ($iErrorLevel) {
if ($iErrorLevel)
{
echo "Error: $iErrorLevel. "; echo "Error: $iErrorLevel. ";
echo "Re-trying: ".$sCMDCheckReplicationLag." in ".CONST_Replication_Recheck_Interval." secs\n"; echo "Re-trying: ".$sCMDCheckReplicationLag." in ".CONST_Replication_Recheck_Interval." secs\n";
} } else {
else
{
echo "."; echo ".";
} }
sleep(CONST_Replication_Recheck_Interval); sleep(CONST_Replication_Recheck_Interval);
@@ -291,8 +255,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
$fCMDStartTime = time(); $fCMDStartTime = time();
echo $sCMDDownload."\n"; echo $sCMDDownload."\n";
exec($sCMDDownload, $sJunk, $iErrorLevel); exec($sCMDDownload, $sJunk, $iErrorLevel);
while ($iErrorLevel > 0) while ($iErrorLevel > 0) {
{
echo "Error: $iErrorLevel\n"; echo "Error: $iErrorLevel\n";
sleep(60); sleep(60);
echo 'Re-trying: '.$sCMDDownload."\n"; echo 'Re-trying: '.$sCMDDownload."\n";
@@ -313,8 +276,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
$fCMDStartTime = time(); $fCMDStartTime = time();
echo $sCMDImport."\n"; echo $sCMDImport."\n";
exec($sCMDImport, $sJunk, $iErrorLevel); exec($sCMDImport, $sJunk, $iErrorLevel);
if ($iErrorLevel) if ($iErrorLevel) {
{
echo "Error: $iErrorLevel\n"; echo "Error: $iErrorLevel\n";
exit($iErrorLevel); exit($iErrorLevel);
} }
@@ -332,12 +294,10 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
$sThisIndexCmd = $sCMDIndex; $sThisIndexCmd = $sCMDIndex;
$fCMDStartTime = time(); $fCMDStartTime = time();
if (!$aResult['no-index']) if (!$aResult['no-index']) {
{
echo "$sThisIndexCmd\n"; echo "$sThisIndexCmd\n";
exec($sThisIndexCmd, $sJunk, $iErrorLevel); exec($sThisIndexCmd, $sJunk, $iErrorLevel);
if ($iErrorLevel) if ($iErrorLevel) {
{
echo "Error: $iErrorLevel\n"; echo "Error: $iErrorLevel\n";
exit($iErrorLevel); exit($iErrorLevel);
} }
@@ -355,12 +315,9 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
echo date('Y-m-d H:i:s')." Completed all for $sBatchEnd in ".round($fDuration/60,2)." minutes\n"; echo date('Y-m-d H:i:s')." Completed all for $sBatchEnd in ".round($fDuration/60,2)." minutes\n";
if (!$aResult['import-osmosis-all']) exit(0); if (!$aResult['import-osmosis-all']) exit(0);
if ( CONST_Replication_Update_Interval > 60 ) if (CONST_Replication_Update_Interval > 60) {
{
$iSleep = max(0,(strtotime($sBatchEnd)+CONST_Replication_Update_Interval-time())); $iSleep = max(0,(strtotime($sBatchEnd)+CONST_Replication_Update_Interval-time()));
} } else {
else
{
$iSleep = max(0,CONST_Replication_Update_Interval-$fDuration); $iSleep = max(0,CONST_Replication_Update_Interval-$fDuration);
} }
echo date('Y-m-d H:i:s')." Sleeping $iSleep seconds\n"; echo date('Y-m-d H:i:s')." Sleeping $iSleep seconds\n";

View File

@@ -25,7 +25,6 @@ $oDB =& getDB();
$bVerbose = $aResult['verbose']; $bVerbose = $aResult['verbose'];
if (!$aResult['search-only']) { if (!$aResult['search-only']) {
$oReverseGeocode = new ReverseGeocode($oDB); $oReverseGeocode = new ReverseGeocode($oDB);
$oReverseGeocode->setZoom(20); $oReverseGeocode->setZoom(20);
$oPlaceLookup = new PlaceLookup($oDB); $oPlaceLookup = new PlaceLookup($oDB);
@@ -34,30 +33,29 @@ if (!$aResult['search-only']) {
echo "Warm reverse: "; echo "Warm reverse: ";
if ($bVerbose) echo "\n"; if ($bVerbose) echo "\n";
for($i = 0; $i < 1000; $i++) { for ($i = 0; $i < 1000; $i++) {
$fLat = rand(-9000, 9000) / 100; $fLat = rand(-9000, 9000) / 100;
$fLon = rand(-18000, 18000) / 100; $fLon = rand(-18000, 18000) / 100;
if ($bVerbose) echo "$fLat, $fLon = "; if ($bVerbose) echo "$fLat, $fLon = ";
$aLookup = $oReverseGeocode->lookup($fLat, $fLon); $aLookup = $oReverseGeocode->lookup($fLat, $fLon);
if ($aLookup && $aLookup['place_id']) if ($aLookup && $aLookup['place_id']) {
{
$aDetails = $oPlaceLookup->lookup((int)$aLookup['place_id'], $aDetails = $oPlaceLookup->lookup((int)$aLookup['place_id'],
$aLookup['type'], $aLookup['fraction']); $aLookup['type'], $aLookup['fraction']);
if ($bVerbose) echo $aDetails['langaddress']."\n"; if ($bVerbose) echo $aDetails['langaddress']."\n";
} else {
echo ".";
} }
else echo ".";
} }
echo "\n"; echo "\n";
} }
if (!$aResult['reverse-only']) { if (!$aResult['reverse-only']) {
$oGeocode =& new Geocode($oDB); $oGeocode =& new Geocode($oDB);
echo "Warm search: "; echo "Warm search: ";
if ($bVerbose) echo "\n"; if ($bVerbose) echo "\n";
$sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000'; $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000';
foreach($oDB->getCol($sSQL) as $sWord) { foreach ($oDB->getCol($sSQL) as $sWord) {
if ($bVerbose) echo "$sWord = "; if ($bVerbose) echo "$sWord = ";
$oGeocode->setLanguagePreference(array('en')); $oGeocode->setLanguagePreference(array('en'));
$oGeocode->setQuery($sWord); $oGeocode->setQuery($sWord);

View File

@@ -13,8 +13,7 @@
$aPolygons = chksql($oDB->getAll($sSQL), $aPolygons = chksql($oDB->getAll($sSQL),
"Could not get list of deleted OSM elements."); "Could not get list of deleted OSM elements.");
if (CONST_DEBUG) if (CONST_DEBUG) {
{
var_dump($aPolygons); var_dump($aPolygons);
exit; exit;
} }
@@ -71,18 +70,14 @@ table td {
if (!$aPolygons) exit; if (!$aPolygons) exit;
echo "<tr>"; echo "<tr>";
//var_dump($aPolygons[0]); //var_dump($aPolygons[0]);
foreach($aPolygons[0] as $sCol => $sVal) foreach ($aPolygons[0] as $sCol => $sVal) {
{
echo "<th>".$sCol."</th>"; echo "<th>".$sCol."</th>";
} }
echo "</tr>"; echo "</tr>";
foreach($aPolygons as $aRow) foreach ($aPolygons as $aRow) {
{
echo "<tr>"; echo "<tr>";
foreach($aRow as $sCol => $sVal) foreach ($aRow as $sCol => $sVal) {
{ switch ($sCol) {
switch($sCol)
{
case 'osm_id': case 'osm_id':
echo '<td>'.osmLink($aRow).'</td>'; echo '<td>'.osmLink($aRow).'</td>';
break; break;

View File

@@ -19,23 +19,18 @@ $iOsmId = $oParams->getInt('osmid', -1);
$oDB =& getDB(); $oDB =& getDB();
if ($sOsmType && $iOsmId > 0) if ($sOsmType && $iOsmId > 0) {
{
$sPlaceId = chksql($oDB->getOne("select place_id from placex where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by type = 'postcode' asc")); $sPlaceId = chksql($oDB->getOne("select place_id from placex where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by type = 'postcode' asc"));
// Be nice about our error messages for broken geometry // Be nice about our error messages for broken geometry
if (!$sPlaceId) if (!$sPlaceId) {
{
$aPointDetails = chksql($oDB->getRow("select osm_type, osm_id, errormessage, class, type, get_name_by_language(name,$sLanguagePrefArraySQL) as localname, ST_AsText(prevgeometry) as prevgeom, ST_AsText(newgeometry) as newgeom from import_polygon_error where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by updated desc limit 1")); $aPointDetails = chksql($oDB->getRow("select osm_type, osm_id, errormessage, class, type, get_name_by_language(name,$sLanguagePrefArraySQL) as localname, ST_AsText(prevgeometry) as prevgeom, ST_AsText(newgeometry) as newgeom from import_polygon_error where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by updated desc limit 1"));
if (!PEAR::isError($aPointDetails) && $aPointDetails) { if (!PEAR::isError($aPointDetails) && $aPointDetails) {
if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches)) if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches)) {
{
$aPointDetails['error_x'] = $aMatches[1]; $aPointDetails['error_x'] = $aMatches[1];
$aPointDetails['error_y'] = $aMatches[2]; $aPointDetails['error_y'] = $aMatches[2];
} } else {
else
{
$aPointDetails['error_x'] = 0; $aPointDetails['error_x'] = 0;
$aPointDetails['error_y'] = 0; $aPointDetails['error_y'] = 0;
} }
@@ -50,14 +45,12 @@ if (!$sPlaceId) userError("Please select a place id");
$iPlaceID = (int)$sPlaceId; $iPlaceID = (int)$sPlaceId;
if (CONST_Use_US_Tiger_Data) if (CONST_Use_US_Tiger_Data) {
{
$iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_tiger where place_id = '.$iPlaceID)); $iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_tiger where place_id = '.$iPlaceID));
if ($iParentPlaceID) $iPlaceID = $iParentPlaceID; if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
} }
if (CONST_Use_Aux_Location_data) if (CONST_Use_Aux_Location_data) {
{
$iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_aux where place_id = '.$iPlaceID)); $iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_aux where place_id = '.$iPlaceID));
if ($iParentPlaceID) $iPlaceID = $iParentPlaceID; if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
} }
@@ -83,16 +76,14 @@ $aPointDetails['icon'] = $aClassType[$aPointDetails['class'].':'.$aPointDetails[
// Get all alternative names (languages, etc) // Get all alternative names (languages, etc)
$sSQL = "select (each(name)).key,(each(name)).value from placex where place_id = $iPlaceID order by (each(name)).key"; $sSQL = "select (each(name)).key,(each(name)).value from placex where place_id = $iPlaceID order by (each(name)).key";
$aPointDetails['aNames'] = $oDB->getAssoc($sSQL); $aPointDetails['aNames'] = $oDB->getAssoc($sSQL);
if (PEAR::isError($aPointDetails['aNames'])) // possible timeout if (PEAR::isError($aPointDetails['aNames'])) { // possible timeout
{
$aPointDetails['aNames'] = []; $aPointDetails['aNames'] = [];
} }
// Extra tags // Extra tags
$sSQL = "select (each(extratags)).key,(each(extratags)).value from placex where place_id = $iPlaceID order by (each(extratags)).key"; $sSQL = "select (each(extratags)).key,(each(extratags)).value from placex where place_id = $iPlaceID order by (each(extratags)).key";
$aPointDetails['aExtraTags'] = $oDB->getAssoc($sSQL); $aPointDetails['aExtraTags'] = $oDB->getAssoc($sSQL);
if (PEAR::isError($aPointDetails['aExtraTags'])) // possible timeout if (PEAR::isError($aPointDetails['aExtraTags'])) { // possible timeout
{
$aPointDetails['aExtraTags'] = []; $aPointDetails['aExtraTags'] = [];
} }
@@ -106,8 +97,7 @@ $sSQL .= " from placex, (select centroid as placegeometry from placex where plac
$sSQL .= " where linked_place_id = $iPlaceID"; $sSQL .= " where linked_place_id = $iPlaceID";
$sSQL .= " order by rank_address asc,rank_search asc,get_name_by_language(name,$sLanguagePrefArraySQL),housenumber"; $sSQL .= " order by rank_address asc,rank_search asc,get_name_by_language(name,$sLanguagePrefArraySQL),housenumber";
$aLinkedLines = $oDB->getAll($sSQL); $aLinkedLines = $oDB->getAll($sSQL);
if (PEAR::isError($aLinkedLines)) // possible timeout if (PEAR::isError($aLinkedLines)) { // possible timeout
{
$aLinkedLines = []; $aLinkedLines = [];
} }
@@ -119,43 +109,36 @@ $sSQL .= " where parent_place_id = $iPlaceID order by rank_address asc,rank_sear
$sSQL .= " (select centroid as placegeometry from placex where place_id = $iPlaceID) as x"; $sSQL .= " (select centroid as placegeometry from placex where place_id = $iPlaceID) as x";
$sSQL .= " order by rank_address asc,rank_search asc,localname,housenumber"; $sSQL .= " order by rank_address asc,rank_search asc,localname,housenumber";
$aParentOfLines = $oDB->getAll($sSQL); $aParentOfLines = $oDB->getAll($sSQL);
if (PEAR::isError($aParentOfLines)) // possible timeout if (PEAR::isError($aParentOfLines)) { // possible timeout
{
$aParentOfLines = []; $aParentOfLines = [];
} }
$aPlaceSearchNameKeywords = false; $aPlaceSearchNameKeywords = false;
$aPlaceSearchAddressKeywords = false; $aPlaceSearchAddressKeywords = false;
if ($oParams->getBool('keywords')) if ($oParams->getBool('keywords')) {
{
$sSQL = "select * from search_name where place_id = $iPlaceID"; $sSQL = "select * from search_name where place_id = $iPlaceID";
$aPlaceSearchName = $oDB->getRow($sSQL); $aPlaceSearchName = $oDB->getRow($sSQL);
if (PEAR::isError($aPlaceSearchName)) // possible timeout if (PEAR::isError($aPlaceSearchName)) { // possible timeout
{
$aPlaceSearchName = []; $aPlaceSearchName = [];
} }
$sSQL = "select * from word where word_id in (".substr($aPlaceSearchName['name_vector'],1,-1).")"; $sSQL = "select * from word where word_id in (".substr($aPlaceSearchName['name_vector'],1,-1).")";
$aPlaceSearchNameKeywords = $oDB->getAll($sSQL); $aPlaceSearchNameKeywords = $oDB->getAll($sSQL);
if (PEAR::isError($aPlaceSearchNameKeywords)) // possible timeout if (PEAR::isError($aPlaceSearchNameKeywords)) { // possible timeout
{
$aPlaceSearchNameKeywords = []; $aPlaceSearchNameKeywords = [];
} }
$sSQL = "select * from word where word_id in (".substr($aPlaceSearchName['nameaddress_vector'],1,-1).")"; $sSQL = "select * from word where word_id in (".substr($aPlaceSearchName['nameaddress_vector'],1,-1).")";
$aPlaceSearchAddressKeywords = $oDB->getAll($sSQL); $aPlaceSearchAddressKeywords = $oDB->getAll($sSQL);
if (PEAR::isError($aPlaceSearchAddressKeywords)) // possible timeout if (PEAR::isError($aPlaceSearchAddressKeywords)) { // possible timeout
{
$aPlaceSearchAddressKeywords = []; $aPlaceSearchAddressKeywords = [];
} }
} }
logEnd($oDB, $hLog, 1); logEnd($oDB, $hLog, 1);
if ($sOutputFormat=='html') if ($sOutputFormat=='html') {
{
$sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1")); $sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
$sTileURL = CONST_Map_Tile_URL; $sTileURL = CONST_Map_Tile_URL;
$sTileAttribution = CONST_Map_Tile_Attribution; $sTileAttribution = CONST_Map_Tile_Attribution;

View File

@@ -20,17 +20,14 @@ $iOsmId = $oParams->getInt('osmid', -1);
$oDB =& getDB(); $oDB =& getDB();
if ($sOsmType && $iOsmId > 0) if ($sOsmType && $iOsmId > 0) {
{
$sPlaceId = chksql($oDB->getOne("select place_id from placex where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by type = 'postcode' asc")); $sPlaceId = chksql($oDB->getOne("select place_id from placex where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by type = 'postcode' asc"));
// Be nice about our error messages for broken geometry // Be nice about our error messages for broken geometry
if (!$sPlaceId) if (!$sPlaceId) {
{
$aPointDetails = chksql($oDB->getRow("select osm_type, osm_id, errormessage, class, type, get_name_by_language(name,$sLanguagePrefArraySQL) as localname, ST_AsText(prevgeometry) as prevgeom, ST_AsText(newgeometry) as newgeom from import_polygon_error where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by updated desc limit 1")); $aPointDetails = chksql($oDB->getRow("select osm_type, osm_id, errormessage, class, type, get_name_by_language(name,$sLanguagePrefArraySQL) as localname, ST_AsText(prevgeometry) as prevgeom, ST_AsText(newgeometry) as newgeom from import_polygon_error where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by updated desc limit 1"));
if ($aPointDetails) { if ($aPointDetails) {
if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches)) if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches)) {
{
$aPointDetails['error_x'] = $aMatches[1]; $aPointDetails['error_x'] = $aMatches[1];
$aPointDetails['error_y'] = $aMatches[2]; $aPointDetails['error_y'] = $aMatches[2];
} }
@@ -44,14 +41,12 @@ if (!$sPlaceId) userError("Please select a place id");
$iPlaceID = (int)$sPlaceId; $iPlaceID = (int)$sPlaceId;
if (CONST_Use_US_Tiger_Data) if (CONST_Use_US_Tiger_Data) {
{
$iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_tiger where place_id = '.$iPlaceID)); $iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_tiger where place_id = '.$iPlaceID));
if ($iParentPlaceID) $iPlaceID = $iParentPlaceID; if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
} }
if (CONST_Use_Aux_Location_data) if (CONST_Use_Aux_Location_data) {
{
$iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_aux where place_id = '.$iPlaceID)); $iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_aux where place_id = '.$iPlaceID));
if ($iParentPlaceID) $iPlaceID = $iParentPlaceID; if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
} }
@@ -65,16 +60,14 @@ $aPlaceAddress = array_reverse($oPlaceLookup->getAddressDetails($iPlaceID));
if (!sizeof($aPlaceAddress)) userError("Unknown place id."); if (!sizeof($aPlaceAddress)) userError("Unknown place id.");
$aBreadcrums = array(); $aBreadcrums = array();
foreach($aPlaceAddress as $i => $aPlace) foreach ($aPlaceAddress as $i => $aPlace) {
{
if (!$aPlace['place_id']) continue; if (!$aPlace['place_id']) continue;
$aBreadcrums[] = array('placeId' => $aPlace['place_id'], $aBreadcrums[] = array('placeId' => $aPlace['place_id'],
'osmType' => $aPlace['osm_type'], 'osmType' => $aPlace['osm_type'],
'osmId' => $aPlace['osm_id'], 'osmId' => $aPlace['osm_id'],
'localName' => $aPlace['localname']); 'localName' => $aPlace['localname']);
if ($sOutputFormat == 'html') if ($sOutputFormat == 'html') {
{
$sPlaceUrl = 'hierarchy.php?place_id='.$aPlace['place_id']; $sPlaceUrl = 'hierarchy.php?place_id='.$aPlace['place_id'];
if ($i) echo " &gt; "; if ($i) echo " &gt; ";
echo '<a href="'.$sPlaceUrl.'">'.$aPlace['localname'].'</a> ('.osmLink($aPlace).')'; echo '<a href="'.$sPlaceUrl.'">'.$aPlace['localname'].'</a> ('.osmLink($aPlace).')';
@@ -82,8 +75,7 @@ foreach($aPlaceAddress as $i => $aPlace)
} }
if ($sOutputFormat == 'json') if ($sOutputFormat == 'json') {
{
header("content-type: application/json; charset=UTF-8"); header("content-type: application/json; charset=UTF-8");
$aDetails = array(); $aDetails = array();
$aDetails['breadcrumbs'] = $aBreadcrums; $aDetails['breadcrumbs'] = $aBreadcrums;
@@ -100,34 +92,28 @@ $sSQL .= " where parent_place_id in (".join(',',$aRelatedPlaceIDs).") and name i
$sSQL .= " order by rank_address asc,rank_search asc,localname,class, type,housenumber"; $sSQL .= " order by rank_address asc,rank_search asc,localname,class, type,housenumber";
$aParentOfLines = chksql($oDB->getAll($sSQL)); $aParentOfLines = chksql($oDB->getAll($sSQL));
if (sizeof($aParentOfLines)) if (sizeof($aParentOfLines)) {
{
echo '<h2>Parent Of:</h2>'; echo '<h2>Parent Of:</h2>';
$aClassType = getClassTypesWithImportance(); $aClassType = getClassTypesWithImportance();
$aGroupedAddressLines = array(); $aGroupedAddressLines = array();
foreach($aParentOfLines as $aAddressLine) foreach ($aParentOfLines as $aAddressLine) {
{
if (isset($aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label']) if (isset($aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'])
&& $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label']) && $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label']
{ ) {
$aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label']; $aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'];
} } elseif (isset($aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'])
elseif (isset($aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label']) && $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label']
&& $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label']) ) {
{
$aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label']; $aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'];
} } else $aAddressLine['label'] = ucwords($aAddressLine['type']);
else $aAddressLine['label'] = ucwords($aAddressLine['type']);
if (!isset($aGroupedAddressLines[$aAddressLine['label']])) $aGroupedAddressLines[$aAddressLine['label']] = array(); if (!isset($aGroupedAddressLines[$aAddressLine['label']])) $aGroupedAddressLines[$aAddressLine['label']] = array();
$aGroupedAddressLines[$aAddressLine['label']][] = $aAddressLine; $aGroupedAddressLines[$aAddressLine['label']][] = $aAddressLine;
} }
foreach($aGroupedAddressLines as $sGroupHeading => $aParentOfLines) foreach ($aGroupedAddressLines as $sGroupHeading => $aParentOfLines) {
{
echo "<h3>$sGroupHeading</h3>"; echo "<h3>$sGroupHeading</h3>";
foreach($aParentOfLines as $aAddressLine) foreach ($aParentOfLines as $aAddressLine) {
{
$aAddressLine['localname'] = $aAddressLine['localname']?$aAddressLine['localname']:$aAddressLine['housenumber']; $aAddressLine['localname'] = $aAddressLine['localname']?$aAddressLine['localname']:$aAddressLine['housenumber'];
$sOSMType = formatOSMType($aAddressLine['osm_type'], false); $sOSMType = formatOSMType($aAddressLine['osm_type'], false);

View File

@@ -31,23 +31,20 @@ $oPlaceLookup->setIncludeNameDetails($oParams->getBool('namedetails', false));
$aOsmIds = explode(',', $oParams->getString('osm_ids', '')); $aOsmIds = explode(',', $oParams->getString('osm_ids', ''));
if (count($aOsmIds) > CONST_Places_Max_ID_count) if (count($aOsmIds) > CONST_Places_Max_ID_count) {
{
userError('Bulk User: Only ' . CONST_Places_Max_ID_count . " ids are allowed in one request."); userError('Bulk User: Only ' . CONST_Places_Max_ID_count . " ids are allowed in one request.");
} }
foreach ($aOsmIds AS $sItem) foreach ($aOsmIds AS $sItem) {
{
// Skip empty sItem // Skip empty sItem
if (empty($sItem)) continue; if (empty($sItem)) continue;
$sType = $sItem[0]; $sType = $sItem[0];
$iId = (int) substr($sItem, 1); $iId = (int) substr($sItem, 1);
if ( $iId > 0 && ($sType == 'N' || $sType == 'W' || $sType == 'R') ) if ($iId > 0 && ($sType == 'N' || $sType == 'W' || $sType == 'R')) {
{
$aCleanedQueryParts[] = $sType . $iId; $aCleanedQueryParts[] = $sType . $iId;
$oPlace = $oPlaceLookup->lookupOSMID($sType, $iId); $oPlace = $oPlaceLookup->lookupOSMID($sType, $iId);
if ($oPlace){ if ($oPlace) {
// we want to use the search-* output templates, so we need to fill // we want to use the search-* output templates, so we need to fill
// $aSearchResults and slightly change the (reverse search) oPlace // $aSearchResults and slightly change the (reverse search) oPlace
// key names // key names

View File

@@ -17,8 +17,7 @@
$iTotalBroken = (int) chksql($oDB->getOne('select count(*) from import_polygon_error')); $iTotalBroken = (int) chksql($oDB->getOne('select count(*) from import_polygon_error'));
$aPolygons = array(); $aPolygons = array();
while($iTotalBroken && !sizeof($aPolygons)) while ($iTotalBroken && !sizeof($aPolygons)) {
{
$sSQL = 'select osm_type as "type",osm_id as "id",class as "key",type as "value",name->\'name\' as "name",'; $sSQL = 'select osm_type as "type",osm_id as "id",class as "key",type as "value",name->\'name\' as "name",';
$sSQL .= 'country_code as "country",errormessage as "error message",updated'; $sSQL .= 'country_code as "country",errormessage as "error message",updated';
$sSQL .= " from import_polygon_error"; $sSQL .= " from import_polygon_error";
@@ -31,8 +30,7 @@
$aPolygons = chksql($oDB->getAll($sSQL)); $aPolygons = chksql($oDB->getAll($sSQL));
} }
if (CONST_Debug) if (CONST_Debug) {
{
var_dump($aPolygons); var_dump($aPolygons);
exit; exit;
} }
@@ -89,32 +87,25 @@ table td {
echo "<table>"; echo "<table>";
echo "<tr>"; echo "<tr>";
//var_dump($aPolygons[0]); //var_dump($aPolygons[0]);
foreach($aPolygons[0] as $sCol => $sVal) foreach ($aPolygons[0] as $sCol => $sVal) {
{
echo "<th>".$sCol."</th>"; echo "<th>".$sCol."</th>";
} }
echo "<th>&nbsp;</th>"; echo "<th>&nbsp;</th>";
echo "<th>&nbsp;</th>"; echo "<th>&nbsp;</th>";
echo "</tr>"; echo "</tr>";
$aSeen = array(); $aSeen = array();
foreach($aPolygons as $aRow) foreach ($aPolygons as $aRow) {
{
if (isset($aSeen[$aRow['type'].$aRow['id']])) continue; if (isset($aSeen[$aRow['type'].$aRow['id']])) continue;
$aSeen[$aRow['type'].$aRow['id']] = 1; $aSeen[$aRow['type'].$aRow['id']] = 1;
echo "<tr>"; echo "<tr>";
foreach($aRow as $sCol => $sVal) foreach ($aRow as $sCol => $sVal) {
{ switch ($sCol) {
switch($sCol)
{
case 'error message': case 'error message':
if (preg_match('/Self-intersection\\[([0-9.\\-]+) ([0-9.\\-]+)\\]/',$sVal,$aMatch)) if (preg_match('/Self-intersection\\[([0-9.\\-]+) ([0-9.\\-]+)\\]/',$sVal,$aMatch)) {
{
$aRow['lat'] = $aMatch[2]; $aRow['lat'] = $aMatch[2];
$aRow['lon'] = $aMatch[1]; $aRow['lon'] = $aMatch[1];
echo "<td><a href=\"http://www.openstreetmap.org/?lat=".$aMatch[2]."&lon=".$aMatch[1]."&zoom=18&layers=M&".$sOSMType."=".$aRow['id']."\">".($sVal?$sVal:'&nbsp;')."</a></td>"; echo "<td><a href=\"http://www.openstreetmap.org/?lat=".$aMatch[2]."&lon=".$aMatch[1]."&zoom=18&layers=M&".$sOSMType."=".$aRow['id']."\">".($sVal?$sVal:'&nbsp;')."</a></td>";
} } else {
else
{
echo "<td>".($sVal?$sVal:'&nbsp;')."</td>"; echo "<td>".($sVal?$sVal:'&nbsp;')."</td>";
} }
break; break;
@@ -127,12 +118,9 @@ table td {
} }
} }
echo "<td><a href=\"http://localhost:8111/import?url=http://www.openstreetmap.org/api/0.6/".$sOSMType.'/'.$aRow['id']."/full\" target=\"josm\">josm</a></td>"; echo "<td><a href=\"http://localhost:8111/import?url=http://www.openstreetmap.org/api/0.6/".$sOSMType.'/'.$aRow['id']."/full\" target=\"josm\">josm</a></td>";
if (isset($aRow['lat'])) if (isset($aRow['lat'])) {
{
echo "<td><a href=\"http://open.mapquestapi.com/dataedit/index_flash.html?lat=".$aRow['lat']."&lon=".$aRow['lon']."&zoom=18\" target=\"potlatch2\">P2</a></td>"; echo "<td><a href=\"http://open.mapquestapi.com/dataedit/index_flash.html?lat=".$aRow['lat']."&lon=".$aRow['lon']."&zoom=18\" target=\"potlatch2\">P2</a></td>";
} } else {
else
{
echo "<td>&nbsp;</td>"; echo "<td>&nbsp;</td>";
} }
echo "</tr>"; echo "</tr>";

View File

@@ -16,14 +16,11 @@ $bAsKML = $oParams->getBool('polygon_kml');
$bAsSVG = $oParams->getBool('polygon_svg'); $bAsSVG = $oParams->getBool('polygon_svg');
$bAsText = $oParams->getBool('polygon_text'); $bAsText = $oParams->getBool('polygon_text');
if ((($bAsGeoJSON?1:0) + ($bAsKML?1:0) + ($bAsSVG?1:0) if ((($bAsGeoJSON?1:0) + ($bAsKML?1:0) + ($bAsSVG?1:0)
+ ($bAsText?1:0)) > CONST_PolygonOutput_MaximumTypes) + ($bAsText?1:0)) > CONST_PolygonOutput_MaximumTypes
{ ) {
if (CONST_PolygonOutput_MaximumTypes) if (CONST_PolygonOutput_MaximumTypes) {
{
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option"); userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
} } else {
else
{
userError("Polygon output is disabled"); userError("Polygon output is disabled");
} }
} }
@@ -52,12 +49,9 @@ $sOsmType = $oParams->getSet('osm_type', array('N', 'W', 'R'));
$iOsmId = $oParams->getInt('osm_id', -1); $iOsmId = $oParams->getInt('osm_id', -1);
$fLat = $oParams->getFloat('lat'); $fLat = $oParams->getFloat('lat');
$fLon = $oParams->getFloat('lon'); $fLon = $oParams->getFloat('lon');
if ($sOsmType && $iOsmId > 0) if ($sOsmType && $iOsmId > 0) {
{
$aPlace = $oPlaceLookup->lookupOSMID($sOsmType, $iOsmId); $aPlace = $oPlaceLookup->lookupOSMID($sOsmType, $iOsmId);
} } else if ($fLat !== false && $fLon !== false) {
else if ($fLat !== false && $fLon !== false)
{
$oReverseGeocode = new ReverseGeocode($oDB); $oReverseGeocode = new ReverseGeocode($oDB);
$oReverseGeocode->setZoom($oParams->getInt('zoom', 18)); $oReverseGeocode->setZoom($oParams->getInt('zoom', 18));
@@ -66,14 +60,11 @@ else if ($fLat !== false && $fLon !== false)
$aPlace = $oPlaceLookup->lookup((int)$aLookup['place_id'], $aPlace = $oPlaceLookup->lookup((int)$aLookup['place_id'],
$aLookup['type'], $aLookup['fraction']); $aLookup['type'], $aLookup['fraction']);
} } else if ($sOutputFormat != 'html') {
else if ($sOutputFormat != 'html')
{
userError("Need coordinates or OSM object to lookup."); userError("Need coordinates or OSM object to lookup.");
} }
if ($aPlace) if ($aPlace) {
{
$oPlaceLookup->setIncludePolygonAsPoints(false); $oPlaceLookup->setIncludePolygonAsPoints(false);
$oPlaceLookup->setIncludePolygonAsText($bAsText); $oPlaceLookup->setIncludePolygonAsText($bAsText);
$oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON); $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON);
@@ -86,21 +77,18 @@ if ($aPlace)
$aPlace['lon'], $aPlace['lat'], $aPlace['lon'], $aPlace['lat'],
$fRadius); $fRadius);
if ($aOutlineResult) if ($aOutlineResult) {
{
$aPlace = array_merge($aPlace, $aOutlineResult); $aPlace = array_merge($aPlace, $aOutlineResult);
} }
} }
if (CONST_Debug) if (CONST_Debug) {
{
var_dump($aPlace); var_dump($aPlace);
exit; exit;
} }
if ($sOutputFormat=='html') if ($sOutputFormat=='html') {
{
$sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1")); $sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
$sTileURL = CONST_Map_Tile_URL; $sTileURL = CONST_Map_Tile_URL;
$sTileAttribution = CONST_Map_Tile_Attribution; $sTileAttribution = CONST_Map_Tile_Attribution;

View File

@@ -20,8 +20,8 @@ if (CONST_Search_ReversePlanForAll
|| isset($aLangPrefOrder['name:de']) || isset($aLangPrefOrder['name:de'])
|| isset($aLangPrefOrder['name:ru']) || isset($aLangPrefOrder['name:ru'])
|| isset($aLangPrefOrder['name:ja']) || isset($aLangPrefOrder['name:ja'])
|| isset($aLangPrefOrder['name:pl'])) || isset($aLangPrefOrder['name:pl'])
{ ) {
$oGeocode->setReverseInPlan(true); $oGeocode->setReverseInPlan(true);
} }
@@ -29,31 +29,25 @@ if (CONST_Search_ReversePlanForAll
$sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2'), 'html'); $sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2'), 'html');
// Show / use polygons // Show / use polygons
if ($sOutputFormat == 'html') if ($sOutputFormat == 'html') {
{
$oGeocode->setIncludePolygonAsText($oParams->getBool('polygon')); $oGeocode->setIncludePolygonAsText($oParams->getBool('polygon'));
$bAsText = false; $bAsText = false;
} } else {
else
{
$bAsPoints = $oParams->getBool('polygon'); $bAsPoints = $oParams->getBool('polygon');
$bAsGeoJSON = $oParams->getBool('polygon_geojson'); $bAsGeoJSON = $oParams->getBool('polygon_geojson');
$bAsKML = $oParams->getBool('polygon_kml'); $bAsKML = $oParams->getBool('polygon_kml');
$bAsSVG = $oParams->getBool('polygon_svg'); $bAsSVG = $oParams->getBool('polygon_svg');
$bAsText = $oParams->getBool('polygon_text'); $bAsText = $oParams->getBool('polygon_text');
if ( ( ($bAsGeoJSON?1:0) if (( ($bAsGeoJSON?1:0)
+ ($bAsKML?1:0) + ($bAsKML?1:0)
+ ($bAsSVG?1:0) + ($bAsSVG?1:0)
+ ($bAsText?1:0) + ($bAsText?1:0)
+ ($bAsPoints?1:0) + ($bAsPoints?1:0)
) > CONST_PolygonOutput_MaximumTypes) ) > CONST_PolygonOutput_MaximumTypes
{ ) {
if (CONST_PolygonOutput_MaximumTypes) if (CONST_PolygonOutput_MaximumTypes) {
{
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option"); userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
} } else {
else
{
userError("Polygon output is disabled"); userError("Polygon output is disabled");
} }
exit; exit;
@@ -70,12 +64,10 @@ $oGeocode->setPolygonSimplificationThreshold($oParams->getFloat('polygon_thresho
$oGeocode->loadParamArray($oParams); $oGeocode->loadParamArray($oParams);
if (CONST_Search_BatchMode && isset($_GET['batch'])) if (CONST_Search_BatchMode && isset($_GET['batch'])) {
{
$aBatch = json_decode($_GET['batch'], true); $aBatch = json_decode($_GET['batch'], true);
$aBatchResults = array(); $aBatchResults = array();
foreach($aBatch as $aBatchParams) foreach ($aBatch as $aBatchParams) {
{
$oBatchGeocode = clone $oGeocode; $oBatchGeocode = clone $oGeocode;
$oBatchParams = new ParameterParser($aBatchParams); $oBatchParams = new ParameterParser($aBatchParams);
$oBatchGeocode->loadParamArray($oBatchParams); $oBatchGeocode->loadParamArray($oBatchParams);
@@ -90,8 +82,7 @@ if (CONST_Search_BatchMode && isset($_GET['batch']))
$oGeocode->setQueryFromParams($oParams); $oGeocode->setQueryFromParams($oParams);
if (!$oGeocode->getQueryString() if (!$oGeocode->getQueryString()
&& isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/') && isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/') {
{
$sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1); $sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1);
// reverse order of '/' separated string // reverse order of '/' separated string
@@ -106,8 +97,7 @@ $hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);
$aSearchResults = $oGeocode->lookup(); $aSearchResults = $oGeocode->lookup();
if ($aSearchResults === false) $aSearchResults = array(); if ($aSearchResults === false) $aSearchResults = array();
if ($sOutputFormat=='html') if ($sOutputFormat=='html') {
{
$sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1")); $sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
} }
logEnd($oDB, $hLog, sizeof($aSearchResults)); logEnd($oDB, $hLog, sizeof($aSearchResults));

View File

@@ -12,28 +12,23 @@ function statusError($sMsg)
} }
$oDB =& DB::connect(CONST_Database_DSN, false); $oDB =& DB::connect(CONST_Database_DSN, false);
if (!$oDB || PEAR::isError($oDB)) if (!$oDB || PEAR::isError($oDB)) {
{
statusError("No database"); statusError("No database");
} }
$sStandardWord = $oDB->getOne("select make_standard_name('a')"); $sStandardWord = $oDB->getOne("select make_standard_name('a')");
if (PEAR::isError($sStandardWord)) if (PEAR::isError($sStandardWord)) {
{
statusError("Module failed"); statusError("Module failed");
} }
if ($sStandardWord != 'a') if ($sStandardWord != 'a') {
{
statusError("Module call failed"); statusError("Module call failed");
} }
$iWordID = $oDB->getOne("select word_id,word_token, word, class, type, country_code, operator, search_name_count from word where word_token in (' a')"); $iWordID = $oDB->getOne("select word_id,word_token, word, class, type, country_code, operator, search_name_count from word where word_token in (' a')");
if (PEAR::isError($iWordID)) if (PEAR::isError($iWordID)) {
{
statusError("Query failed"); statusError("Query failed");
} }
if (!$iWordID) if (!$iWordID) {
{
statusError("No value"); statusError("No value");
} }