function loadParamArray($oParams)
{
- $this->bIncludeAddressDetails = $oParams->getBool('addressdetails',
- $this->bIncludeAddressDetails);
- $this->bIncludeExtraTags = $oParams->getBool('extratags',
- $this->bIncludeExtraTags);
- $this->bIncludeNameDetails = $oParams->getBool('namedetails',
- $this->bIncludeNameDetails);
+ $this->bIncludeAddressDetails
+ = $oParams->getBool('addressdetails', $this->bIncludeAddressDetails);
+ $this->bIncludeExtraTags
+ = $oParams->getBool('extratags', $this->bIncludeExtraTags);
+ $this->bIncludeNameDetails
+ = $oParams->getBool('namedetails', $this->bIncludeNameDetails);
$this->bBoundedSearch = $oParams->getBool('bounded', $this->bBoundedSearch);
$this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
// Search query
$sQuery = $oParams->getString('q');
if (!$sQuery) {
- $this->setStructuredQuery($oParams->getString('amenity'),
- $oParams->getString('street'),
- $oParams->getString('city'),
- $oParams->getString('county'),
- $oParams->getString('state'),
- $oParams->getString('country'),
- $oParams->getString('postalcode'));
+ $this->setStructuredQuery(
+ $oParams->getString('amenity'),
+ $oParams->getString('street'),
+ $oParams->getString('city'),
+ $oParams->getString('county'),
+ $oParams->getString('state'),
+ $oParams->getString('country'),
+ $oParams->getString('postalcode')
+ );
$this->setReverseInPlan(false);
} else {
$this->setQuery($sQuery);
$this->loadStructuredAddressElement($sCity, 'city', 14, 24, false);
$this->loadStructuredAddressElement($sCounty, 'county', 9, 13, false);
$this->loadStructuredAddressElement($sState, 'state', 8, 8, false);
- $this->loadStructuredAddressElement($sPostalCode, 'postalcode' , 5, 11, array(5, 11));
+ $this->loadStructuredAddressElement($sPostalCode, 'postalcode', 5, 11, array(5, 11));
$this->loadStructuredAddressElement($sCountry, 'country', 4, 4, false);
if (sizeof($this->aStructuredQuery) > 0) {
//$aPlaceIDs is an array with key: placeID and value: tiger-housenumber, if found, else -1
if (sizeof($aPlaceIDs) == 0) return array();
- $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$this->aLangPrefOrder))."]";
+ $sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $this->aLangPrefOrder))."]";
// Get the details for display (is this a redundant extra step?)
$sPlaceIDs = join(',', array_keys($aPlaceIDs));
$sSQL .= "from placex where place_id in ($sPlaceIDs) ";
$sSQL .= "and (placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) $sSQL .= " OR (extratags->'place') = 'city'";
- if ($this->aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',',$this->aAddressRankList).")";
+ if ($this->aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',', $this->aAddressRankList).")";
$sSQL .= ") ";
if ($this->sAllowedTypesSQLList) $sSQL .= "and placex.class in $this->sAllowedTypesSQLList ";
$sSQL .= "and linked_place_id is null ";
if (CONST_Debug) {
echo "<hr>"; var_dump($sSQL);
}
- $aSearchResults = chksql($this->oDB->getAll($sSQL),
- "Could not get details for place.");
+ $aSearchResults = chksql(
+ $this->oDB->getAll($sSQL),
+ "Could not get details for place."
+ );
return $aSearchResults;
}
if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
foreach ($aValidTokens[' '.$sToken] as $aSearchTermToken) {
if (empty($aSearchTermToken['country_code'])
- && empty($aSearchTermToken['lat'])
- && empty($aSearchTermToken['class'])
+ && empty($aSearchTermToken['lat'])
+ && empty($aSearchTermToken['class'])
) {
$aSearch = $aCurrentSearch;
$aSearch['iSearchRank'] += 1;
{
if (!$this->sQuery && !$this->aStructuredQuery) return false;
- $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$this->aLangPrefOrder))."]";
+ $sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $this->aLangPrefOrder))."]";
$sCountryCodesSQL = false;
if ($this->aCountryCodes) {
$sCountryCodesSQL = join(',', array_map('addQuotes', $this->aCountryCodes));
// Conflicts between US state abreviations and various words for 'the' in different languages
if (isset($this->aLangPrefOrder['name:en'])) {
- $sQuery = preg_replace('/(^|,)\s*il\s*(,|$)/','\1illinois\2', $sQuery);
- $sQuery = preg_replace('/(^|,)\s*al\s*(,|$)/','\1alabama\2', $sQuery);
- $sQuery = preg_replace('/(^|,)\s*la\s*(,|$)/','\1louisiana\2', $sQuery);
+ $sQuery = preg_replace('/(^|,)\s*il\s*(,|$)/', '\1illinois\2', $sQuery);
+ $sQuery = preg_replace('/(^|,)\s*al\s*(,|$)/', '\1alabama\2', $sQuery);
+ $sQuery = preg_replace('/(^|,)\s*la\s*(,|$)/', '\1louisiana\2', $sQuery);
}
$bBoundingBoxSearch = $this->bBoundedSearch && $this->sViewboxSmallSQL;
if ($this->sViewboxCentreSQL) {
// For complex viewboxes (routes) precompute the bounding geometry
- $sGeom = chksql($this->oDB->getOne("select ".$this->sViewboxSmallSQL),
- "Could not get small viewbox");
+ $sGeom = chksql(
+ $this->oDB->getOne("select ".$this->sViewboxSmallSQL),
+ "Could not get small viewbox"
+ );
$this->sViewboxSmallSQL = "'".$sGeom."'::geometry";
- $sGeom = chksql($this->oDB->getOne("select ".$this->sViewboxLargeSQL),
- "Could not get large viewbox");
+ $sGeom = chksql(
+ $this->oDB->getOne("select ".$this->sViewboxLargeSQL),
+ "Could not get large viewbox"
+ );
$this->sViewboxLargeSQL = "'".$sGeom."'::geometry";
}
$aPhrases = $this->aStructuredQuery;
$bStructuredPhrases = true;
} else {
- $aPhrases = explode(',',$sQuery);
+ $aPhrases = explode(',', $sQuery);
$bStructuredPhrases = false;
}
// Generate a complete list of all
$aTokens = array();
foreach ($aPhrases as $iPhrase => $sPhrase) {
- $aPhrase = chksql($this->oDB->getRow("select make_standard_name('".pg_escape_string($sPhrase)."') as string"),
- "Cannot nomralize query string (is it an UTF-8 string?)");
+ $aPhrase = chksql(
+ $this->oDB->getRow("select make_standard_name('".pg_escape_string($sPhrase)."') as string"),
+ "Cannot nomralize query string (is it an UTF-8 string?)"
+ );
if (trim($aPhrase['string'])) {
$aPhrases[$iPhrase] = $aPhrase;
- $aPhrases[$iPhrase]['words'] = explode(' ',$aPhrases[$iPhrase]['string']);
+ $aPhrases[$iPhrase]['words'] = explode(' ', $aPhrases[$iPhrase]['string']);
$aPhrases[$iPhrase]['wordsets'] = getWordSets($aPhrases[$iPhrase]['words'], 0);
$aTokens = array_merge($aTokens, getTokensFromSets($aPhrases[$iPhrase]['wordsets']));
} else {
if (sizeof($aTokens)) {
// Check which tokens we have, get the ID numbers
$sSQL = 'select word_id,word_token, word, class, type, country_code, operator, search_name_count';
- $sSQL .= ' from word where word_token in ('.join(',',array_map("getDBQuoted",$aTokens)).')';
+ $sSQL .= ' from word where word_token in ('.join(',', array_map("getDBQuoted", $aTokens)).')';
if (CONST_Debug) var_Dump($sSQL);
$aValidTokens = array();
if (sizeof($aTokens)) {
- $aDatabaseWords = chksql($this->oDB->getAll($sSQL),
- "Could not get word tokens.");
+ $aDatabaseWords = chksql(
+ $this->oDB->getAll($sSQL),
+ "Could not get word tokens."
+ );
} else {
$aDatabaseWords = array();
}
foreach ($aTokens as $sToken) {
// Source of gb postcodes is now definitive - always use
if (preg_match('/^([A-Z][A-Z]?[0-9][0-9A-Z]? ?[0-9])([A-Z][A-Z])$/', strtoupper(trim($sToken)), $aData)) {
- if (substr($aData[1],-2,1) != ' ') {
- $aData[0] = substr($aData[0],0,strlen($aData[1])-1).' '.substr($aData[0],strlen($aData[1])-1);
- $aData[1] = substr($aData[1],0,-1).' '.substr($aData[1],-1,1);
+ if (substr($aData[1], -2, 1) != ' ') {
+ $aData[0] = substr($aData[0], 0, strlen($aData[1])-1).' '.substr($aData[0], strlen($aData[1])-1);
+ $aData[1] = substr($aData[1], 0, -1).' '.substr($aData[1], -1, 1);
}
$aGBPostcodeLocation = gbPostcodeCalculate($aData[0], $aData[1], $aData[2], $this->oDB);
if ($aGBPostcodeLocation) {
$aValidTokens[$sToken] = $aGBPostcodeLocation;
}
- } else if (!isset($aValidTokens[$sToken]) && preg_match('/^([0-9]{5}) [0-9]{4}$/', $sToken, $aData)) {
+ } elseif (!isset($aValidTokens[$sToken]) && preg_match('/^([0-9]{5}) [0-9]{4}$/', $sToken, $aData)) {
// US ZIP+4 codes - if there is no token,
// merge in the 5-digit ZIP code
if (isset($aValidTokens[$aData[1]])) {
foreach ($aTokens as $sToken) {
// Unknown single word token with a number - assume it is a house number
- if (!isset($aValidTokens[' '.$sToken]) && strpos($sToken,' ') === false && preg_match('/[0-9]/', $sToken)) {
+ if (!isset($aValidTokens[' '.$sToken]) && strpos($sToken, ' ') === false && preg_match('/[0-9]/', $sToken)) {
$aValidTokens[' '.$sToken] = array(array('class' => 'place', 'type' => 'house'));
}
}
$sSQL .= " where st_contains($this->sViewboxSmallSQL, ct.centroid)";
if ($sCountryCodesSQL) $sSQL .= " and calculated_country_code in ($sCountryCodesSQL)";
if (sizeof($this->aExcludePlaceIDs)) {
- $sSQL .= " and place_id not in (".join(',',$this->aExcludePlaceIDs).")";
+ $sSQL .= " and place_id not in (".join(',', $this->aExcludePlaceIDs).")";
}
if ($this->sViewboxCentreSQL) $sSQL .= " order by st_distance($this->sViewboxCentreSQL, ct.centroid) asc";
$sSQL .= " limit $this->iLimit";
$aPlaceIDs = chksql($this->oDB->getCol($sSQL));
}
}
- } else if ($aSearch['fLon'] && !sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['sClass']) {
+ } elseif ($aSearch['fLon'] && !sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['sClass']) {
// If a coordinate is given, the search must either
// be for a name or a special search. Ignore everythin else.
$aPlaceIDs = array();
// TODO: filter out the pointless search terms (2 letter name tokens and less)
// they might be right - but they are just too darned expensive to run
- if (sizeof($aSearch['aName'])) $aTerms[] = "name_vector @> ARRAY[".join($aSearch['aName'],",")."]";
- if (sizeof($aSearch['aNameNonSearch'])) $aTerms[] = "array_cat(name_vector,ARRAY[]::integer[]) @> ARRAY[".join($aSearch['aNameNonSearch'],",")."]";
+ if (sizeof($aSearch['aName'])) $aTerms[] = "name_vector @> ARRAY[".join($aSearch['aName'], ",")."]";
+ if (sizeof($aSearch['aNameNonSearch'])) $aTerms[] = "array_cat(name_vector,ARRAY[]::integer[]) @> ARRAY[".join($aSearch['aNameNonSearch'], ",")."]";
if (sizeof($aSearch['aAddress']) && $aSearch['aName'] != $aSearch['aAddress']) {
// For infrequent name terms disable index usage for address
- if (CONST_Search_NameOnlySearchFrequencyThreshold &&
- sizeof($aSearch['aName']) == 1 &&
- $aWordFrequencyScores[$aSearch['aName'][reset($aSearch['aName'])]] < CONST_Search_NameOnlySearchFrequencyThreshold
+ if (CONST_Search_NameOnlySearchFrequencyThreshold
+ && sizeof($aSearch['aName']) == 1
+ && $aWordFrequencyScores[$aSearch['aName'][reset($aSearch['aName'])]] < CONST_Search_NameOnlySearchFrequencyThreshold
) {
- $aTerms[] = "array_cat(nameaddress_vector,ARRAY[]::integer[]) @> ARRAY[".join(array_merge($aSearch['aAddress'],$aSearch['aAddressNonSearch']),",")."]";
+ $aTerms[] = "array_cat(nameaddress_vector,ARRAY[]::integer[]) @> ARRAY[".join(array_merge($aSearch['aAddress'], $aSearch['aAddressNonSearch']), ",")."]";
} else {
- $aTerms[] = "nameaddress_vector @> ARRAY[".join($aSearch['aAddress'],",")."]";
+ $aTerms[] = "nameaddress_vector @> ARRAY[".join($aSearch['aAddress'], ",")."]";
if (sizeof($aSearch['aAddressNonSearch'])) {
- $aTerms[] = "array_cat(nameaddress_vector,ARRAY[]::integer[]) @> ARRAY[".join($aSearch['aAddressNonSearch'],",")."]";
+ $aTerms[] = "array_cat(nameaddress_vector,ARRAY[]::integer[]) @> ARRAY[".join($aSearch['aAddressNonSearch'], ",")."]";
}
}
}
$aOrder[] = "ST_Distance(centroid, ST_SetSRID(ST_Point(".$aSearch['fLon'].",".$aSearch['fLat']."),4326)) ASC";
}
if (sizeof($this->aExcludePlaceIDs)) {
- $aTerms[] = "place_id not in (".join(',',$this->aExcludePlaceIDs).")";
+ $aTerms[] = "place_id not in (".join(',', $this->aExcludePlaceIDs).")";
}
if ($sCountryCodesSQL) {
$aTerms[] = "country_code in ($sCountryCodesSQL)";
$aOrder[] = "$sImportanceSQL DESC";
if (sizeof($aSearch['aFullNameAddress'])) {
- $sExactMatchSQL = '(select count(*) from (select unnest(ARRAY['.join($aSearch['aFullNameAddress'],",").']) INTERSECT select unnest(nameaddress_vector))s) as exactmatch';
+ $sExactMatchSQL = '(select count(*) from (select unnest(ARRAY['.join($aSearch['aFullNameAddress'], ",").']) INTERSECT select unnest(nameaddress_vector))s) as exactmatch';
$aOrder[] = 'exactmatch DESC';
} else {
$sExactMatchSQL = '0::int as exactmatch';
$sSQL = "select place_id, ";
$sSQL .= $sExactMatchSQL;
$sSQL .= " from search_name";
- $sSQL .= " where ".join(' and ',$aTerms);
- $sSQL .= " order by ".join(', ',$aOrder);
+ $sSQL .= " where ".join(' and ', $aTerms);
+ $sSQL .= " order by ".join(', ', $aOrder);
if ($aSearch['sHouseNumber'] || $aSearch['sClass']) {
$sSQL .= " limit 20";
} elseif (!sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && $aSearch['sClass']) {
}
if (CONST_Debug) var_dump($sSQL);
- $aViewBoxPlaceIDs = chksql($this->oDB->getAll($sSQL),
- "Could not get places for search terms.");
+ $aViewBoxPlaceIDs = chksql(
+ $this->oDB->getAll($sSQL),
+ "Could not get places for search terms."
+ );
//var_dump($aViewBoxPlaceIDs);
// Did we have an viewbox matches?
$aPlaceIDs = array();
if ($aSearch['sHouseNumber'] && sizeof($aPlaceIDs)) {
$searchedHousenumber = intval($aSearch['sHouseNumber']);
$aRoadPlaceIDs = $aPlaceIDs;
- $sPlaceIDs = join(',',$aPlaceIDs);
+ $sPlaceIDs = join(',', $aPlaceIDs);
// Now they are indexed, look for a house attached to a street we found
$sHouseNumberRegex = '\\\\m'.$aSearch['sHouseNumber'].'\\\\M';
$sSQL = "select place_id from placex where parent_place_id in (".$sPlaceIDs.") and transliteration(housenumber) ~* E'".$sHouseNumberRegex."'";
if (sizeof($this->aExcludePlaceIDs)) {
- $sSQL .= " and place_id not in (".join(',',$this->aExcludePlaceIDs).")";
+ $sSQL .= " and place_id not in (".join(',', $this->aExcludePlaceIDs).")";
}
$sSQL .= " limit $this->iLimit";
if (CONST_Debug) var_dump($sSQL);
if (CONST_Use_Aux_Location_data && !sizeof($aPlaceIDs)) {
$sSQL = "select place_id from location_property_aux where parent_place_id in (".$sPlaceIDs.") and housenumber = '".pg_escape_string($aSearch['sHouseNumber'])."'";
if (sizeof($this->aExcludePlaceIDs)) {
- $sSQL .= " and parent_place_id not in (".join(',',$this->aExcludePlaceIDs).")";
+ $sSQL .= " and parent_place_id not in (".join(',', $this->aExcludePlaceIDs).")";
}
//$sSQL .= " limit $this->iLimit";
if (CONST_Debug) var_dump($sSQL);
$sSQL = "select place_id from placex where place_id in ($sPlaceIDs) and rank_search < $this->iMaxRank";
if (CONST_Debug) var_dump($sSQL);
$aPlaceIDs = chksql($this->oDB->getCol($sSQL));
- $sPlaceIDs = join(',',$aPlaceIDs);
+ $sPlaceIDs = join(',', $aPlaceIDs);
}
if ($sPlaceIDs || $sPlaceGeom) {
$sOrderBySQL = '';
if ($sNearPointSQL) $sOrderBySQL = "ST_Distance($sNearPointSQL, l.centroid)";
- else if ($sPlaceIDs) $sOrderBySQL = "ST_Distance(l.centroid, f.geometry)";
- else if ($sPlaceGeom) $sOrderBysSQL = "ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid)";
+ elseif ($sPlaceIDs) $sOrderBySQL = "ST_Distance(l.centroid, f.geometry)";
+ elseif ($sPlaceGeom) $sOrderBysSQL = "ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid)";
$sSQL = "select distinct l.place_id".($sOrderBySQL?','.$sOrderBySQL:'')." from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." as l";
if ($sCountryCodesSQL) $sSQL .= " join placex as lp using (place_id)";
$sSQL .= "ST_Contains('".$sPlaceGeom."', l.centroid) ";
}
if (sizeof($this->aExcludePlaceIDs)) {
- $sSQL .= " and l.place_id not in (".join(',',$this->aExcludePlaceIDs).")";
+ $sSQL .= " and l.place_id not in (".join(',', $this->aExcludePlaceIDs).")";
}
if ($sCountryCodesSQL) $sSQL .= " and lp.calculated_country_code in ($sCountryCodesSQL)";
if ($sOrderBySQL) $sSQL .= "order by ".$sOrderBySQL." asc";
$sSQL .= "f.place_id in ( $sPlaceIDs) and ST_DWithin(l.geometry, f.centroid, $fRange) ";
$sSQL .= "and l.class='".$aSearch['sClass']."' and l.type='".$aSearch['sType']."' ";
if (sizeof($this->aExcludePlaceIDs)) {
- $sSQL .= " and l.place_id not in (".join(',',$this->aExcludePlaceIDs).")";
+ $sSQL .= " and l.place_id not in (".join(',', $this->aExcludePlaceIDs).")";
}
if ($sCountryCodesSQL) $sSQL .= " and l.calculated_country_code in ($sCountryCodesSQL)";
if ($sOrderBy) $sSQL .= "order by ".$OrderBysSQL." asc";
// Need to verify passes rank limits before dropping out of the loop (yuk!)
// reduces the number of place ids, like a filter
// rank_address is 30 for interpolated housenumbers
- $sSQL = "select place_id from placex where place_id in (".join(',',array_keys($aResultPlaceIDs)).") ";
+ $sSQL = "select place_id from placex where place_id in (".join(',', array_keys($aResultPlaceIDs)).") ";
$sSQL .= "and (placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) $sSQL .= " OR (extratags->'place') = 'city'";
- if ($this->aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',',$this->aAddressRankList).")";
+ if ($this->aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',', $this->aAddressRankList).")";
if (CONST_Use_US_Tiger_Data) {
- $sSQL .= ") UNION select place_id from location_property_tiger where place_id in (".join(',',array_keys($aResultPlaceIDs)).") ";
+ $sSQL .= ") UNION select place_id from location_property_tiger where place_id in (".join(',', array_keys($aResultPlaceIDs)).") ";
$sSQL .= "and (30 between $this->iMinAddressRank and $this->iMaxAddressRank ";
- if ($this->aAddressRankList) $sSQL .= " OR 30 in (".join(',',$this->aAddressRankList).")";
+ if ($this->aAddressRankList) $sSQL .= " OR 30 in (".join(',', $this->aAddressRankList).")";
}
- $sSQL .= ") UNION select place_id from location_property_osmline where place_id in (".join(',',array_keys($aResultPlaceIDs)).")";
+ $sSQL .= ") UNION select place_id from location_property_osmline where place_id in (".join(',', array_keys($aResultPlaceIDs)).")";
$sSQL .= " and (30 between $this->iMinAddressRank and $this->iMaxAddressRank)";
if (CONST_Debug) var_dump($sSQL);
$aFilteredPlaceIDs = chksql($this->oDB->getCol($sSQL));
$oReverse = new ReverseGeocode($this->oDB);
$oReverse->setZoom(18);
- $aLookup = $oReverse->lookup((float)$this->aNearPoint[0],
- (float)$this->aNearPoint[1],
- false);
+ $aLookup = $oReverse->lookup(
+ (float)$this->aNearPoint[0],
+ (float)$this->aNearPoint[1],
+ false
+ );
if (CONST_Debug) var_dump("Reverse search", $aLookup);
}
$aClassType = getClassTypesWithImportance();
- $aRecheckWords = preg_split('/\b[\s,\\-]*/u',$sQuery);
+ $aRecheckWords = preg_split('/\b[\s,\\-]*/u', $sQuery);
foreach ($aRecheckWords as $i => $sWord) {
if (!preg_match('/\pL/', $sWord)) unset($aRecheckWords[$i]);
}
// Is there an icon set for this type of result?
if (isset($aClassType[$aResult['class'].':'.$aResult['type']]['icon'])
- && $aClassType[$aResult['class'].':'.$aResult['type']]['icon']
+ && $aClassType[$aResult['class'].':'.$aResult['type']]['icon']
) {
$aResult['icon'] = CONST_Website_BaseURL.'images/mapicons/'.$aClassType[$aResult['class'].':'.$aResult['type']]['icon'].'.p.20.png';
}
if (isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['label'])
- && $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['label']
+ && $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['label']
) {
$aResult['label'] = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['label'];
} elseif (isset($aClassType[$aResult['class'].':'.$aResult['type']]['label'])
- && $aClassType[$aResult['class'].':'.$aResult['type']]['label']
+ && $aClassType[$aResult['class'].':'.$aResult['type']]['label']
) {
$aResult['label'] = $aClassType[$aResult['class'].':'.$aResult['type']]['label'];
}
}
// Adjust importance for the number of exact string matches in the result
- $aResult['importance'] = max(0.001,$aResult['importance']);
+ $aResult['importance'] = max(0.001, $aResult['importance']);
$iCountWords = 0;
$sAddress = $aResult['langaddress'];
foreach ($aRecheckWords as $i => $sWord) {
// - number of exact matches from the query
if (isset($this->exactMatchCache[$aResult['place_id']])) {
$aResult['foundorder'] -= $this->exactMatchCache[$aResult['place_id']];
- } else if (isset($this->exactMatchCache[$aResult['parent_place_id']])) {
+ } elseif (isset($this->exactMatchCache[$aResult['parent_place_id']])) {
$aResult['foundorder'] -= $this->exactMatchCache[$aResult['parent_place_id']];
}
// - importance of the class/type
$bFirst = false;
}
if (!$this->bDeDupe || (!isset($aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']])
- && !isset($aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['type'].$aResult['name'].$aResult['admin_level']]))
+ && !isset($aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['type'].$aResult['name'].$aResult['admin_level']]))
) {
$aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']] = true;
$aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['type'].$aResult['name'].$aResult['admin_level']] = true;
{
private $aParams;
- function __construct($aParams=NULL)
+ function __construct($aParams = NULL)
{
$this->aParams = ($aParams === NULL) ? $_GET : $aParams;
}
- function getBool($sName, $bDefault=false)
+ function getBool($sName, $bDefault = false)
{
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
return $bDefault;
return (bool) $this->aParams[$sName];
}
- function getInt($sName, $bDefault=false)
+ function getInt($sName, $bDefault = false)
{
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
return $bDefault;
return (int) $this->aParams[$sName];
}
- function getFloat($sName, $bDefault=false)
+ function getFloat($sName, $bDefault = false)
{
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
return $bDefault;
return (float) $this->aParams[$sName];
}
- function getString($sName, $bDefault=false)
+ function getString($sName, $bDefault = false)
{
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
return $bDefault;
return $this->aParams[$sName];
}
- function getSet($sName, $aValues, $sDefault=false)
+ function getSet($sName, $aValues, $sDefault = false)
{
if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) {
return $sDefault;
return $this->aParams[$sName];
}
- function getStringList($sName, $aDefault=false)
+ function getStringList($sName, $aDefault = false)
{
$sValue = $this->getString($sName);
return $aDefault;
}
- function getPreferredLanguages($sFallback=NULL)
+ function getPreferredLanguages($sFallback = NULL)
{
if ($sFallback === NULL && isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
$sFallback = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
{
if (!$iPlaceID) return null;
- $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted", $this->aLangPrefOrder))."]";
+ $sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $this->aLangPrefOrder))."]";
$bIsTiger = CONST_Use_US_Tiger_Data && $sType == 'tiger';
$bIsInterpolation = $sType == 'interpolation';
$sSQL .= " WHEN interpolationtype='all' THEN (".$fInterpolFraction."*(endnumber-startnumber)+startnumber)::int";
$sSQL .= " END as housenumber";
$sSQL .= " from location_property_tiger where place_id = ".$iPlaceID.") as blub1) as blub2";
- } else if ($bIsInterpolation) {
+ } elseif ($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 .= " 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, ";
if ($this->bAddressDetails) {
// to get addressdetails for tiger data, the housenumber is needed
$iHousenumber = ($bIsTiger || $bIsInterpolation) ? $aPlace['housenumber'] : -1;
- $aPlace['aAddress'] = $this->getAddressNames($aPlace['place_id'],
- $iHousenumber);
+ $aPlace['aAddress'] = $this->getAddressNames($aPlace['place_id'], $iHousenumber);
}
if ($this->bExtraTags) {
function getAddressDetails($iPlaceID, $bAll = false, $housenumber = -1)
{
- $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted", $this->aLangPrefOrder))."]";
+ $sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $this->aLangPrefOrder))."]";
$sSQL = "select *,get_name_by_language(name,$sLanguagePrefArraySQL) as localname from get_addressdata(".$iPlaceID.",".$housenumber.")";
if (!$bAll) $sSQL .= " WHERE isaddress OR type = 'country_code'";
}
if ($aTypeLabel && ((isset($aLine['localname']) && $aLine['localname']) || (isset($aLine['housenumber']) && $aLine['housenumber']))) {
$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') {
$aAddress[$sTypeLabel] = $aLine['localname']?$aLine['localname']:$aLine['housenumber'];
}
// astext
// lat
// lon
- function getOutlines($iPlaceID, $fLon=null, $fLat=null, $fRadius=null)
+ function getOutlines($iPlaceID, $fLon = null, $fLat = null, $fRadius = null)
{
$aOutlineResult = array();
$sSQL .= $sFrom;
}
- $aPointPolygon = chksql($this->oDB->getRow($sSQL),
- "Could not get outline");
+ $aPointPolygon = chksql($this->oDB->getRow($sSQL), "Could not get outline");
if ($aPointPolygon['place_id']) {
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) {
$sSQL .= ' OR ST_DWithin('.$sPointSQL.', centroid, '.$fSearchDiam.'))';
$sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', geometry) ASC limit 1';
if (CONST_Debug) var_dump($sSQL);
- $aPlace = chksql($this->oDB->getRow($sSQL),
- "Could not determine closest place.");
+ $aPlace = chksql(
+ $this->oDB->getRow($sSQL),
+ "Could not determine closest place."
+ );
$iPlaceID = $aPlace['place_id'];
$iParentPlaceID = $aPlace['parent_place_id'];
$bIsInUnitedStates = ($aPlace['calculated_country_code'] == 'us');
echo $i['housenumber'] . ' | ' . $i['distance'] * 1000 . ' | ' . $i['lat'] . ' | ' . $i['lon']. ' | '. "<br>\n";
}
}
- $aPlaceLine = chksql($this->oDB->getRow($sSQL),
- "Could not determine closest housenumber on an osm interpolation line.");
+ $aPlaceLine = chksql(
+ $this->oDB->getRow($sSQL),
+ "Could not determine closest housenumber on an osm interpolation line."
+ );
if ($aPlaceLine) {
if (CONST_Debug) var_dump('found housenumber in interpolation lines table', $aPlaceLine);
if ($aPlace['rank_search'] == 30) {
// if the placex house or the interpolated house are closer to the searched point
// distance between point and placex house
$sSQL = 'SELECT ST_distance('.$sPointSQL.', house.geometry) as distance FROM placex as house WHERE house.place_id='.$iPlaceID;
- $aDistancePlacex = chksql($this->oDB->getRow($sSQL),
- "Could not determine distance between searched point and placex house.");
+ $aDistancePlacex = chksql(
+ $this->oDB->getRow($sSQL),
+ "Could not determine distance between searched point and placex house."
+ );
$fDistancePlacex = $aDistancePlacex['distance'];
// distance between point and interpolated house (fraction on interpolation line)
$sSQL = 'SELECT ST_distance('.$sPointSQL.', ST_LineInterpolatePoint(linegeo, '.$aPlaceLine['fraction'].')) as distance';
$sSQL .= ' FROM location_property_osmline WHERE place_id = '.$aPlaceLine['place_id'];
- $aDistanceInterpolation = chksql($this->oDB->getRow($sSQL),
- "Could not determine distance between searched point and interpolated house.");
+ $aDistanceInterpolation = chksql(
+ $this->oDB->getRow($sSQL),
+ "Could not determine distance between searched point and interpolated house."
+ );
$fDistanceInterpolation = $aDistanceInterpolation['distance'];
if ($fDistanceInterpolation < $fDistancePlacex) {
// interpolation is closer to point than placex house
}
}
- $aPlaceTiger = chksql($this->oDB->getRow($sSQL),
- "Could not determine closest Tiger place.");
+ $aPlaceTiger = chksql(
+ $this->oDB->getRow($sSQL),
+ "Could not determine closest Tiger place."
+ );
if ($aPlaceTiger) {
if (CONST_Debug) var_dump('found Tiger housenumber', $aPlaceTiger);
$bPlaceIsTiger = true;
$sSQL .= " WHERE place_id = $iPlaceID";
$sSQL .= " ORDER BY abs(cached_rank_address - $iMaxRank) asc,cached_rank_address desc,isaddress desc,distance desc";
$sSQL .= ' LIMIT 1';
- $iPlaceID = chksql($this->oDB->getOne($sSQL),
- "Could not get parent for place.");
+ $iPlaceID = chksql($this->oDB->getOne($sSQL), "Could not get parent for place.");
if (!$iPlaceID) {
$iPlaceID = $aPlace['place_id'];
}
$aNames = array();
if ($aLine[1]) $aNames[] = '-'.$aLine[1];
if ($aLine[0]) $aNames[] = '--'.$aLine[0];
- $sName = join(', ',$aNames);
- echo ' '.$sName.str_repeat(' ',30-strlen($sName)).$aLine[7]."\n";
+ $sName = join(', ', $aNames);
+ echo ' '.$sName.str_repeat(' ', 30-strlen($sName)).$aLine[7]."\n";
} else {
echo $aLine."\n";
}
function &getDB($bNew = false, $bPersistent = false)
{
// Get the database object
- $oDB = chksql(DB::connect(CONST_Database_DSN.($bNew?'?new_link=true':''), $bPersistent),
- "Failed to establish database connection");
+ $oDB = chksql(
+ DB::connect(CONST_Database_DSN.($bNew?'?new_link=true':''), $bPersistent),
+ "Failed to establish database connection"
+ );
$oDB->setFetchMode(DB_FETCHMODE_ASSOC);
$oDB->query("SET DateStyle TO 'sql,european'");
$oDB->query("SET client_encoding TO 'utf-8'");
function getWordSets($aWords, $iDepth)
{
- $aResult = array(array(join(' ',$aWords)));
+ $aResult = array(array(join(' ', $aWords)));
$sFirstToken = '';
if ($iDepth < 8) {
while (sizeof($aWords) > 1) {
$sFirstToken .= ($sFirstToken?' ':'').$sWord;
$aRest = getWordSets($aWords, $iDepth+1);
foreach ($aRest as $aSet) {
- $aResult[] = array_merge(array($sFirstToken),$aSet);
+ $aResult[] = array_merge(array($sFirstToken), $aSet);
}
}
}
function getInverseWordSets($aWords, $iDepth)
{
- $aResult = array(array(join(' ',$aWords)));
+ $aResult = array(array(join(' ', $aWords)));
$sFirstToken = '';
if ($iDepth < 8) {
while (sizeof($aWords) > 1) {
$sFirstToken = $sWord.($sFirstToken?' ':'').$sFirstToken;
$aRest = getInverseWordSets($aWords, $iDepth+1);
foreach ($aRest as $aSet) {
- $aResult[] = array_merge(array($sFirstToken),$aSet);
+ $aResult[] = array_merge(array($sFirstToken), $aSet);
}
}
}
) {
$fDiameter = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter'];
} elseif (isset($aResult['class'])
- && isset($aResult['type'])
- && isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
- && $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']
+ && isset($aResult['type'])
+ && isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
+ && $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']
) {
$fDiameter = $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'];
}
header("Content-Type: application/json; charset=UTF-8");
echo $jsonout;
} 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");
echo $_GET['json_callback'].'('.$jsonout.')';
} else {
}
if ($aTypeLabel && ((isset($aLine['localname']) && $aLine['localname']) || (isset($aLine['housenumber']) && $aLine['housenumber']))) {
$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') {
$aAddress[$sTypeLabel] = $aLine['localname']?$aLine['localname']:$aLine['housenumber'];
}
}
// returns boolean
-function validLatLon($fLat,$fLon)
+function validLatLon($fLat, $fLon)
{
return ($fLat <= 90.1 && $fLat >= -90.1 && $fLon <= 180.1 && $fLon >= -180.1);
}
}
$hLog = array(
- date('Y-m-d H:i:s',$aStartTime[0]).'.'.$aStartTime[1],
+ date('Y-m-d H:i:s', $aStartTime[0]).'.'.$aStartTime[1],
$_SERVER["REMOTE_ADDR"],
$_SERVER['QUERY_STRING'],
$sOutQuery,
else $sUserAgent = '';
$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 .= ','.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]).')';
$oDB->query($sSQL);
}
if (CONST_Log_DB) {
$aEndTime = explode('.', $fEndTime);
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];
$sSQL = 'update new_query_log set endtime = '.getDBQuoted($sEndTime).', results = '.$iNumResults;
$sSQL .= ' where starttime = '.getDBQuoted($hLog[0]);
}
if (CONST_Log_File) {
- $aOutdata = sprintf("[%s] %.4f %d %s \"%s\"\n",
- $hLog[0], $fEndTime-$hLog[5], $iNumResults,
- $hLog[4], $hLog[2]);
+ $aOutdata = sprintf(
+ "[%s] %.4f %d %s \"%s\"\n",
+ $hLog[0],
+ $fEndTime-$hLog[5],
+ $iNumResults,
+ $hLog[4],
+ $hLog[2]
+ );
file_put_contents(CONST_Log_File, $aOutdata, FILE_APPEND | LOCK_EX);
}
<?php
-function formatOSMType($sType, $bIncludeExternal=true)
+function formatOSMType($sType, $bIncludeExternal = true)
{
if ($sType == 'N') return 'node';
if ($sType == 'W') return 'way';
return '';
}
-function osmLink($aFeature, $sRefText=false)
+function osmLink($aFeature, $sRefText = false)
{
$sOSMType = formatOSMType($aFeature['osm_type'], false);
if ($sOSMType) {
function wikipediaLink($aFeature)
{
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 '';
}
-function detailsLink($aFeature, $sTitle=false)
+function detailsLink($aFeature, $sTitle = false)
{
if (!$aFeature['place_id']) return '';
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", "", "", "", "", "", "");
foreach ($aBlocks as $sKey => $aDetails) {
- printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", $sKey, $aDetails['totalBlocks'],
- (int)$aDetails['currentBucketSize'], $aDetails['currentlyBlocked']?'Y':'N',
- date("r", $aDetails['lastBlockTimestamp']), $aDetails['isSleeping']?'Y':'N');
+ printf(
+ " %-40s | %12s | %7s | %13s | %31s | %8s\n",
+ $sKey,
+ $aDetails['totalBlocks'],
+ (int)$aDetails['currentBucketSize'],
+ $aDetails['currentlyBlocked']?'Y':'N',
+ date("r", $aDetails['lastBlockTimestamp']),
+ $aDetails['isSleeping']?'Y':'N'
+ );
}
echo "\n";
}
foreach ($aLanguages as $i => $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";
}
}
}
$oDB->query($sSQL);
}
-function degreesAndMinutesToDecimal($iDegrees, $iMinutes=0, $fSeconds=0, $sNSEW='N')
+function degreesAndMinutesToDecimal($iDegrees, $iMinutes = 0, $fSeconds = 0, $sNSEW = 'N')
{
$sNSEW = strtoupper($sNSEW);
return ($sNSEW == 'S' || $sNSEW == 'W'?-1:1) * ((float)$iDegrees + (float)$iMinutes/60 + (float)$fSeconds/3600);
if (!isset($aPageProperties['sWebsite']) && isset($aParams['website']) && $aParams['website']) {
if (preg_match('#^\\[?([^ \\]]+)[^\\]]*\\]?$#', $aParams['website'], $aMatch)) {
$aPageProperties['sWebsite'] = $aMatch[1];
- if (strpos($aPageProperties['sWebsite'],':/'.'/') === FALSE) {
+ if (strpos($aPageProperties['sWebsite'], ':/'.'/') === FALSE) {
$aPageProperties['sWebsite'] = 'http:/'.'/'.$aPageProperties['sWebsite'];
}
}
}
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') {
- $aPageProperties['sInfoboxType'] = trim(substr($aTemplate[0],8));
+ if (!isset($aPageProperties['sInfoboxType']) && strtolower(substr($aTemplate[0], 0, 7)) == 'infobox') {
+ $aPageProperties['sInfoboxType'] = trim(substr($aTemplate[0], 8));
// $aPageProperties['aInfoboxParams'] = $aParams;
}
} 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['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')) {
+ } elseif (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['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])) {
+ } elseif (isset($aParams[0]) && is_numeric($aParams[0]) && isset($aParams[1]) && is_numeric($aParams[1])) {
$aPageProperties['fLat'] = (float)$aParams[0];
$aPageProperties['fLon'] = (float)$aParams[1];
}
}
if (isset($aParams['Latitude']) && isset($aParams['Longitude'])) {
- $aParams['Latitude'] = str_replace(' ',' ',$aParams['Latitude']);
- $aParams['Longitude'] = str_replace(' ',' ',$aParams['Longitude']);
+ $aParams['Latitude'] = str_replace(' ', ' ', $aParams['Latitude']);
+ $aParams['Longitude'] = str_replace(' ', ' ', $aParams['Longitude']);
if (preg_match('#^([0-9]+)°( ([0-9]+)′)? ([NS]) to ([0-9]+)°( ([0-9]+)′)? ([NS])#', $aParams['Latitude'], $aMatch)) {
$aPageProperties['fLat'] =
(degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4])
+degreesAndMinutesToDecimal($aMatch[5], $aMatch[7], 0, $aMatch[8])) / 2;
- } else if (preg_match('#^([0-9]+)°( ([0-9]+)′)? ([NS])#', $aParams['Latitude'], $aMatch)) {
+ } elseif (preg_match('#^([0-9]+)°( ([0-9]+)′)? ([NS])#', $aParams['Latitude'], $aMatch)) {
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]);
}
$aPageProperties['fLon'] =
(degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4])
+degreesAndMinutesToDecimal($aMatch[5], $aMatch[7], 0, $aMatch[8])) / 2;
- } else if (preg_match('#^([0-9]+)°( ([0-9]+)′)? ([EW])#', $aParams['Longitude'], $aMatch)) {
+ } elseif (preg_match('#^([0-9]+)°( ([0-9]+)′)? ([EW])#', $aParams['Longitude'], $aMatch)) {
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]);
}
}
$aP = _templatesToProperties(_parseWikipediaContent($sPageText));
if (isset($aP['sInfoboxType'])) {
- $aP['sInfoboxType'] = preg_replace('#\\s+#',' ',$aP['sInfoboxType']);
+ $aP['sInfoboxType'] = preg_replace('#\\s+#', ' ', $aP['sInfoboxType']);
$sSQL = 'update wikipedia_article set ';
$sSQL .= 'infobox_type = \''.pg_escape_string($aP['sInfoboxType']).'\'';
$sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';';
$sNominatimBaseURL = 'http://SEVERNAME/search.php';
foreach ($aWikiArticles as $aRecord) {
- $aRecord['name'] = str_replace('_',' ',$aRecord['title']);
+ $aRecord['name'] = str_replace('_', ' ', $aRecord['title']);
$sURL = $sNominatimBaseURL.'?format=xml&accept-language=en';
$sURL .= "&viewbox=".($aRecord['lon']-$fMaxDist).",".($aRecord['lat']+$fMaxDist).",".($aRecord['lon']+$fMaxDist).",".($aRecord['lat']-$fMaxDist);
break;
case 'prefecture japan':
- $aRecord['name'] = trim(str_replace(' Prefecture',' ', $aRecord['name']));
+ $aRecord['name'] = trim(str_replace(' Prefecture', ' ', $aRecord['name']));
case 'state':
case '#us state':
case 'county':
xml_parser_free($hXMLParser);
if (!isset($aNominatRecords[0])) {
- $aNameParts = preg_split('#[(,]#',$aRecord['name']);
+ $aNameParts = preg_split('#[(,]#', $aRecord['name']);
if (sizeof($aNameParts) > 1) {
$sNameURL = $sURL.'&q='.urlencode(trim($aNameParts[0]));
var_Dump($sNameURL);
elseif ($iRank <= 26) $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) {
echo "-- Diff too big $fDiff (max: $fMaxDist)".$aRecord['lat'].','.$aNominatRecords[$i]['LAT'].' & '.$aRecord['lon'].','.$aNominatRecords[$i]['LON']." \n";
} else {
foreach (glob($aCMDResult['parse-tiger'].'/tl_20??_?????_edges.zip', 0) as $sImportFile) {
set_time_limit(30);
- preg_match('#([0-9]{5})_(.*)#',basename($sImportFile), $aMatch);
+ preg_match('#([0-9]{5})_(.*)#', basename($sImportFile), $aMatch);
$sCountyID = $aMatch[1];
echo "Processing ".$sCountyID."...\n";
$sUnzipCmd = "unzip -d $sTempDir $sImportFile";
echo "Tables\n";
$sTemplate = file_get_contents(CONST_BasePath.'/sql/tables.sql');
$sTemplate = str_replace('{www-user}', CONST_Database_Web_User, $sTemplate);
- $sTemplate = replace_tablespace('{ts:address-data}',
- CONST_Tablespace_Address_Data, $sTemplate);
- $sTemplate = replace_tablespace('{ts:address-index}',
- CONST_Tablespace_Address_Index, $sTemplate);
- $sTemplate = replace_tablespace('{ts:search-data}',
- CONST_Tablespace_Search_Data, $sTemplate);
- $sTemplate = replace_tablespace('{ts:search-index}',
- CONST_Tablespace_Search_Index, $sTemplate);
- $sTemplate = replace_tablespace('{ts:aux-data}',
- CONST_Tablespace_Aux_Data, $sTemplate);
- $sTemplate = replace_tablespace('{ts:aux-index}',
- CONST_Tablespace_Aux_Index, $sTemplate);
+ $sTemplate = replace_tablespace(
+ '{ts:address-data}',
+ CONST_Tablespace_Address_Data,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:address-index}',
+ CONST_Tablespace_Address_Index,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:search-data}',
+ CONST_Tablespace_Search_Data,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:search-index}',
+ CONST_Tablespace_Search_Index,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:aux-data}',
+ CONST_Tablespace_Aux_Data,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:aux-index}',
+ CONST_Tablespace_Aux_Index,
+ $sTemplate
+ );
pgsqlRunScript($sTemplate, false);
// re-run the functions
$bDidSomething = true;
$sTemplate = file_get_contents(CONST_BasePath.'/sql/partition-tables.src.sql');
- $sTemplate = replace_tablespace('{ts:address-data}',
- CONST_Tablespace_Address_Data, $sTemplate);
- $sTemplate = replace_tablespace('{ts:address-index}',
- CONST_Tablespace_Address_Index, $sTemplate);
- $sTemplate = replace_tablespace('{ts:search-data}',
- CONST_Tablespace_Search_Data, $sTemplate);
- $sTemplate = replace_tablespace('{ts:search-index}',
- CONST_Tablespace_Search_Index, $sTemplate);
- $sTemplate = replace_tablespace('{ts:aux-data}',
- CONST_Tablespace_Aux_Data, $sTemplate);
- $sTemplate = replace_tablespace('{ts:aux-index}',
- CONST_Tablespace_Aux_Index, $sTemplate);
+ $sTemplate = replace_tablespace(
+ '{ts:address-data}',
+ CONST_Tablespace_Address_Data,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:address-index}',
+ CONST_Tablespace_Address_Index,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:search-data}',
+ CONST_Tablespace_Search_Data,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:search-index}',
+ CONST_Tablespace_Search_Index,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:aux-data}',
+ CONST_Tablespace_Aux_Data,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:aux-index}',
+ CONST_Tablespace_Aux_Index,
+ $sTemplate
+ );
pgsqlRunPartitionScript($sTemplate);
}
$sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_start.sql');
$sTemplate = str_replace('{www-user}', CONST_Database_Web_User, $sTemplate);
- $sTemplate = replace_tablespace('{ts:aux-data}',
- CONST_Tablespace_Aux_Data, $sTemplate);
- $sTemplate = replace_tablespace('{ts:aux-index}',
- CONST_Tablespace_Aux_Index, $sTemplate);
+ $sTemplate = replace_tablespace(
+ '{ts:aux-data}',
+ CONST_Tablespace_Aux_Data,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:aux-index}',
+ CONST_Tablespace_Aux_Index,
+ $sTemplate
+ );
pgsqlRunScript($sTemplate, false);
$aDBInstances = array();
echo "Creating indexes\n";
$sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_finish.sql');
$sTemplate = str_replace('{www-user}', CONST_Database_Web_User, $sTemplate);
- $sTemplate = replace_tablespace('{ts:aux-data}',
- CONST_Tablespace_Aux_Data, $sTemplate);
- $sTemplate = replace_tablespace('{ts:aux-index}',
- CONST_Tablespace_Aux_Index, $sTemplate);
+ $sTemplate = replace_tablespace(
+ '{ts:aux-data}',
+ CONST_Tablespace_Aux_Data,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:aux-index}',
+ CONST_Tablespace_Aux_Index,
+ $sTemplate
+ );
pgsqlRunScript($sTemplate, false);
}
$bDidSomething = true;
$sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql');
- $sTemplate = replace_tablespace('{ts:address-index}',
- CONST_Tablespace_Address_Index, $sTemplate);
- $sTemplate = replace_tablespace('{ts:search-index}',
- CONST_Tablespace_Search_Index, $sTemplate);
- $sTemplate = replace_tablespace('{ts:aux-index}',
- CONST_Tablespace_Aux_Index, $sTemplate);
+ $sTemplate = replace_tablespace(
+ '{ts:address-index}',
+ CONST_Tablespace_Address_Index,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:search-index}',
+ CONST_Tablespace_Search_Index,
+ $sTemplate
+ );
+ $sTemplate = replace_tablespace(
+ '{ts:aux-index}',
+ CONST_Tablespace_Aux_Index,
+ $sTemplate
+ );
pgsqlRunScript($sTemplate);
}
function replace_tablespace($sTemplate, $sTablespace, $sSql)
{
if ($sTablespace) {
- $sSql = str_replace($sTemplate, 'TABLESPACE "'.$sTablespace.'"',
- $sSql);
+ $sSql = str_replace($sTemplate, 'TABLESPACE "'.$sTablespace.'"', $sSql);
} else {
$sSql = str_replace($sTemplate, '', $sSql);
}
# quotes into the wiki
$sType = preg_replace('/"/', '', $sType);
# sanity check, in case somebody added garbage in the wiki
- if (preg_match('/^\\w+$/', $sClass) < 1 ||
- preg_match('/^\\w+$/', $sType) < 1) {
+ if (preg_match('/^\\w+$/', $sClass) < 1
+ || preg_match('/^\\w+$/', $sType) < 1
+ ) {
trigger_error("Bad class/type for language $sLanguage: $sClass=$sType");
exit;
}
}
$iFileSize = filesize($sImportFile);
$sBatchEnd = getosmosistimestamp($sOsmosisConfigDirectory);
- $sSQL = "INSERT INTO import_osmosis_log values ('$sBatchEnd',$iFileSize,'".date('Y-m-d H:i:s',$fCMDStartTime)."','".date('Y-m-d H:i:s')."','osmosis')";
+ $sSQL = "INSERT INTO import_osmosis_log values ('$sBatchEnd',$iFileSize,'".date('Y-m-d H:i:s', $fCMDStartTime)."','".date('Y-m-d H:i:s')."','osmosis')";
var_Dump($sSQL);
$oDB->query($sSQL);
- echo date('Y-m-d H:i:s')." Completed osmosis step for $sBatchEnd in ".round((time()-$fCMDStartTime)/60,2)." minutes\n";
+ echo date('Y-m-d H:i:s')." Completed osmosis step for $sBatchEnd in ".round((time()-$fCMDStartTime)/60, 2)." minutes\n";
}
$iFileSize = filesize($sImportFile);
echo "Error: $iErrorLevel\n";
exit($iErrorLevel);
}
- $sSQL = "INSERT INTO import_osmosis_log values ('$sBatchEnd',$iFileSize,'".date('Y-m-d H:i:s',$fCMDStartTime)."','".date('Y-m-d H:i:s')."','osm2pgsql')";
+ $sSQL = "INSERT INTO import_osmosis_log values ('$sBatchEnd',$iFileSize,'".date('Y-m-d H:i:s', $fCMDStartTime)."','".date('Y-m-d H:i:s')."','osm2pgsql')";
var_Dump($sSQL);
$oDB->query($sSQL);
- echo date('Y-m-d H:i:s')." Completed osm2pgsql step for $sBatchEnd in ".round((time()-$fCMDStartTime)/60,2)." minutes\n";
+ echo date('Y-m-d H:i:s')." Completed osm2pgsql step for $sBatchEnd in ".round((time()-$fCMDStartTime)/60, 2)." minutes\n";
// Archive for debug?
unlink($sImportFile);
}
}
- $sSQL = "INSERT INTO import_osmosis_log values ('$sBatchEnd',$iFileSize,'".date('Y-m-d H:i:s',$fCMDStartTime)."','".date('Y-m-d H:i:s')."','index')";
+ $sSQL = "INSERT INTO import_osmosis_log values ('$sBatchEnd',$iFileSize,'".date('Y-m-d H:i:s', $fCMDStartTime)."','".date('Y-m-d H:i:s')."','index')";
var_Dump($sSQL);
$oDB->query($sSQL);
- echo date('Y-m-d H:i:s')." Completed index step for $sBatchEnd in ".round((time()-$fCMDStartTime)/60,2)." minutes\n";
+ echo date('Y-m-d H:i:s')." Completed index step for $sBatchEnd in ".round((time()-$fCMDStartTime)/60, 2)." minutes\n";
$sSQL = "update import_status set lastimportdate = '$sBatchEnd'";
$oDB->query($sSQL);
$fDuration = time() - $fStartTime;
- 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 (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 {
- $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";
sleep($iSleep);
{
$sStateFile = file_get_contents($sOsmosisConfigDirectory.'/state.txt');
preg_match('#timestamp=(.+)#', $sStateFile, $aResult);
- return str_replace('\:',':',$aResult[1]);
+ return str_replace('\:', ':', $aResult[1]);
}
if ($bVerbose) echo "$fLat, $fLon = ";
$aLookup = $oReverseGeocode->lookup($fLat, $fLon);
if ($aLookup && $aLookup['place_id']) {
- $aDetails = $oPlaceLookup->lookup((int)$aLookup['place_id'],
- $aLookup['type'], $aLookup['fraction']);
+ $aDetails = $oPlaceLookup->lookup(
+ (int)$aLookup['place_id'],
+ $aLookup['type'],
+ $aLookup['fraction']
+ );
if ($bVerbose) echo $aDetails['langaddress']."\n";
} else {
echo ".";
$oDB =& getDB();
$sSQL = "select placex.place_id, calculated_country_code as country_code, name->'name' as name, i.* from placex, import_polygon_delete i where placex.osm_id = i.osm_id and placex.osm_type = i.osm_type and placex.class = i.class and placex.type = i.type";
- $aPolygons = chksql($oDB->getAll($sSQL),
- "Could not get list of deleted OSM elements.");
+ $aPolygons = chksql($oDB->getAll($sSQL), "Could not get list of deleted OSM elements.");
if (CONST_DEBUG) {
var_dump($aPolygons);
$sOutputFormat = 'html';
$aLangPrefOrder = $oParams->getPreferredLanguages();
-$sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
+$sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $aLangPrefOrder))."]";
$sPlaceId = $oParams->getString('place_id');
$sOsmType = $oParams->getSet('osmtype', array('N', 'W', 'R'));
$sSQL .= " case when importance = 0 OR importance IS NULL then 0.75-(rank_search::float/40) else importance end as calculated_importance, ";
$sSQL .= " ST_AsText(CASE WHEN ST_NPoints(geometry) > 5000 THEN ST_SimplifyPreserveTopology(geometry, 0.0001) ELSE geometry END) as outlinestring";
$sSQL .= " from placex where place_id = $iPlaceID";
-$aPointDetails = chksql($oDB->getRow($sSQL),
- "Could not get details of place object.");
+$aPointDetails = chksql($oDB->getRow($sSQL), "Could not get details of place object.");
$aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber'];
$aClassType = getClassTypesWithImportance();
$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);
if (PEAR::isError($aPlaceSearchNameKeywords)) { // possible timeout
$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);
if (PEAR::isError($aPlaceSearchAddressKeywords)) { // possible timeout
$aPlaceSearchAddressKeywords = [];
$sOutputFormat = $oParams->getSet('format', array('html', 'json'), 'html');
$aLangPrefOrder = $oParams->getPreferredLanguages();
-$sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
+$sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $aLangPrefOrder))."]";
$sPlaceId = $oParams->getString('place_id');
$sOsmType = $oParams->getSet('osmtype', array('N', 'W', 'R'));
$sSQL = "select obj.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, st_area(geometry) as area, ";
$sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength ";
$sSQL .= " from (select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name from placex ";
-$sSQL .= " where parent_place_id in (".join(',',$aRelatedPlaceIDs).") and name is not null order by rank_address asc,rank_search asc limit 500) as obj";
+$sSQL .= " where parent_place_id in (".join(',', $aRelatedPlaceIDs).") and name is not null order by rank_address asc,rank_search asc limit 500) as obj";
$sSQL .= " order by rank_address asc,rank_search asc,localname,class, type,housenumber";
$aParentOfLines = chksql($oDB->getAll($sSQL));
$aGroupedAddressLines = array();
foreach ($aParentOfLines as $aAddressLine) {
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'];
} 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'];
} else $aAddressLine['label'] = ucwords($aAddressLine['type']);
if (CONST_Debug) exit;
$sXmlRootTag = 'lookupresults';
-$sQuery = join(',',$aCleanedQueryParts);
+$sQuery = join(',', $aCleanedQueryParts);
// we initialize these to avoid warnings in our logfile
$sViewBox = '';
$bShowPolygons = '';
foreach ($aRow as $sCol => $sVal) {
switch ($sCol) {
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['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:' ')."</a></td>";
$bAsKML = $oParams->getBool('polygon_kml');
$bAsSVG = $oParams->getBool('polygon_svg');
$bAsText = $oParams->getBool('polygon_text');
-if ((($bAsGeoJSON?1:0) + ($bAsKML?1:0) + ($bAsSVG?1:0)
- + ($bAsText?1:0)) > CONST_PolygonOutput_MaximumTypes
-) {
+
+$iWantedTypes = ($bAsGeoJSON?1:0) + ($bAsKML?1:0) + ($bAsSVG?1:0) + ($bAsText?1:0);
+if ($iWantedTypes > CONST_PolygonOutput_MaximumTypes) {
if (CONST_PolygonOutput_MaximumTypes) {
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
} else {
$fLon = $oParams->getFloat('lon');
if ($sOsmType && $iOsmId > 0) {
$aPlace = $oPlaceLookup->lookupOSMID($sOsmType, $iOsmId);
-} else if ($fLat !== false && $fLon !== false) {
+} elseif ($fLat !== false && $fLon !== false) {
$oReverseGeocode = new ReverseGeocode($oDB);
$oReverseGeocode->setZoom($oParams->getInt('zoom', 18));
$aLookup = $oReverseGeocode->lookup($fLat, $fLon);
if (CONST_Debug) var_dump($aLookup);
- $aPlace = $oPlaceLookup->lookup((int)$aLookup['place_id'],
- $aLookup['type'], $aLookup['fraction']);
-} else if ($sOutputFormat != 'html') {
+ $aPlace = $oPlaceLookup->lookup(
+ (int)$aLookup['place_id'],
+ $aLookup['type'],
+ $aLookup['fraction']
+ );
+} elseif ($sOutputFormat != 'html') {
userError("Need coordinates or OSM object to lookup.");
}
$oPlaceLookup->setPolygonSimplificationThreshold($fThreshold);
$fRadius = $fDiameter = getResultDiameter($aPlace);
- $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'],
- $aPlace['lon'], $aPlace['lat'],
- $fRadius);
+ $aOutlineResult = $oPlaceLookup->getOutlines(
+ $aPlace['place_id'],
+ $aPlace['lon'],
+ $aPlace['lat'],
+ $fRadius
+ );
if ($aOutlineResult) {
$aPlace = array_merge($aPlace, $aOutlineResult);
$bAsKML = $oParams->getBool('polygon_kml');
$bAsSVG = $oParams->getBool('polygon_svg');
$bAsText = $oParams->getBool('polygon_text');
- if (( ($bAsGeoJSON?1:0)
- + ($bAsKML?1:0)
- + ($bAsSVG?1:0)
- + ($bAsText?1:0)
- + ($bAsPoints?1:0)
- ) > CONST_PolygonOutput_MaximumTypes
- ) {
+ $iWantedTypes = ($bAsGeoJSON?1:0) + ($bAsKML?1:0) + ($bAsSVG?1:0) + ($bAsText?1:0) + ($bAsPoints?1:0);
+ if ($iWantedTypes > CONST_PolygonOutput_MaximumTypes) {
if (CONST_PolygonOutput_MaximumTypes) {
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
} else {
$oGeocode->setQueryFromParams($oParams);
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);
// reverse order of '/' separated string
$aPhrases = explode('/', $sQuery);
$aPhrases = array_reverse($aPhrases);
- $sQuery = join(', ',$aPhrases);
+ $sQuery = join(', ', $aPhrases);
$oGeocode->setQuery($sQuery);
}
$bShowPolygons = (isset($_GET['polygon']) && $_GET['polygon']);
$aExcludePlaceIDs = $oGeocode->getExcludedPlaceIDs();
-$sMoreURL = CONST_Website_BaseURL.'search.php?format='.urlencode($sOutputFormat).'&exclude_place_ids='.join(',',$aExcludePlaceIDs);
+$sMoreURL = CONST_Website_BaseURL.'search.php?format='.urlencode($sOutputFormat).'&exclude_place_ids='.join(',', $aExcludePlaceIDs);
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) $sMoreURL .= '&accept-language='.$_SERVER["HTTP_ACCEPT_LANGUAGE"];
if ($bShowPolygons) $sMoreURL .= '&polygon=1';
if ($oGeocode->getIncludeAddressDetails()) $sMoreURL .= '&addressdetails=1';