Skip to content

Commit

Permalink
Merge branch 'master' of github.com:twain47/Nominatim
Browse files Browse the repository at this point in the history
  • Loading branch information
twain47 committed Mar 26, 2012
2 parents b99a043 + b6db7c1 commit 80cf5df
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 76 deletions.
25 changes: 25 additions & 0 deletions lib/lib.php
@@ -1,5 +1,30 @@
<?php

function failInternalError($sError, $sSQL = false, $vDumpVar = false)
{
header('HTTP/1.0 500 Internal Server Error');
header('Content-type: text/html; charset=utf-8');
echo "<html><body><h1>Internal Server Error</h1>";
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>Feel free to report the bug in the <a href="http://trac.openstreetmap.org">OSM bug database</a>. Please include the error message above an the URL you used.</p>';
if (CONST_Debug)
{
echo "<hr><h2>Debugging Information</h2><br>";
if ($sSQL) {
echo "<h3>SQL query</h3><code>".$sSQL."</code>";
}
if ($vDumpVar) {
echo "<h3>Result</h3> <code>";
var_dump($vDumpVar);
echo "</code>";
}
}
echo "\n</body></html>\n";
exit;

}

function fail($sError, $sUserError = false)
{
if (!$sUserError) $sUserError = $sError;
Expand Down
51 changes: 51 additions & 0 deletions settings/phrase_settings.php
@@ -0,0 +1,51 @@
<?php
# These settings control the import of special phrases from the wiki.

# Languages to download the special phrases for.
$aLanguageIn = array(
'af',
'ar',
'br',
'ca',
'cs',
'de',
'en',
'es',
'et',
'eu',
'fa',
'fi',
'fr',
'gl',
'hr',
'hu',
'ia',
'is',
'it',
'ja',
'mk',
'nl',
'no',
'pl',
'ps',
'pt',
'ru',
'sk',
'sv',
'uk',
'vi',
);

# class/type combinations to exclude
$aTagsBlacklist = array(
'boundary' => array('administrative'),
'place' => array('house', 'houses'),
);
# If a class is in the white list then all types will
# be ignored except the ones given in the list.
# Also use this list to exclude an entire class from
# special phrases.
$aTagsWhitelist = array(
'highway' => array('bus_stop', 'rest_area', 'raceway'),
'building' => array(),
);
20 changes: 7 additions & 13 deletions sql/functions.sql
Expand Up @@ -1118,9 +1118,9 @@ BEGIN

-- work around bug in postgis, this may have been fixed in 2.0.0 (see http://trac.osgeo.org/postgis/ticket/547)
update placex set indexed_status = 2 where (ST_Contains(NEW.geometry, placex.geometry) OR ST_Intersects(NEW.geometry, placex.geometry))
AND rank_search > NEW.rank_search and indexed_status = 0 and ST_geometrytype(placex.geometry) = 'ST_Point';
AND rank_search > NEW.rank_search and indexed_status = 0 and ST_geometrytype(placex.geometry) = 'ST_Point' and (rank_search < 28 or name is not null);
update placex set indexed_status = 2 where (ST_Contains(NEW.geometry, placex.geometry) OR ST_Intersects(NEW.geometry, placex.geometry))
AND rank_search > NEW.rank_search and indexed_status = 0 and ST_geometrytype(placex.geometry) != 'ST_Point';
AND rank_search > NEW.rank_search and indexed_status = 0 and ST_geometrytype(placex.geometry) != 'ST_Point' and (rank_search < 28 or name is not null);
END IF;
ELSE
-- mark nearby items for re-indexing, where 'nearby' depends on the features rank_search and is a complete guess :(
Expand All @@ -1145,7 +1145,7 @@ BEGIN
END IF;
IF diameter > 0 THEN
-- RAISE WARNING 'placex point insert: % % % % %',NEW.osm_type,NEW.osm_id,NEW.class,NEW.type,diameter;
update placex set indexed_status = 2 where indexed_status = 0 and rank_search > NEW.rank_search and ST_DWithin(placex.geometry, NEW.geometry, diameter);
update placex set indexed_status = 2 where indexed_status = 0 and rank_search > NEW.rank_search and ST_DWithin(placex.geometry, NEW.geometry, diameter) and (rank_search < 28 or name is not null);
END IF;

END IF;
Expand Down Expand Up @@ -1807,12 +1807,12 @@ BEGIN
update placex set indexed_status = 2 where indexed_status = 0 and
(ST_Contains(NEW.geometry, placex.geometry) OR ST_Intersects(NEW.geometry, placex.geometry))
AND NOT (ST_Contains(existinggeometry, placex.geometry) OR ST_Intersects(existinggeometry, placex.geometry))
AND rank_search > existingplacex.rank_search;
AND rank_search > existingplacex.rank_search AND (rank_search < 28 or name is not null);

update placex set indexed_status = 2 where indexed_status = 0 and
(ST_Contains(existinggeometry, placex.geometry) OR ST_Intersects(existinggeometry, placex.geometry))
AND NOT (ST_Contains(NEW.geometry, placex.geometry) OR ST_Intersects(NEW.geometry, placex.geometry))
AND rank_search > existingplacex.rank_search;
AND rank_search > existingplacex.rank_search AND (rank_search < 28 or name is not null);

END IF;

Expand All @@ -1832,7 +1832,8 @@ BEGIN

IF st_area(NEW.geometry) < 0.5 THEN
UPDATE placex set indexed_status = 2 from place_addressline where address_place_id = existingplacex.place_id
and placex.place_id = place_addressline.place_id and indexed_status = 0;
and placex.place_id = place_addressline.place_id and indexed_status = 0
and (rank_search < 28 or name is not null);
END IF;

END IF;
Expand Down Expand Up @@ -2408,13 +2409,6 @@ END;
$$
LANGUAGE plpgsql;

CREATE AGGREGATE array_agg(INT[])
(
sfunc = array_cat,
stype = INT[],
initcond = '{}'
);

CREATE OR REPLACE FUNCTION tigger_create_interpolation(linegeo GEOMETRY, in_startnumber INTEGER,
in_endnumber INTEGER, interpolationtype TEXT,
in_street TEXT, in_isin TEXT, in_postcode TEXT) RETURNS INTEGER
Expand Down
47 changes: 13 additions & 34 deletions utils/specialphrases.php
Expand Up @@ -15,39 +15,8 @@
);
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);

$aLanguageIn = array(
'af',
'ar',
'br',
'ca',
'cs',
'de',
'en',
'es',
'et',
'eu',
'fa',
'fi',
'fr',
'gl',
'hr',
'hu',
'ia',
'is',
'it',
'ja',
'mk',
'nl',
'no',
'pl',
'ps',
'pt',
'ru',
'sk',
'sv',
'uk',
'vi',
);
include(CONST_BasePath.'/settings/phrase_settings.php');


if ($aCMDResult['countries']) {
echo "select getorcreate_country(make_standard_name('uk'), 'gb');\n";
Expand Down Expand Up @@ -84,7 +53,17 @@
preg_match('/^\\w+$/', $sType) < 1) {
trigger_error("Bad class/type for language $sLanguage: $sClass=$sType");
exit;
}
}
# blacklisting: disallow certain class/type combinations
if (isset($aTagsBlacklist[$sClass]) && in_array($sType, $aTagsBlacklist[$sClass])) {
# fwrite(STDERR, "Blacklisted: ".$sClass."/".$sType."\n");
continue;
}
# whitelisting: if class is in whitelist, allow only tags in the list
if (isset($aTagsWhitelist[$sClass]) && !in_array($sType, $aTagsWhitelist[$sClass])) {
# fwrite(STDERR, "Non-Whitelisted: ".$sClass."/".$sType."\n");
continue;
}
$aPairs[$sClass.'|'.$sType] = array($sClass, $sType);

