5 require_once(CONST_BasePath.'/lib/Result.php');
11 protected $aLangPrefOrderSql = "''";
13 protected $bAddressDetails = false;
14 protected $bAddressAdminLevels = false;
15 protected $bExtraTags = false;
16 protected $bNameDetails = false;
18 protected $bIncludePolygonAsPoints = false;
19 protected $bIncludePolygonAsText = false;
20 protected $bIncludePolygonAsGeoJSON = false;
21 protected $bIncludePolygonAsKML = false;
22 protected $bIncludePolygonAsSVG = false;
23 protected $fPolygonSimplificationThreshold = 0.0;
25 protected $sAnchorSql = null;
26 protected $sAddressRankListSql = null;
27 protected $sAllowedTypesSQLList = null;
28 protected $bDeDupe = true;
31 public function __construct(&$oDB)
36 public function doDeDupe()
38 return $this->bDeDupe;
41 public function setIncludePolygonAsPoints($b = true)
43 $this->bIncludePolygonAsPoints = $b;
46 public function setAddressAdminLevels($b = true)
48 $this->bAddressAdminLevels = $b;
51 public function loadParamArray($oParams, $sGeomType = null)
53 $aLangs = $oParams->getPreferredLanguages();
54 $this->aLangPrefOrderSql =
55 'ARRAY['.join(',', array_map('getDBQuoted', $aLangs)).']';
57 $this->bAddressDetails = $oParams->getBool('addressdetails', true);
58 $this->bExtraTags = $oParams->getBool('extratags', false);
59 $this->bNameDetails = $oParams->getBool('namedetails', false);
61 $this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
63 if ($sGeomType === null || $sGeomType == 'geojson') {
64 $this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
65 $this->bIncludePolygonAsPoints = false;
68 if ($oParams->getString('format', '') !== 'geojson') {
69 if ($sGeomType === null || $sGeomType == 'text') {
70 $this->bIncludePolygonAsText = $oParams->getBool('polygon_text');
72 if ($sGeomType === null || $sGeomType == 'kml') {
73 $this->bIncludePolygonAsKML = $oParams->getBool('polygon_kml');
75 if ($sGeomType === null || $sGeomType == 'svg') {
76 $this->bIncludePolygonAsSVG = $oParams->getBool('polygon_svg');
79 $this->fPolygonSimplificationThreshold
80 = $oParams->getFloat('polygon_threshold', 0.0);
83 ($this->bIncludePolygonAsText ? 1 : 0) +
84 ($this->bIncludePolygonAsGeoJSON ? 1 : 0) +
85 ($this->bIncludePolygonAsKML ? 1 : 0) +
86 ($this->bIncludePolygonAsSVG ? 1 : 0);
87 if ($iWantedTypes > CONST_PolygonOutput_MaximumTypes) {
88 if (CONST_PolygonOutput_MaximumTypes) {
89 userError('Select only '.CONST_PolygonOutput_MaximumTypes.' polgyon output option');
91 userError('Polygon output is disabled');
96 public function getMoreUrlParams()
100 if ($this->bAddressDetails) $aParams['addressdetails'] = '1';
101 if ($this->bExtraTags) $aParams['extratags'] = '1';
102 if ($this->bNameDetails) $aParams['namedetails'] = '1';
104 if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
105 if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
106 if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
107 if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
108 if ($this->bIncludePolygonAsSVG) $aParams['polygon_svg'] = '1';
110 if ($this->fPolygonSimplificationThreshold > 0.0) {
111 $aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
114 if (!$this->bDeDupe) $aParams['dedupe'] = '0';
119 public function setAnchorSql($sPoint)
121 $this->sAnchorSql = $sPoint;
124 public function setAddressRankList($aList)
126 $this->sAddressRankListSql = '('.join(',', $aList).')';
129 public function setAllowedTypesSQLList($sSql)
131 $this->sAllowedTypesSQLList = $sSql;
134 public function setLanguagePreference($aLangPrefOrder)
136 $this->aLangPrefOrderSql =
137 'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']';
140 public function setIncludeAddressDetails($bAddressDetails = true)
142 $this->bAddressDetails = $bAddressDetails;
145 private function addressImportanceSql($sGeometry, $sPlaceId)
147 if ($this->sAnchorSql) {
148 $sSQL = 'ST_Distance('.$this->sAnchorSql.','.$sGeometry.')';
150 $sSQL = '(SELECT max(ai_p.importance * (ai_p.rank_address + 2))';
151 $sSQL .= ' FROM place_addressline ai_s, placex ai_p';
152 $sSQL .= ' WHERE ai_s.place_id = '.$sPlaceId;
153 $sSQL .= ' AND ai_p.place_id = ai_s.address_place_id ';
154 $sSQL .= ' AND ai_s.isaddress ';
155 $sSQL .= ' AND ai_p.importance is not null)';
158 return $sSQL.' AS addressimportance,';
161 private function langAddressSql($sHousenumber)
163 return 'get_address_by_language(place_id,'.$sHousenumber.','.$this->aLangPrefOrderSql.') AS langaddress,';
166 public function lookupOSMID($sType, $iID)
168 $sSQL = "select place_id from placex where osm_type = '".$sType."' and osm_id = ".$iID;
169 $iPlaceID = chksql($this->oDB->getOne($sSQL));
175 $aResults = $this->lookup(array($iPlaceID => new Result($iPlaceID)));
177 return empty($aResults) ? null : reset($aResults);
180 public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30)
182 Debug::newFunction('Place lookup');
184 if (empty($aResults)) {
187 $aSubSelects = array();
189 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_PLACEX);
191 Debug::printVar('Ids from placex', $sPlaceIDs);
193 $sSQL .= ' osm_type,';
197 $sSQL .= ' admin_level,';
198 $sSQL .= ' rank_search,';
199 $sSQL .= ' rank_address,';
200 $sSQL .= ' min(place_id) AS place_id,';
201 $sSQL .= ' min(parent_place_id) AS parent_place_id,';
202 $sSQL .= ' -1 as housenumber,';
203 $sSQL .= ' country_code,';
204 $sSQL .= $this->langAddressSql('-1');
205 $sSQL .= ' get_name_by_language(name,'.$this->aLangPrefOrderSql.') AS placename,';
206 $sSQL .= " get_name_by_language(name, ARRAY['ref']) AS ref,";
207 if ($this->bExtraTags) {
208 $sSQL .= 'hstore_to_json(extratags)::text AS extra,';
210 if ($this->bNameDetails) {
211 $sSQL .= 'hstore_to_json(name)::text AS names,';
213 $sSQL .= ' avg(ST_X(centroid)) AS lon, ';
214 $sSQL .= ' avg(ST_Y(centroid)) AS lat, ';
215 $sSQL .= ' COALESCE(importance,0.75-(rank_search::float/40)) AS importance, ';
216 $sSQL .= $this->addressImportanceSql(
217 'ST_Collect(centroid)',
218 'min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END)'
220 $sSQL .= " (extratags->'place') AS extra_place ";
221 $sSQL .= ' FROM placex';
222 $sSQL .= " WHERE place_id in ($sPlaceIDs) ";
224 $sSQL .= " placex.rank_address between $iMinRank and $iMaxRank ";
225 if (14 >= $iMinRank && 14 <= $iMaxRank) {
226 $sSQL .= " OR (extratags->'place') = 'city'";
228 if ($this->sAddressRankListSql) {
229 $sSQL .= ' OR placex.rank_address in '.$this->sAddressRankListSql;
232 if ($this->sAllowedTypesSQLList) {
233 $sSQL .= 'AND placex.class in '.$this->sAllowedTypesSQLList;
235 $sSQL .= ' AND linked_place_id is null ';
236 $sSQL .= ' GROUP BY ';
237 $sSQL .= ' osm_type, ';
238 $sSQL .= ' osm_id, ';
241 $sSQL .= ' admin_level, ';
242 $sSQL .= ' rank_search, ';
243 $sSQL .= ' rank_address, ';
244 $sSQL .= ' housenumber,';
245 $sSQL .= ' country_code, ';
246 $sSQL .= ' importance, ';
247 if (!$this->bDeDupe) $sSQL .= 'place_id,';
248 $sSQL .= ' langaddress, ';
249 $sSQL .= ' placename, ';
251 if ($this->bExtraTags) $sSQL .= 'extratags, ';
252 if ($this->bNameDetails) $sSQL .= 'name, ';
253 $sSQL .= " extratags->'place' ";
255 $aSubSelects[] = $sSQL;
259 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_POSTCODE);
261 Debug::printVar('Ids from location_postcode', $sPlaceIDs);
263 $sSQL .= " 'P' as osm_type,";
264 $sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id = lp.parent_place_id) as osm_id,';
265 $sSQL .= " 'place' as class, 'postcode' as type,";
266 $sSQL .= ' null as admin_level, rank_search, rank_address,';
267 $sSQL .= ' place_id, parent_place_id,';
268 $sSQL .= ' null as housenumber,';
269 $sSQL .= ' country_code,';
270 $sSQL .= $this->langAddressSql('-1');
271 $sSQL .= ' postcode as placename,';
272 $sSQL .= ' postcode as ref,';
273 if ($this->bExtraTags) $sSQL .= 'null AS extra,';
274 if ($this->bNameDetails) $sSQL .= 'null AS names,';
275 $sSQL .= ' ST_x(geometry) AS lon, ST_y(geometry) AS lat,';
276 $sSQL .= ' (0.75-(rank_search::float/40)) AS importance, ';
277 $sSQL .= $this->addressImportanceSql('geometry', 'lp.parent_place_id');
278 $sSQL .= ' null AS extra_place ';
279 $sSQL .= 'FROM location_postcode lp';
280 $sSQL .= " WHERE place_id in ($sPlaceIDs) ";
281 $sSQL .= " AND lp.rank_address between $iMinRank and $iMaxRank";
283 $aSubSelects[] = $sSQL;
286 // All other tables are rank 30 only.
287 if ($iMaxRank == 30) {
289 if (CONST_Use_US_Tiger_Data) {
290 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_TIGER);
292 Debug::printVar('Ids from Tiger table', $sPlaceIDs);
293 $sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_TIGER);
294 // Tiger search only if a housenumber was searched and if it was found
295 // (realized through a join)
297 $sSQL .= " 'T' AS osm_type, ";
298 $sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id=blub.parent_place_id) as osm_id, ';
299 $sSQL .= " 'place' AS class, ";
300 $sSQL .= " 'house' AS type, ";
301 $sSQL .= ' null AS admin_level, ';
302 $sSQL .= ' 30 AS rank_search, ';
303 $sSQL .= ' 30 AS rank_address, ';
304 $sSQL .= ' place_id, ';
305 $sSQL .= ' parent_place_id, ';
306 $sSQL .= ' housenumber_for_place as housenumber,';
307 $sSQL .= " 'us' AS country_code, ";
308 $sSQL .= $this->langAddressSql('housenumber_for_place');
309 $sSQL .= ' null AS placename, ';
310 $sSQL .= ' null AS ref, ';
311 if ($this->bExtraTags) $sSQL .= 'null AS extra,';
312 if ($this->bNameDetails) $sSQL .= 'null AS names,';
313 $sSQL .= ' st_x(centroid) AS lon, ';
314 $sSQL .= ' st_y(centroid) AS lat,';
315 $sSQL .= ' -1.15 AS importance, ';
316 $sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id');
317 $sSQL .= ' null AS extra_place ';
319 $sSQL .= ' SELECT place_id, '; // interpolate the Tiger housenumbers here
320 $sSQL .= ' ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) AS centroid, ';
321 $sSQL .= ' parent_place_id, ';
322 $sSQL .= ' housenumber_for_place';
324 $sSQL .= ' location_property_tiger ';
325 $sSQL .= ' JOIN (values '.$sHousenumbers.') AS housenumbers(place_id, housenumber_for_place) USING(place_id)) ';
327 $sSQL .= ' housenumber_for_place >= startnumber';
328 $sSQL .= ' AND housenumber_for_place <= endnumber';
329 $sSQL .= ' ) AS blub'; //postgres wants an alias here
331 $aSubSelects[] = $sSQL;
335 // osmline - interpolated housenumbers
336 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_OSMLINE);
338 Debug::printVar('Ids from interpolation', $sPlaceIDs);
339 $sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_OSMLINE);
340 // interpolation line search only if a housenumber was searched
341 // (realized through a join)
343 $sSQL .= " 'W' AS osm_type, ";
344 $sSQL .= ' osm_id, ';
345 $sSQL .= " 'place' AS class, ";
346 $sSQL .= " 'house' AS type, ";
347 $sSQL .= ' 15 AS admin_level, ';
348 $sSQL .= ' 30 AS rank_search, ';
349 $sSQL .= ' 30 AS rank_address, ';
350 $sSQL .= ' place_id, ';
351 $sSQL .= ' parent_place_id, ';
352 $sSQL .= ' housenumber_for_place as housenumber,';
353 $sSQL .= ' country_code, ';
354 $sSQL .= $this->langAddressSql('housenumber_for_place');
355 $sSQL .= ' null AS placename, ';
356 $sSQL .= ' null AS ref, ';
357 if ($this->bExtraTags) $sSQL .= 'null AS extra, ';
358 if ($this->bNameDetails) $sSQL .= 'null AS names, ';
359 $sSQL .= ' st_x(centroid) AS lon, ';
360 $sSQL .= ' st_y(centroid) AS lat, ';
361 // slightly smaller than the importance for normal houses
362 $sSQL .= ' -0.1 AS importance, ';
363 $sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id');
364 $sSQL .= ' null AS extra_place ';
367 $sSQL .= ' osm_id, ';
368 $sSQL .= ' place_id, ';
369 $sSQL .= ' country_code, ';
370 $sSQL .= ' CASE '; // interpolate the housenumbers here
371 $sSQL .= ' WHEN startnumber != endnumber ';
372 $sSQL .= ' THEN ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) ';
373 $sSQL .= ' ELSE ST_LineInterpolatePoint(linegeo, 0.5) ';
374 $sSQL .= ' END as centroid, ';
375 $sSQL .= ' parent_place_id, ';
376 $sSQL .= ' housenumber_for_place ';
378 $sSQL .= ' location_property_osmline ';
379 $sSQL .= ' JOIN (values '.$sHousenumbers.') AS housenumbers(place_id, housenumber_for_place) USING(place_id)';
381 $sSQL .= ' WHERE housenumber_for_place >= 0 ';
382 $sSQL .= ' ) as blub'; //postgres wants an alias here
384 $aSubSelects[] = $sSQL;
387 if (CONST_Use_Aux_Location_data) {
388 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_AUX);
390 $sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_AUX);
392 $sSQL .= " 'L' AS osm_type, ";
393 $sSQL .= ' place_id AS osm_id, ';
394 $sSQL .= " 'place' AS class,";
395 $sSQL .= " 'house' AS type, ";
396 $sSQL .= ' null AS admin_level, ';
397 $sSQL .= ' 30 AS rank_search,';
398 $sSQL .= ' 30 AS rank_address, ';
399 $sSQL .= ' place_id,';
400 $sSQL .= ' parent_place_id, ';
401 $sSQL .= ' housenumber,';
402 $sSQL .= " 'us' AS country_code, ";
403 $sSQL .= $this->langAddressSql('-1');
404 $sSQL .= ' null AS placename, ';
405 $sSQL .= ' null AS ref, ';
406 if ($this->bExtraTags) $sSQL .= 'null AS extra, ';
407 if ($this->bNameDetails) $sSQL .= 'null AS names, ';
408 $sSQL .= ' ST_X(centroid) AS lon, ';
409 $sSQL .= ' ST_Y(centroid) AS lat, ';
410 $sSQL .= ' -1.10 AS importance, ';
411 $sSQL .= $this->addressImportanceSql(
413 'location_property_aux.parent_place_id'
415 $sSQL .= ' null AS extra_place ';
416 $sSQL .= ' FROM location_property_aux ';
417 $sSQL .= " WHERE place_id in ($sPlaceIDs) ";
419 $aSubSelects[] = $sSQL;
424 if (empty($aSubSelects)) {
428 $sSQL = join(' UNION ', $aSubSelects);
429 Debug::printSQL($sSQL);
430 $aPlaces = chksql($this->oDB->getAll($sSQL), 'Could not lookup place');
432 foreach ($aPlaces as &$aPlace) {
433 if ($this->bAddressDetails) {
434 // to get addressdetails for tiger data, the housenumber is needed
435 $aPlace['aAddress'] = $this->getAddressNames(
437 $aPlace['housenumber']
441 if ($this->bAddressAdminLevels) {
442 $aPlace['aAddressAdminLevels'] = $this->getAddressAdminLevels(
444 $aPlace['housenumber']
448 if ($this->bExtraTags) {
449 if ($aPlace['extra']) {
450 $aPlace['sExtraTags'] = json_decode($aPlace['extra']);
452 $aPlace['sExtraTags'] = (object) array();
456 if ($this->bNameDetails) {
457 if ($aPlace['names']) {
458 $aPlace['sNameDetails'] = json_decode($aPlace['names']);
460 $aPlace['sNameDetails'] = (object) array();
464 $aPlace['addresstype'] = ClassTypes\getProperty(
471 Debug::printVar('Places', $aPlaces);
476 public function getAddressDetails($iPlaceID, $bAll = false, $sHousenumber = -1)
479 $sSQL .= ' get_name_by_language(name,'.$this->aLangPrefOrderSql.') as localname';
480 $sSQL .= ' FROM get_addressdata('.$iPlaceID.','.$sHousenumber.')';
482 $sSQL .= " WHERE isaddress OR type = 'country_code'";
484 $sSQL .= ' ORDER BY rank_address desc,isaddress DESC';
486 return chksql($this->oDB->getAll($sSQL));
489 public function getAddressNames($iPlaceID, $sHousenumber = null)
491 $aAddressLines = $this->getAddressDetails(
494 $sHousenumber === null ? -1 : $sHousenumber
498 $aFallback = array();
499 foreach ($aAddressLines as $aLine) {
501 $aTypeLabel = ClassTypes\getInfo($aLine);
503 if ($aTypeLabel === false) {
504 $aTypeLabel = ClassTypes\getFallbackInfo($aLine);
508 if ((isset($aLine['localname']) && $aLine['localname']) || (isset($aLine['housenumber']) && $aLine['housenumber'])) {
509 $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel'])?$aTypeLabel['simplelabel']:$aTypeLabel['label']);
510 $sTypeLabel = str_replace(' ', '_', $sTypeLabel);
511 if (!isset($aAddress[$sTypeLabel]) || (isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel]) || $aLine['class'] == 'place') {
512 $aAddress[$sTypeLabel] = $aLine['localname']?$aLine['localname']:$aLine['housenumber'];
514 $aFallback[$sTypeLabel] = $bFallback;
520 /* "Downing Street, London"
522 * "level15" => "Covent Garden",
523 * "level8" => "Westminster",
524 * "level6" => "London",
525 * "level5" => "Greater London",
526 * "level4" => "England",
527 * "level2" => "United Kingdom"
531 public function getAddressAdminLevels($iPlaceID, $sHousenumber = null)
533 $aAddressLines = $this->getAddressDetails(
536 $sHousenumber === null ? -1 : $sHousenumber
540 foreach ($aAddressLines as $aLine) {
541 if (isset($aLine['admin_level'])
542 && $aLine['admin_level'] < 15
543 && !isset($aAddress['level'.$aLine['admin_level']])) {
544 $aAddress['level'.$aLine['admin_level']] = $aLine['localname'];
551 /* returns an array which will contain the keys
553 * and may also contain one or more of the keys
563 public function getOutlines($iPlaceID, $fLon = null, $fLat = null, $fRadius = null, $fLonReverse = null, $fLatReverse = null)
566 $aOutlineResult = array();
567 if (!$iPlaceID) return $aOutlineResult;
569 if (CONST_Search_AreaPolygons) {
570 // Get the bounding box and outline polygon
571 $sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,';
572 if ($fLonReverse != null && $fLatReverse != null) {
573 $sSQL .= ' ST_Y(closest_point) as centrelat,';
574 $sSQL .= ' ST_X(closest_point) as centrelon,';
576 $sSQL .= ' ST_Y(centroid) as centrelat, ST_X(centroid) as centrelon,';
578 $sSQL .= ' ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,';
579 $sSQL .= ' ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon';
580 if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson';
581 if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml';
582 if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg';
583 if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ',ST_AsText(geometry) as astext';
584 if ($fLonReverse != null && $fLatReverse != null) {
585 $sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN ';
586 $sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))';
587 $sFrom .=' ELSE centroid END AS closest_point';
588 $sFrom .= ' from placex where place_id = '.$iPlaceID.') as plx';
590 $sFrom = ' from placex where place_id = '.$iPlaceID;
592 if ($this->fPolygonSimplificationThreshold > 0) {
593 $sSQL .= ' from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry'.$sFrom.') as plx';
598 $aPointPolygon = chksql($this->oDB->getRow($sSQL), 'Could not get outline');
600 if ($aPointPolygon['place_id']) {
601 if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) {
602 $aOutlineResult['lat'] = $aPointPolygon['centrelat'];
603 $aOutlineResult['lon'] = $aPointPolygon['centrelon'];
606 if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson'];
607 if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml'];
608 if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg'];
609 if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext'];
610 if ($this->bIncludePolygonAsPoints) $aOutlineResult['aPolyPoints'] = geometryText2Points($aPointPolygon['astext'], $fRadius);
613 if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) {
614 $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
615 $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
618 if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) {
619 $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
620 $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
623 $aOutlineResult['aBoundingBox'] = array(
624 (string)$aPointPolygon['minlat'],
625 (string)$aPointPolygon['maxlat'],
626 (string)$aPointPolygon['minlon'],
627 (string)$aPointPolygon['maxlon']
632 // as a fallback we generate a bounding box without knowing the size of the geometry
633 if ((!isset($aOutlineResult['aBoundingBox'])) && isset($fLon)) {
635 if ($this->bIncludePolygonAsPoints) {
636 $sGeometryText = 'POINT('.$fLon.','.$fLat.')';
637 $aOutlineResult['aPolyPoints'] = geometryText2Points($sGeometryText, $fRadius);
641 $aBounds['minlat'] = $fLat - $fRadius;
642 $aBounds['maxlat'] = $fLat + $fRadius;
643 $aBounds['minlon'] = $fLon - $fRadius;
644 $aBounds['maxlon'] = $fLon + $fRadius;
646 $aOutlineResult['aBoundingBox'] = array(
647 (string)$aBounds['minlat'],
648 (string)$aBounds['maxlat'],
649 (string)$aBounds['minlon'],
650 (string)$aBounds['maxlon']
653 return $aOutlineResult;