- $sSQL = "select place_id,partition, 'T' as osm_type, place_id as osm_id, 'place' as class, 'house' as type, null as admin_level,";
- $sSQL .= $oResult->iHouseNumber.' as housenumber, postcode,';
- $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 country_code, ";
- $sSQL .= " get_address_by_language(place_id,".$oResult->iHouseNumber.", $sLanguagePrefArraySQL) as langaddress,";
- $sSQL .= " null as placename,";
- $sSQL .= " null as ref,";
- if ($this->bExtraTags) $sSQL .= " null as extra,";
- if ($this->bNameDetails) $sSQL .= " null as names,";
- $sSQL .= " ST_X(point) as lon, ST_Y(point) as lat";
- $sSQL .= " FROM (select *, ST_LineInterpolatePoint(linegeo, (".$oResult->iHouseNumber."-startnumber::float)/(endnumber-startnumber)::float) as point ";
- $sSQL .= " FROM location_property_tiger where place_id = ".$iPlaceID.") as blub";
- $sSQL = "select place_id, partition, 'W' as osm_type, osm_id, 'place' as class, 'house' as type, null admin_level,";
- $sSQL .= $oResult->iHouseNumber.' as housenumber, postcode,';
- $sSQL .= " 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, country_code, ";
- $sSQL .= " get_address_by_language(place_id,".$oResult->iHouseNumber.", $sLanguagePrefArraySQL) as langaddress,";
- $sSQL .= " null as placename,";
- $sSQL .= " null as ref,";
- if ($this->bExtraTags) $sSQL .= " null as extra,";
- if ($this->bNameDetails) $sSQL .= " null as names,";
- $sSQL .= " ST_X(point) as lon, ST_Y(point) as lat ";
- $sSQL .= " FROM (select *, ST_LineInterpolatePoint(linegeo, (".$oResult->iHouseNumber."-startnumber::float)/(endnumber-startnumber)::float) as point ";
- $sSQL .= " from location_property_osmline where place_id = ".$iPlaceID.") as blub";
- // 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)
- $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_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,";
- $sSQL .= "ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon";
- if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ",ST_AsGeoJSON(geometry) as asgeojson";
- if ($this->bIncludePolygonAsKML) $sSQL .= ",ST_AsKML(geometry) as askml";
- if ($this->bIncludePolygonAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg";
- if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ",ST_AsText(geometry) as astext";
- $sFrom = " from placex where place_id = ".$iPlaceID;
+ $sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,';
+ if ($fLonReverse != null && $fLatReverse != null) {
+ $sSQL .= ' CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN';
+ $sSQL .= ' ST_Y(closest_point)';
+ $sSQL .= ' ELSE ST_Y(centroid) ';
+ $sSQL .= ' END as centrelat, ';
+ $sSQL .= ' CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN';
+ $sSQL .= ' ST_X(closest_point)';
+ $sSQL .= ' ELSE ST_X(centroid) ';
+ $sSQL .= ' END as centrelon, ';
+ } else {
+ $sSQL .= ' ST_Y(centroid) as centrelat, ST_X(centroid) as centrelon,';
+ }
+ $sSQL .= ' ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,';
+ $sSQL .= ' ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon';
+ if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson';
+ if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml';
+ if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg';
+ if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ',ST_AsText(geometry) as astext';
+ $sFrom = ' from (SELECT * , ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326)) AS closest_point';
+ $sFrom .= ' from placex where place_id = '.$iPlaceID.') as plx';
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 {
$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) {