switch(trim($aMatch[4]))
Expand Down
13 changes: 6 additions & 7 deletions website/details.php
Expand Up @@ -48,11 +48,11 @@
$sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea,ST_GeometryType(geometry) as geotype, ST_Y(ST_Centroid(geometry)) as lat,ST_X(ST_Centroid(geometry)) as lon ";
$sSQL .= " from placex where place_id = $iPlaceID";
$aPointDetails = $oDB->getRow($sSQL);
IF (PEAR::IsError($aPointDetails))
if (PEAR::IsError($aPointDetails))
{
var_dump($aPointDetails);
exit;
failInternalError("Could not get details of place object.", $sSQL, $aPointDetails);
}

$aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber'];
$fLon = $aPointDetails['lon'];
$fLat = $aPointDetails['lat'];
Expand All @@ -71,14 +71,13 @@

// Get the bounding box and outline polygon
$sSQL = "select ST_AsText(geometry) as outlinestring,";
$sSQL .= "ST_Y(ST_PointN(ExteriorRing(ST_Box2D(geometry)),4)) as minlat,ST_Y(ST_PointN(ExteriorRing(ST_Box2D(geometry)),2)) as maxlat,";
$sSQL .= "ST_X(ST_PointN(ExteriorRing(ST_Box2D(geometry)),1)) as minlon,ST_X(ST_PointN(ExteriorRing(ST_Box2D(geometry)),3)) as maxlon";
$sSQL .= "ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,";
$sSQL .= "ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon";
$sSQL .= " from placex where place_id = $iPlaceID";
$aPointPolygon = $oDB->getRow($sSQL);
IF (PEAR::IsError($aPointPolygon))
{
var_dump($aPointPolygon);
exit;
failInternalError("Could not get bounding box of place object.", $sSQL, $aPointPolygon);
}
if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$aPointPolygon['outlinestring'],$aMatch))
{
Expand Down
9 changes: 3 additions & 6 deletions website/reverse.php
Expand Up @@ -105,8 +105,7 @@
$iPlaceID = $aPlace['place_id'];
if (PEAR::IsError($iPlaceID))
{
var_Dump($sSQL, $iPlaceID);
exit;
failInternalError("Could not determine closest place.", $sSQL, $iPlaceID);
}
}

