mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
Reverse geocode include geometry
This commit is contained in:
119
lib/Geocode.php
119
lib/Geocode.php
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
require_once(CONST_BasePath.'/lib/PlaceLookup.php');
|
||||
|
||||
class Geocode
|
||||
{
|
||||
protected $oDB;
|
||||
@@ -1634,87 +1636,20 @@
|
||||
foreach($aSearchResults as $iResNum => $aResult)
|
||||
{
|
||||
// Default
|
||||
$fDiameter = 0.0001;
|
||||
$fDiameter = getResultDiameter($aResult);
|
||||
|
||||
if (isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter'])
|
||||
&& $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter'])
|
||||
$oPlaceLookup = new PlaceLookup($this->oDB);
|
||||
$oPlaceLookup->setIncludePolygonAsPoints($this->bIncludePolygonAsPoints);
|
||||
$oPlaceLookup->setIncludePolygonAsText($this->bIncludePolygonAsText);
|
||||
$oPlaceLookup->setIncludePolygonAsGeoJSON($this->bIncludePolygonAsGeoJSON);
|
||||
$oPlaceLookup->setIncludePolygonAsKML($this->bIncludePolygonAsKML);
|
||||
$oPlaceLookup->setIncludePolygonAsSVG($this->bIncludePolygonAsSVG);
|
||||
$oPlaceLookup->setPolygonSimplificationThreshold($this->fPolygonSimplificationThreshold);
|
||||
|
||||
$aOutlineResult = $oPlaceLookup->getOutlines($aResult['place_id'], $aResult['lon'], $aResult['lat'], $fDiameter/2);
|
||||
foreach($aOutlineResult as $k => $v)
|
||||
{
|
||||
$fDiameter = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter'];
|
||||
}
|
||||
elseif (isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
|
||||
&& $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
|
||||
{
|
||||
$fDiameter = $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'];
|
||||
}
|
||||
$fRadius = $fDiameter / 2;
|
||||
|
||||
if (CONST_Search_AreaPolygons)
|
||||
{
|
||||
// Get the bounding box and outline polygon
|
||||
$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 = ".$aResult['place_id'];
|
||||
if ($this->fPolygonSimplificationThreshold > 0)
|
||||
{
|
||||
$sSQL .= " from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,".$this->fPolygonSimplificationThreshold.") as geometry".$sFrom.") as plx";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sSQL .= $sFrom;
|
||||
}
|
||||
|
||||
$aPointPolygon = $this->oDB->getRow($sSQL);
|
||||
if (PEAR::IsError($aPointPolygon))
|
||||
{
|
||||
failInternalError("Could not get outline.", $sSQL, $aPointPolygon);
|
||||
}
|
||||
|
||||
if ($aPointPolygon['place_id'])
|
||||
{
|
||||
if ($this->bIncludePolygonAsGeoJSON) $aResult['asgeojson'] = $aPointPolygon['asgeojson'];
|
||||
if ($this->bIncludePolygonAsKML) $aResult['askml'] = $aPointPolygon['askml'];
|
||||
if ($this->bIncludePolygonAsSVG) $aResult['assvg'] = $aPointPolygon['assvg'];
|
||||
if ($this->bIncludePolygonAsText) $aResult['astext'] = $aPointPolygon['astext'];
|
||||
|
||||
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null )
|
||||
{
|
||||
$aResult['lat'] = $aPointPolygon['centrelat'];
|
||||
$aResult['lon'] = $aPointPolygon['centrelon'];
|
||||
}
|
||||
|
||||
if ($this->bIncludePolygonAsPoints)
|
||||
{
|
||||
$aPolyPoints[] = geometryText2Points($aPointPolygon['astext'],$fRadius);
|
||||
|
||||
// Output data suitable for display (points and a bounding box)
|
||||
if (isset($aPolyPoints))
|
||||
{
|
||||
$aResult['aPolyPoints'] = array();
|
||||
foreach($aPolyPoints as $aPoint)
|
||||
{
|
||||
$aResult['aPolyPoints'][] = array($aPoint[1], $aPoint[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001)
|
||||
{
|
||||
$aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
|
||||
$aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
|
||||
}
|
||||
if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001)
|
||||
{
|
||||
$aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
|
||||
$aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
|
||||
}
|
||||
$aResult['aBoundingBox'] = array((string)$aPointPolygon['minlat'],(string)$aPointPolygon['maxlat'],(string)$aPointPolygon['minlon'],(string)$aPointPolygon['maxlon']);
|
||||
}
|
||||
$aResult[$k] = $v;
|
||||
}
|
||||
|
||||
if ($aResult['extra_place'] == 'city')
|
||||
@@ -1724,32 +1659,6 @@
|
||||
$aResult['rank_search'] = 16;
|
||||
}
|
||||
|
||||
if (!isset($aResult['aBoundingBox']))
|
||||
{
|
||||
$iSteps = max(8,min(100,$fRadius * 3.14 * 100000));
|
||||
$fStepSize = (2*pi())/$iSteps;
|
||||
$aPointPolygon['minlat'] = $aResult['lat'] - $fRadius;
|
||||
$aPointPolygon['maxlat'] = $aResult['lat'] + $fRadius;
|
||||
$aPointPolygon['minlon'] = $aResult['lon'] - $fRadius;
|
||||
$aPointPolygon['maxlon'] = $aResult['lon'] + $fRadius;
|
||||
|
||||
// Output data suitable for display (points and a bounding box)
|
||||
if ($this->bIncludePolygonAsPoints)
|
||||
{
|
||||
$aPolyPoints = array();
|
||||
for($f = 0; $f < 2*pi(); $f += $fStepSize)
|
||||
{
|
||||
$aPolyPoints[] = array('',$aResult['lon']+($fRadius*sin($f)),$aResult['lat']+($fRadius*cos($f)));
|
||||
}
|
||||
$aResult['aPolyPoints'] = array();
|
||||
foreach($aPolyPoints as $aPoint)
|
||||
{
|
||||
$aResult['aPolyPoints'][] = array($aPoint[1], $aPoint[2]);
|
||||
}
|
||||
}
|
||||
$aResult['aBoundingBox'] = array((string)$aPointPolygon['minlat'],(string)$aPointPolygon['maxlat'],(string)$aPointPolygon['minlon'],(string)$aPointPolygon['maxlon']);
|
||||
}
|
||||
|
||||
// Is there an icon set for this type of result?
|
||||
if (isset($aClassType[$aResult['class'].':'.$aResult['type']]['icon'])
|
||||
&& $aClassType[$aResult['class'].':'.$aResult['type']]['icon'])
|
||||
|
||||
@@ -15,6 +15,14 @@
|
||||
|
||||
protected $bNameDetails = false;
|
||||
|
||||
protected $bIncludePolygonAsPoints = false;
|
||||
protected $bIncludePolygonAsText = false;
|
||||
protected $bIncludePolygonAsGeoJSON = false;
|
||||
protected $bIncludePolygonAsKML = false;
|
||||
protected $bIncludePolygonAsSVG = false;
|
||||
protected $fPolygonSimplificationThreshold = 0.0;
|
||||
|
||||
|
||||
function PlaceLookup(&$oDB)
|
||||
{
|
||||
$this->oDB =& $oDB;
|
||||
@@ -46,6 +54,48 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setIncludePolygonAsPoints($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsPoints = $b;
|
||||
}
|
||||
|
||||
function getIncludePolygonAsPoints()
|
||||
{
|
||||
return $this->bIncludePolygonAsPoints;
|
||||
}
|
||||
|
||||
function setIncludePolygonAsText($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsText = $b;
|
||||
}
|
||||
|
||||
function getIncludePolygonAsText()
|
||||
{
|
||||
return $this->bIncludePolygonAsText;
|
||||
}
|
||||
|
||||
function setIncludePolygonAsGeoJSON($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsGeoJSON = $b;
|
||||
}
|
||||
|
||||
function setIncludePolygonAsKML($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsKML = $b;
|
||||
}
|
||||
|
||||
function setIncludePolygonAsSVG($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsSVG = $b;
|
||||
}
|
||||
|
||||
function setPolygonSimplificationThreshold($f)
|
||||
{
|
||||
$this->fPolygonSimplificationThreshold = $f;
|
||||
}
|
||||
|
||||
|
||||
function setPlaceID($iPlaceID)
|
||||
{
|
||||
$this->iPlaceID = $iPlaceID;
|
||||
@@ -219,5 +269,110 @@
|
||||
return $aAddress;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// returns an array which will contain the keys
|
||||
// aBoundingBox
|
||||
// and may also contain one or more of the keys
|
||||
// asgeojson
|
||||
// askml
|
||||
// assvg
|
||||
// astext
|
||||
// lat
|
||||
// lon
|
||||
function getOutlines($iPlaceID, $fLon=null, $fLat=null, $fRadius=null)
|
||||
{
|
||||
|
||||
$aOutlineResult = array();
|
||||
if (!$iPlaceID) return $aOutlineResult;
|
||||
|
||||
if (CONST_Search_AreaPolygons)
|
||||
{
|
||||
// Get the bounding box and outline polygon
|
||||
$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;
|
||||
if ($this->fPolygonSimplificationThreshold > 0)
|
||||
{
|
||||
$sSQL .= " from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,".$this->fPolygonSimplificationThreshold.") as geometry".$sFrom.") as plx";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sSQL .= $sFrom;
|
||||
}
|
||||
|
||||
$aPointPolygon = $this->oDB->getRow($sSQL);
|
||||
if (PEAR::IsError($aPointPolygon))
|
||||
{
|
||||
echo var_dump($aPointPolygon);
|
||||
failInternalError("Could not get outline.", $sSQL, $aPointPolygon);
|
||||
}
|
||||
|
||||
if ($aPointPolygon['place_id'])
|
||||
{
|
||||
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null )
|
||||
{
|
||||
$aOutlineResult['lat'] = $aPointPolygon['centrelat'];
|
||||
$aOutlineResult['lon'] = $aPointPolygon['centrelon'];
|
||||
}
|
||||
|
||||
if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson'];
|
||||
if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml'];
|
||||
if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg'];
|
||||
if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext'];
|
||||
if ($this->bIncludePolygonAsPoints) $aOutlineResult['aPolyPoints'] = geometryText2Points($aPointPolygon['astext'], $fRadius);
|
||||
|
||||
|
||||
if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001)
|
||||
{
|
||||
$aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
|
||||
$aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
|
||||
}
|
||||
if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001)
|
||||
{
|
||||
$aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
|
||||
$aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
|
||||
}
|
||||
|
||||
$aOutlineResult['aBoundingBox'] = array(
|
||||
(string)$aPointPolygon['minlat'],
|
||||
(string)$aPointPolygon['maxlat'],
|
||||
(string)$aPointPolygon['minlon'],
|
||||
(string)$aPointPolygon['maxlon']
|
||||
);
|
||||
}
|
||||
} // CONST_Search_AreaPolygons
|
||||
|
||||
// as a fallback we generate a bounding box without knowing the size of the geometry
|
||||
if ( (!isset($aOutlineResult['aBoundingBox'])) && isset($fLon) )
|
||||
{
|
||||
|
||||
if ($this->bIncludePolygonAsPoints)
|
||||
{
|
||||
$sGeometryText = 'POINT('.$fLon.','.$fLat.')';
|
||||
$aOutlineResult['aPolyPoints'] = geometryText2Points($sGeometryText, $fRadius);
|
||||
}
|
||||
|
||||
$aBounds = array();
|
||||
$aBounds['minlat'] = $fLat - $fRadius;
|
||||
$aBounds['maxlat'] = $fLat + $fRadius;
|
||||
$aBounds['minlon'] = $fLon - $fRadius;
|
||||
$aBounds['maxlon'] = $fLon + $fRadius;
|
||||
|
||||
$aOutlineResult['aBoundingBox'] = array(
|
||||
(string)$aBounds['minlat'],
|
||||
(string)$aBounds['maxlat'],
|
||||
(string)$aBounds['minlon'],
|
||||
(string)$aBounds['maxlon']
|
||||
);
|
||||
}
|
||||
return $aOutlineResult;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
|
||||
protected $aLangPrefOrder = array();
|
||||
|
||||
protected $bIncludePolygonAsPoints = false;
|
||||
protected $bIncludePolygonAsText = false;
|
||||
protected $bIncludePolygonAsGeoJSON = false;
|
||||
protected $bIncludePolygonAsKML = false;
|
||||
protected $bIncludePolygonAsSVG = false;
|
||||
protected $fPolygonSimplificationThreshold = 0.0;
|
||||
|
||||
|
||||
function ReverseGeocode(&$oDB)
|
||||
{
|
||||
$this->oDB =& $oDB;
|
||||
@@ -58,6 +66,48 @@
|
||||
$this->iMaxRank = (isset($iZoom) && isset($aZoomRank[$iZoom]))?$aZoomRank[$iZoom]:28;
|
||||
}
|
||||
|
||||
function setIncludePolygonAsPoints($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsPoints = $b;
|
||||
}
|
||||
|
||||
function getIncludePolygonAsPoints()
|
||||
{
|
||||
return $this->bIncludePolygonAsPoints;
|
||||
}
|
||||
|
||||
function setIncludePolygonAsText($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsText = $b;
|
||||
}
|
||||
|
||||
function getIncludePolygonAsText()
|
||||
{
|
||||
return $this->bIncludePolygonAsText;
|
||||
}
|
||||
|
||||
function setIncludePolygonAsGeoJSON($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsGeoJSON = $b;
|
||||
}
|
||||
|
||||
function setIncludePolygonAsKML($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsKML = $b;
|
||||
}
|
||||
|
||||
function setIncludePolygonAsSVG($b = true)
|
||||
{
|
||||
$this->bIncludePolygonAsSVG = $b;
|
||||
}
|
||||
|
||||
function setPolygonSimplificationThreshold($f)
|
||||
{
|
||||
$this->fPolygonSimplificationThreshold = $f;
|
||||
}
|
||||
|
||||
// returns { place_id =>, type => '(osm|tiger)' }
|
||||
// fails if no place was found
|
||||
function lookup()
|
||||
{
|
||||
$sPointSQL = 'ST_SetSRID(ST_Point('.$this->fLon.','.$this->fLat.'),4326)';
|
||||
@@ -86,7 +136,8 @@
|
||||
if ($fSearchDiam > 0.008 && $iMaxRank > 22) $iMaxRank = 22;
|
||||
if ($fSearchDiam > 0.001 && $iMaxRank > 26) $iMaxRank = 26;
|
||||
|
||||
$sSQL = 'select place_id,parent_place_id,rank_search,calculated_country_code from placex';
|
||||
$sSQL = 'select place_id,parent_place_id,rank_search,calculated_country_code';
|
||||
$sSQL .= ' FROM placex';
|
||||
$sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, '.$fSearchDiam.')';
|
||||
$sSQL .= ' and rank_search != 28 and rank_search >= '.$iMaxRank;
|
||||
$sSQL .= ' and (name is not null or housenumber is not null)';
|
||||
@@ -152,7 +203,11 @@
|
||||
{
|
||||
$iPlaceID = $iParentPlaceID;
|
||||
}
|
||||
$sSQL = "select address_place_id from place_addressline where place_id = $iPlaceID order by abs(cached_rank_address - $iMaxRank) asc,cached_rank_address desc,isaddress desc,distance desc limit 1";
|
||||
$sSQL = 'select address_place_id';
|
||||
$sSQL .= ' FROM place_addressline';
|
||||
$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 = $this->oDB->getOne($sSQL);
|
||||
if (PEAR::IsError($iPlaceID))
|
||||
{
|
||||
@@ -165,7 +220,8 @@
|
||||
}
|
||||
|
||||
return array('place_id' => $iPlaceID,
|
||||
'type' => $bPlaceIsTiger ? 'tiger' : 'osm');
|
||||
'type' => $bPlaceIsTiger ? 'tiger' : 'osm');
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
65
lib/lib.php
65
lib/lib.php
@@ -673,6 +673,31 @@
|
||||
return $aOrders;
|
||||
}
|
||||
|
||||
function getResultDiameter($aResult)
|
||||
{
|
||||
$aClassType = getClassTypes();
|
||||
|
||||
$fDiameter = 0.0001;
|
||||
|
||||
if (isset($aResult['class'])
|
||||
&& isset($aResult['type'])
|
||||
&& isset($aResult['admin_level'])
|
||||
&& isset($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'];
|
||||
}
|
||||
elseif (isset($aResult['class'])
|
||||
&& isset($aResult['type'])
|
||||
&& isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
|
||||
&& $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
|
||||
{
|
||||
$fDiameter = $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'];
|
||||
}
|
||||
|
||||
return $fDiameter;
|
||||
}
|
||||
|
||||
|
||||
function javascript_renderData($xVal, $iOptions = 0)
|
||||
{
|
||||
@@ -1024,27 +1049,47 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
function geometryText2Points($geometry_as_text,$fRadius)
|
||||
function geometryText2Points($geometry_as_text, $fRadius)
|
||||
{
|
||||
$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('#MULTIPOLYGON\\(\\(\\(([- 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('#POINT\\((-?[0-9.]+) (-?[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);
|
||||
}
|
||||
elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#', $geometry_as_text, $aMatch))
|
||||
{
|
||||
$aPolyPoints = createPointsAroundCenter($aMatch[1], $aMatch[2], $fRadius);
|
||||
}
|
||||
|
||||
if (isset($aPolyPoints))
|
||||
{
|
||||
$aResultPoints = array();
|
||||
foreach($aPolyPoints as $aPoint)
|
||||
{
|
||||
$aResultPoints[] = array($aPoint[1], $aPoint[2]);
|
||||
}
|
||||
return $aResultPoints;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function createPointsAroundCenter($fLon, $fLat, $fRadius)
|
||||
{
|
||||
$iSteps = max(8, min(100, ($fRadius * 40000)^2));
|
||||
$fStepSize = (2*pi())/$iSteps;
|
||||
$aPolyPoints = array();
|
||||
for($f = 0; $f < 2*pi(); $f += $fStepSize)
|
||||
{
|
||||
$aPolyPoints[] = array('',$aMatch[1]+($fRadius*sin($f)),$aMatch[2]+($fRadius*cos($f)));
|
||||
$aPolyPoints[] = array('', $fLon+($fRadius*sin($f)), $fLat+($fRadius*cos($f)) );
|
||||
}
|
||||
}
|
||||
return $aPolyPoints;
|
||||
return $aPolyPoints;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,38 @@
|
||||
if (isset($aPlace['aAddress'])) $aFilteredPlaces['address'] = $aPlace['aAddress'];
|
||||
if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags'];
|
||||
if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails'];
|
||||
|
||||
if (isset($aPlace['aBoundingBox']))
|
||||
{
|
||||
$aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox'];
|
||||
|
||||
if (isset($aPlace['aPolyPoints']) && $bAsPoints)
|
||||
{
|
||||
$aFilteredPlaces['polygonpoints'] = $aPlace['aPolyPoints'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($aPlace['asgeojson']))
|
||||
{
|
||||
$aFilteredPlaces['geojson'] = json_decode($aPlace['asgeojson']);
|
||||
}
|
||||
|
||||
if (isset($aPlace['assvg']))
|
||||
{
|
||||
$aFilteredPlaces['svg'] = $aPlace['assvg'];
|
||||
}
|
||||
|
||||
if (isset($aPlace['astext']))
|
||||
{
|
||||
$aFilteredPlaces['geotext'] = $aPlace['astext'];
|
||||
}
|
||||
|
||||
if (isset($aPlace['askml']))
|
||||
{
|
||||
$aFilteredPlaces['geokml'] = $aPlace['askml'];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
javascript_renderData($aFilteredPlaces);
|
||||
|
||||
@@ -36,6 +36,37 @@
|
||||
if (isset($aPlace['aAddress'])) $aFilteredPlaces['address'] = $aPlace['aAddress'];
|
||||
if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags'];
|
||||
if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails'];
|
||||
|
||||
if (isset($aPlace['aBoundingBox']))
|
||||
{
|
||||
$aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox'];
|
||||
|
||||
if (isset($aPlace['aPolyPoints']) && $bAsPoints)
|
||||
{
|
||||
$aFilteredPlaces['polygonpoints'] = $aPlace['aPolyPoints'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($aPlace['asgeojson']))
|
||||
{
|
||||
$aFilteredPlaces['geojson'] = json_decode($aPlace['asgeojson']);
|
||||
}
|
||||
|
||||
if (isset($aPlace['assvg']))
|
||||
{
|
||||
$aFilteredPlaces['svg'] = $aPlace['assvg'];
|
||||
}
|
||||
|
||||
if (isset($aPlace['astext']))
|
||||
{
|
||||
$aFilteredPlaces['geotext'] = $aPlace['astext'];
|
||||
}
|
||||
|
||||
if (isset($aPlace['askml']))
|
||||
{
|
||||
$aFilteredPlaces['geokml'] = $aPlace['askml'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
javascript_renderData($aFilteredPlaces);
|
||||
|
||||
@@ -27,6 +27,40 @@
|
||||
if ($aPlace['ref']) echo ' ref="'.htmlspecialchars($aPlace['ref']).'"';
|
||||
if (isset($aPlace['lat'])) echo ' lat="'.htmlspecialchars($aPlace['lat']).'"';
|
||||
if (isset($aPlace['lon'])) echo ' lon="'.htmlspecialchars($aPlace['lon']).'"';
|
||||
if (isset($aPlace['aBoundingBox']))
|
||||
{
|
||||
echo ' boundingbox="';
|
||||
echo join(',', $aPlace['aBoundingBox']);
|
||||
echo '"';
|
||||
|
||||
if ($bAsPoints && isset($aPlace['aPolyPoints']))
|
||||
{
|
||||
echo ' polygonpoints=\'';
|
||||
echo json_encode($aPlace['aPolyPoints']);
|
||||
echo '\'';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($aPlace['asgeojson']))
|
||||
{
|
||||
echo ' geojson=\'';
|
||||
echo $aPlace['asgeojson'];
|
||||
echo '\'';
|
||||
}
|
||||
|
||||
if (isset($aPlace['assvg']))
|
||||
{
|
||||
echo ' geosvg=\'';
|
||||
echo $aPlace['assvg'];
|
||||
echo '\'';
|
||||
}
|
||||
|
||||
if (isset($aPlace['astext']))
|
||||
{
|
||||
echo ' geotext=\'';
|
||||
echo $aPlace['astext'];
|
||||
echo '\'';
|
||||
}
|
||||
echo ">".htmlspecialchars($aPlace['langaddress'])."</result>";
|
||||
|
||||
if (isset($aPlace['aAddress']))
|
||||
@@ -63,6 +97,14 @@
|
||||
}
|
||||
echo "</namedetails>";
|
||||
}
|
||||
|
||||
if (isset($aPlace['askml']))
|
||||
{
|
||||
echo "\n<geokml>";
|
||||
echo $aPlace['askml'];
|
||||
echo "</geokml>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo "</reversegeocode>";
|
||||
|
||||
@@ -18,11 +18,7 @@
|
||||
|
||||
if (isset($aPointDetails['aBoundingBox']))
|
||||
{
|
||||
$aPlace['boundingbox'] = array(
|
||||
$aPointDetails['aBoundingBox'][0],
|
||||
$aPointDetails['aBoundingBox'][1],
|
||||
$aPointDetails['aBoundingBox'][2],
|
||||
$aPointDetails['aBoundingBox'][3]);
|
||||
$aPlace['boundingbox'] = $aPointDetails['aBoundingBox'][0];
|
||||
|
||||
if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons)
|
||||
{
|
||||
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
if (isset($aPointDetails['aBoundingBox']))
|
||||
{
|
||||
$aPlace['boundingbox'] = array(
|
||||
$aPointDetails['aBoundingBox'][0],
|
||||
$aPointDetails['aBoundingBox'][1],
|
||||
$aPointDetails['aBoundingBox'][2],
|
||||
$aPointDetails['aBoundingBox'][3]);
|
||||
$aPlace['boundingbox'] = $aPointDetails['aBoundingBox'];
|
||||
|
||||
if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons)
|
||||
{
|
||||
|
||||
@@ -36,10 +36,7 @@
|
||||
if (isset($aResult['aBoundingBox']))
|
||||
{
|
||||
echo ' boundingbox="';
|
||||
echo $aResult['aBoundingBox'][0];
|
||||
echo ','.$aResult['aBoundingBox'][1];
|
||||
echo ','.$aResult['aBoundingBox'][2];
|
||||
echo ','.$aResult['aBoundingBox'][3];
|
||||
echo join(',',$aResult['aBoundingBox']);
|
||||
echo '"';
|
||||
|
||||
if ($bShowPolygons && isset($aResult['aPolyPoints']))
|
||||
|
||||
Reference in New Issue
Block a user