<?php
+ require_once(CONST_BasePath.'/lib/PlaceLookup.php');
+
class Geocode
{
protected $oDB;
if ($aSearch['sClass'] && sizeof($aPlaceIDs))
{
-- $sPlaceIDs = join(',', aPlaceIDs);
++ $sPlaceIDs = join(',', $aPlaceIDs);
$aClassPlaceIDs = array();
if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'name')
foreach($aSearchResults as $iResNum => $aResult)
{
// Default
- $fDiameter = 0.0001;
-
- if (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($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
- && $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
+ $fDiameter = getResultDiameter($aResult);
+
+ $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);
+ if ($aOutlineResult)
{
- $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 = array_merge($aResult, $aOutlineResult);
}
-
+
if ($aResult['extra_place'] == 'city')
{
$aResult['class'] = 'place';
$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'])
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;
}
}
+
+ 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;
$sSQL = "select place_id,partition, 'T' as osm_type, place_id as osm_id, 'place' as class, 'house' as type, null as admin_level, housenumber, null as street, null as isin, postcode,";
$sSQL .= " 'us' as country_code, parent_place_id, null as linked_place_id, 30 as rank_address, 30 as rank_search,";
$sSQL .= " coalesce(null,0.75-(30::float/40)) as importance, null as indexed_status, null as indexed_date, null as wikipedia, 'us' as calculated_country_code, ";
-- $sSQL .= " get_address_by_language(place_id, housenumber,$sLanguagePrefArraySQL) as langaddress,";
++ $sSQL .= " get_address_by_language(place_id, housenumber, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= " null as placename,";
$sSQL .= " null as ref,";
if ($this->bExtraTags) $sSQL .= " null as extra,";
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;
+ }
}
?>
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;
$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)';
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)';
$sSQL .= ' AND ST_DWithin('.$sPointSQL.', linegeo, '.$fSearchDiam.')'; //no centroid anymore in Tiger data, now we have lines
$sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', linegeo) ASC limit 1';
--
-- // print all house numbers in the parent (street)
-- /*if (CONST_Debug)
++ if (CONST_Debug)
{
$sSQL = preg_replace('/limit 1/', 'limit 100', $sSQL);
var_dump($sSQL);
{
echo $i['housenumber'] . ' | ' . $i['distance'] * 1000 . ' | ' . $i['lat'] . ' | ' . $i['lon']. ' | '. "<br>\n";
}
-- }*/
++ }
$aPlaceTiger = $this->oDB->getRow($sSQL);
if (PEAR::IsError($aPlace))
{
$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))
{
}
return array('place_id' => $iPlaceID,
- 'type' => $bPlaceIsTiger ? 'tiger' : 'osm');
- 'type' => $bPlaceIsTiger ? 'tiger' : 'osm',
- 'fraction' => $bPlaceIsTiger ? $iFraction : -1 );
++ 'type' => $bPlaceIsTiger ? 'tiger' : 'osm',
++ 'fraction' => $bPlaceIsTiger ? $iFraction : -1);
}
+
}
?>
<?php
- if (file_exists(CONST_BasePath.'/settings/local.php')) require_once(CONST_BasePath.'/settings/local.php');
+ @define('CONST_BasePath', '@CMAKE_SOURCE_DIR@');
+ @define('CONST_InstallPath', '@CMAKE_BINARY_DIR@');
+ if (file_exists(CONST_InstallPath.'/settings/local.php')) require_once(CONST_InstallPath.'/settings/local.php');
if (isset($_GET['debug']) && $_GET['debug']) @define('CONST_Debug', true);
// General settings
@define('CONST_Debug', false);
-- @define('CONST_Database_DSN', 'pgsql://@/nominatim'); // <driver>://<username>:<password>@<host>:<port>/<database>
++ @define('CONST_Database_DSN', 'pgsql://@/nominatim'); // <driver>://<username>:<password>@<host>:<port>/<database>
@define('CONST_Database_Web_User', 'www-data');
@define('CONST_Max_Word_Frequency', '50000');
@define('CONST_Limit_Reindexing', true);
// Paths
@define('CONST_Path_Postgresql_Contrib', '/usr/share/postgresql/'.CONST_Postgresql_Version.'/contrib');
@define('CONST_Path_Postgresql_Postgis', CONST_Path_Postgresql_Contrib.'/postgis-'.CONST_Postgis_Version);
- @define('CONST_Osm2pgsql_Binary', CONST_BasePath.'/osm2pgsql/osm2pgsql');
+ @define('CONST_Osm2pgsql_Binary', CONST_InstallPath.'/osm2pgsql/osm2pgsql');
@define('CONST_Osmosis_Binary', '/usr/bin/osmosis');
@define('CONST_Tiger_Data_Path', CONST_BasePath.'/data/tiger');
}
+ public function test_getClassTypesWithImportance()
+ {
+ $aClasses = getClassTypesWithImportance();
+
+ $this->assertGreaterThan(
+ 200,
+ count($aClasses)
+ );
+
+ $this->assertEquals(
+ array(
+ 'label' => "Country",
+ 'frequency' => 0,
+ 'icon' => "poi_boundary_administrative",
+ 'defzoom' => 6,
+ 'defdiameter' => 15,
+ 'importance' => 3
+ ),
+ $aClasses['place:country']
+ );
+ }
+
+
+ public function test_getResultDiameter()
+ {
+ $aResult = array();
+ $this->assertEquals(
+ 0.0001,
+ getResultDiameter($aResult)
+ );
+
+ $aResult = array('class' => 'place', 'type' => 'country');
+ $this->assertEquals(
+ 15,
+ getResultDiameter($aResult)
+ );
+
+ $aResult = array('class' => 'boundary', 'type' => 'administrative', 'admin_level' => 6);
+ $this->assertEquals(
+ 0.32,
+ getResultDiameter($aResult)
+ );
+ }
+
+
public function test_addQuotes()
{
// FIXME: not quoting existing quote signs is probably a bug
65536,
count( getWordSets(array_fill( 0, 18, 'a'),0) )
);
+ }
+ }
+
+
+
+
+ public function test_geometryText2Points()
+ {
+ $fRadius = 1;
+
+ // invalid value
+ $this->assertEquals(
+ NULL,
+ geometryText2Points('', $fRadius)
+ );
+
+
+ // POINT
+ $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
+ $this->assertEquals(
+ 101,
+ count($aPoints)
+ );
+
+ $this->assertEquals(
+
+ array(
+ ['', 10, 21],
+ ['', 10.062790519529, 20.998026728428],
+ ['', 10.125333233564, 20.992114701314]
+ ),
+ array_splice($aPoints, 0,3)
+ );
+
+ // POLYGON
+ $this->assertEquals(
+ array(
+ ['30 10', '30', '10'],
+ ['40 40', '40', '40'],
+ ['20 40', '20', '40'],
+ ['10 20', '10', '20'],
+ ['30 10', '30', '10']
+ ),
+ geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
+ );
+
+ // MULTIPOLYGON
+ // only the first polygon is used
+ $this->assertEquals(
+ array(
+ ['30 20', '30', '20'],
+ ['45 40', '45', '40'],
+ ['10 40', '10', '40'],
+ ['30 20', '30', '20'],
+
+ // ['15 5' , '15', '5' ],
+ // ['45 10', '45', '10'],
+ // ['10 20', '10', '20'],
+ // ['5 10' , '5' , '10'],
+ // ['15 5' , '15', '5' ]
+ ),
+ geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)
+ );
+ // you might say we're creating a circle
+ public function test_createPointsAroundCenter()
+ {
+ $aPoints = createPointsAroundCenter(0, 0, 2);
+ $this->assertEquals(
+ 101,
+ count($aPoints)
+ );
+ $this->assertEquals(
+ array(
+ ['', 0, 2],
+ ['', 0.12558103905863, 1.9960534568565],
+ ['', 0.25066646712861, 1.984229402629]
+ ),
+ array_splice($aPoints, 0, 3)
+ );
}
+ public function test_geometryText2Points()
+ {
+ $fRadius = 1;
+ // invalid value
+ $this->assertEquals(
+ NULL,
+ geometryText2Points('', $fRadius)
+ );
+
+ // POINT
+ $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
+ $this->assertEquals(
+ 101,
+ count($aPoints)
+ );
+ $this->assertEquals(
+ array(
+ [10, 21],
+ [10.062790519529, 20.998026728428],
+ [10.125333233564, 20.992114701314]
+ ),
+ array_splice($aPoints, 0,3)
+ );
+
+ // POLYGON
+ $this->assertEquals(
+ array(
+ ['30', '10'],
+ ['40', '40'],
+ ['20', '40'],
+ ['10', '20'],
+ ['30', '10']
+ ),
+ geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
+ );
+
+ // MULTIPOLYGON
+ $this->assertEquals(
+ array(
+ ['30', '20'], // first polygon only
+ ['45', '40'],
+ ['10', '40'],
+ ['30', '20'],
+ ),
+ geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)
+ );
+ }
}