Expand All @@ -118,8 +117,7 @@
$iPlaceID = $oDB->getOne($sSQL);
if (PEAR::IsError($iPlaceID))
{
var_Dump($sSQL, $iPlaceID);
exit;
failInternalError("Could not get parent for place.", $sSQL, $iPlaceID);
}

if ($iPlaceID && $aPlace['place_id'] && $iMaxRank < 28)
Expand All @@ -129,8 +127,7 @@
$iPlaceID = $oDB->getOne($sSQL);
if (PEAR::IsError($iPlaceID))
{
var_Dump($sSQL, $iPlaceID);
exit;
failInternalError("Could not get larger parent for place.", $sSQL, $iPlaceID);
}
}
if (!$iPlaceID)
Expand Down
24 changes: 8 additions & 16 deletions website/search.php
Expand Up @@ -163,17 +163,15 @@
$sViewboxSmallSQL = $oDB->getOne($sSQL);
if (PEAR::isError($sViewboxSmallSQL))
{
var_dump($sViewboxSmallSQL);
exit;
failInternalError("Could not get small viewbox.", $sSQL, $sViewboxSmallSQL);
}
$sViewboxSmallSQL = "'".$sViewboxSmallSQL."'::geometry";

$sSQL = "select st_buffer(".$sViewboxCentreSQL.",".(float)($_GET['routewidth']/30).")";
$sViewboxLargeSQL = $oDB->getOne($sSQL);
if (PEAR::isError($sViewboxLargeSQL))
{
var_dump($sViewboxLargeSQL);
exit;
failInternalError("Could not get large viewbox.", $sSQL, $sViewboxLargeSQL);
}
$sViewboxLargeSQL = "'".$sViewboxLargeSQL."'::geometry";
}
Expand Down Expand Up @@ -325,8 +323,7 @@
$aDatabaseWords = array();
if (PEAR::IsError($aDatabaseWords))
{
var_dump($sSQL, $aDatabaseWords);
exit;
failInternalError("Could not get word tokens.", $sSQL, $aDatabaseWords);
}
$aPossibleMainWordIDs = array();
foreach($aDatabaseWords as $aToken)
Expand Down Expand Up @@ -796,8 +793,7 @@
$aViewBoxPlaceIDs = $oDB->getAll($sSQL);
if (PEAR::IsError($aViewBoxPlaceIDs))
{
var_dump($sSQL, $aViewBoxPlaceIDs);
exit;
failInternalError("Could not get places for search terms.", $sSQL, $aViewBoxPlaceIDs);
}
//var_dump($aViewBoxPlaceIDs);
// Did we have an viewbox matches?
Expand Down Expand Up @@ -978,8 +974,7 @@

if (PEAR::IsError($aPlaceIDs))
{
var_dump($sSQL, $aPlaceIDs);
exit;
failInternalError("Could not get place IDs from tokens." ,$sSQL, $aPlaceIDs);
}

if (CONST_Debug) var_Dump($aPlaceIDs);
Expand Down Expand Up @@ -1055,8 +1050,7 @@

if (PEAR::IsError($aSearchResults))
{
var_dump($sSQL, $aSearchResults);
exit;
failInternalError("Could not get details for place.", $sSQL, $aSearchResults);
}
}
} // end if ($sQuery)
Expand Down Expand Up @@ -1124,8 +1118,7 @@

if (PEAR::IsError($aSearchResults))
{
var_dump($sSQL, $aSearchResults);
exit;
failInternalError("Could not get details for place (near).", $sSQL, $aSearchResults);
}
}
}
Expand Down Expand Up @@ -1161,8 +1154,7 @@
$aPointPolygon = $oDB->getRow($sSQL);
if (PEAR::IsError($aPointPolygon))
{
var_dump($sSQL, $aPointPolygon);
exit;
failInternalError("Could not get outline.", $sSQL, $aPointPolygon);
}
if ($aPointPolygon['place_id'])
{
Expand Down

0 comments on commit 80cf5df

Please sign in to comment.