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 setAddressDetails($b = true)
48 $this->bAddressDetails = $b;
51 public function setAddressAdminLevels($b = true)
53 $this->bAddressAdminLevels = $b;
56 public function loadParamArray($oParams, $sGeomType = null)
58 $aLangs = $oParams->getPreferredLanguages();
59 $this->aLangPrefOrderSql =
60 'ARRAY['.join(',', array_map('getDBQuoted', $aLangs)).']';
62 $this->bAddressDetails = $oParams->getBool('addressdetails', true);
63 $this->bExtraTags = $oParams->getBool('extratags', false);
64 $this->bNameDetails = $oParams->getBool('namedetails', false);
66 $this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
68 if ($sGeomType === null || $sGeomType == 'geojson') {
69 $this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
70 $this->bIncludePolygonAsPoints = false;
73 if ($oParams->getString('format', '') !== 'geojson') {
74 if ($sGeomType === null || $sGeomType == 'text') {
75 $this->bIncludePolygonAsText = $oParams->getBool('polygon_text');
77 if ($sGeomType === null || $sGeomType == 'kml') {
78 $this->bIncludePolygonAsKML = $oParams->getBool('polygon_kml');
80 if ($sGeomType === null || $sGeomType == 'svg') {
81 $this->bIncludePolygonAsSVG = $oParams->getBool('polygon_svg');
84 $this->fPolygonSimplificationThreshold
85 = $oParams->getFloat('polygon_threshold', 0.0);
88 ($this->bIncludePolygonAsText ? 1 : 0) +
89 ($this->bIncludePolygonAsGeoJSON ? 1 : 0) +
90 ($this->bIncludePolygonAsKML ? 1 : 0) +
91 ($this->bIncludePolygonAsSVG ? 1 : 0);
92 if ($iWantedTypes > CONST_PolygonOutput_MaximumTypes) {
93 if (CONST_PolygonOutput_MaximumTypes) {
94 userError('Select only '.CONST_PolygonOutput_MaximumTypes.' polgyon output option');
96 userError('Polygon output is disabled');
101 public function getMoreUrlParams()
105 if ($this->bAddressDetails) $aParams['addressdetails'] = '1';
106 if ($this->bExtraTags) $aParams['extratags'] = '1';
107 if ($this->bNameDetails) $aParams['namedetails'] = '1';
109 if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
110 if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
111 if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
112 if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
113 if ($this->bIncludePolygonAsSVG) $aParams['polygon_svg'] = '1';
115 if ($this->fPolygonSimplificationThreshold > 0.0) {
116 $aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
119 if (!$this->bDeDupe) $aParams['dedupe'] = '0';
124 public function setAnchorSql($sPoint)
126 $this->sAnchorSql = $sPoint;
129 public function setAddressRankList($aList)
131 $this->sAddressRankListSql = '('.join(',', $aList).')';
134 public function setAllowedTypesSQLList($sSql)
136 $this->sAllowedTypesSQLList = $sSql;
139 public function setLanguagePreference($aLangPrefOrder)
141 $this->aLangPrefOrderSql =
142 'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']';
145 public function setIncludeAddressDetails($bAddressDetails = true)
147 $this->bAddressDetails = $bAddressDetails;
150 private function addressImportanceSql($sGeometry, $sPlaceId)
152 if ($this->sAnchorSql) {
153 $sSQL = 'ST_Distance('.$this->sAnchorSql.','.$sGeometry.')';
155 $sSQL = '(SELECT max(ai_p.importance * (ai_p.rank_address + 2))';
156 $sSQL .= ' FROM place_addressline ai_s, placex ai_p';
157 $sSQL .= ' WHERE ai_s.place_id = '.$sPlaceId;
158 $sSQL .= ' AND ai_p.place_id = ai_s.address_place_id ';
159 $sSQL .= ' AND ai_s.isaddress ';
160 $sSQL .= ' AND ai_p.importance is not null)';
163 return $sSQL.' AS addressimportance,';
166 private function langAddressSql($sHousenumber)
168 return 'get_address_by_language(place_id,'.$sHousenumber.','.$this->aLangPrefOrderSql.') AS langaddress,';
171 public function lookupOSMID($sType, $iID)
173 $sSQL = "select place_id from placex where osm_type = '".$sType."' and osm_id = ".$iID;
174 $iPlaceID = chksql($this->oDB->getOne($sSQL));
180 $aResults = $this->lookup(array($iPlaceID => new Result($iPlaceID)));
182 return empty($aResults) ? null : reset($aResults);
185 public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30)
187 Debug::newFunction('Place lookup');
189 if (empty($aResults)) {
192 $aSubSelects = array();
194 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_PLACEX);
196 Debug::printVar('Ids from placex', $sPlaceIDs);
198 $sSQL .= ' osm_type,';
202 $sSQL .= ' admin_level,';
203 $sSQL .= ' rank_search,';
204 $sSQL .= ' rank_address,';
205 $sSQL .= ' min(place_id) AS place_id,';
206 $sSQL .= ' min(parent_place_id) AS parent_place_id,';
207 $sSQL .= ' -1 as housenumber,';
208 $sSQL .= ' country_code,';
209 $sSQL .= $this->langAddressSql('-1');
210 $sSQL .= ' get_name_by_language(name,'.$this->aLangPrefOrderSql.') AS placename,';
211 $sSQL .= " get_name_by_language(name, ARRAY['ref']) AS ref,";
212 if ($this->bExtraTags) {
213 $sSQL .= 'hstore_to_json(extratags)::text AS extra,';
215 if ($this->bNameDetails) {
216 $sSQL .= 'hstore_to_json(name)::text AS names,';
218 $sSQL .= ' avg(ST_X(centroid)) AS lon, ';
219 $sSQL .= ' avg(ST_Y(centroid)) AS lat, ';
220 $sSQL .= ' COALESCE(importance,0.75-(rank_search::float/40)) AS importance, ';
221 $sSQL .= $this->addressImportanceSql(
222 'ST_Collect(centroid)',
223 'min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END)'
225 $sSQL .= " (extratags->'place') AS extra_place ";
226 $sSQL .= ' FROM placex';
227 $sSQL .= " WHERE place_id in ($sPlaceIDs) ";
229 $sSQL .= " placex.rank_address between $iMinRank and $iMaxRank ";
230 if (14 >= $iMinRank && 14 <= $iMaxRank) {
231 $sSQL .= " OR (extratags->'place') = 'city'";
233 if ($this->sAddressRankListSql) {
234 $sSQL .= ' OR placex.rank_address in '.$this->sAddressRankListSql;
237 if ($this->sAllowedTypesSQLList) {
238 $sSQL .= 'AND placex.class in '.$this->sAllowedTypesSQLList;
240 $sSQL .= ' AND linked_place_id is null ';
241 $sSQL .= ' GROUP BY ';
242 $sSQL .= ' osm_type, ';
243 $sSQL .= ' osm_id, ';
246 $sSQL .= ' admin_level, ';
247 $sSQL .= ' rank_search, ';
248 $sSQL .= ' rank_address, ';
249 $sSQL .= ' housenumber,';
250 $sSQL .= ' country_code, ';
251 $sSQL .= ' importance, ';
252 if (!$this->bDeDupe) $sSQL .= 'place_id,';
253 $sSQL .= ' langaddress, ';
254 $sSQL .= ' placename, ';
256 if ($this->bExtraTags) $sSQL .= 'extratags, ';
257 if ($this->bNameDetails) $sSQL .= 'name, ';
258 $sSQL .= " extratags->'place' ";
260 $aSubSelects[] = $sSQL;
264 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_POSTCODE);
266 Debug::printVar('Ids from location_postcode', $sPlaceIDs);
268 $sSQL .= " 'P' as osm_type,";
269 $sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id = lp.parent_place_id) as osm_id,';
270 $sSQL .= " 'place' as class, 'postcode' as type,";
271 $sSQL .= ' null as admin_level, rank_search, rank_address,';
272 $sSQL .= ' place_id, parent_place_id,';
273 $sSQL .= ' null as housenumber,';
274 $sSQL .= ' country_code,';
275 $sSQL .= $this->langAddressSql('-1');
276 $sSQL .= ' postcode as placename,';
277 $sSQL .= ' postcode as ref,';
278 if ($this->bExtraTags) $sSQL .= 'null AS extra,';
279 if ($this->bNameDetails) $sSQL .= 'null AS names,';
280 $sSQL .= ' ST_x(geometry) AS lon, ST_y(geometry) AS lat,';
281 $sSQL .= ' (0.75-(rank_search::float/40)) AS importance, ';
282 $sSQL .= $this->addressImportanceSql('geometry', 'lp.parent_place_id');
283 $sSQL .= ' null AS extra_place ';
284 $sSQL .= 'FROM location_postcode lp';
285 $sSQL .= " WHERE place_id in ($sPlaceIDs) ";
286 $sSQL .= " AND lp.rank_address between $iMinRank and $iMaxRank";
288 $aSubSelects[] = $sSQL;
291 // All other tables are rank 30 only.
292 if ($iMaxRank == 30) {
294 if (CONST_Use_US_Tiger_Data) {
295 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_TIGER);
297 Debug::printVar('Ids from Tiger table', $sPlaceIDs);
298 $sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_TIGER);
299 // Tiger search only if a housenumber was searched and if it was found
300 // (realized through a join)
302 $sSQL .= " 'T' AS osm_type, ";
303 $sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id=blub.parent_place_id) as osm_id, ';
304 $sSQL .= " 'place' AS class, ";
305 $sSQL .= " 'house' AS type, ";
306 $sSQL .= ' null AS admin_level, ';
307 $sSQL .= ' 30 AS rank_search, ';
308 $sSQL .= ' 30 AS rank_address, ';
309 $sSQL .= ' place_id, ';
310 $sSQL .= ' parent_place_id, ';
311 $sSQL .= ' housenumber_for_place as housenumber,';
312 $sSQL .= " 'us' AS country_code, ";
313 $sSQL .= $this->langAddressSql('housenumber_for_place');
314 $sSQL .= ' null AS placename, ';
315 $sSQL .= ' null AS ref, ';
316 if ($this->bExtraTags) $sSQL .= 'null AS extra,';
317 if ($this->bNameDetails) $sSQL .= 'null AS names,';
318 $sSQL .= ' st_x(centroid) AS lon, ';
319 $sSQL .= ' st_y(centroid) AS lat,';
320 $sSQL .= ' -1.15 AS importance, ';
321 $sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id');
322 $sSQL .= ' null AS extra_place ';
324 $sSQL .= ' SELECT place_id, '; // interpolate the Tiger housenumbers here
325 $sSQL .= ' ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) AS centroid, ';
326 $sSQL .= ' parent_place_id, ';
327 $sSQL .= ' housenumber_for_place';
329 $sSQL .= ' location_property_tiger ';
330 $sSQL .= ' JOIN (values '.$sHousenumbers.') AS housenumbers(place_id, housenumber_for_place) USING(place_id)) ';
332 $sSQL .= ' housenumber_for_place >= startnumber';
333 $sSQL .= ' AND housenumber_for_place <= endnumber';
334 $sSQL .= ' ) AS blub'; //postgres wants an alias here
336 $aSubSelects[] = $sSQL;
340 // osmline - interpolated housenumbers
341 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_OSMLINE);
343 Debug::printVar('Ids from interpolation', $sPlaceIDs);
344 $sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_OSMLINE);
345 // interpolation line search only if a housenumber was searched
346 // (realized through a join)
348 $sSQL .= " 'W' AS osm_type, ";
349 $sSQL .= ' osm_id, ';
350 $sSQL .= " 'place' AS class, ";
351 $sSQL .= " 'house' AS type, ";
352 $sSQL .= ' 15 AS admin_level, ';
353 $sSQL .= ' 30 AS rank_search, ';
354 $sSQL .= ' 30 AS rank_address, ';
355 $sSQL .= ' place_id, ';
356 $sSQL .= ' parent_place_id, ';
357 $sSQL .= ' housenumber_for_place as housenumber,';
358 $sSQL .= ' country_code, ';
359 $sSQL .= $this->langAddressSql('housenumber_for_place');
360 $sSQL .= ' null AS placename, ';
361 $sSQL .= ' null AS ref, ';
362 if ($this->bExtraTags) $sSQL .= 'null AS extra, ';
363 if ($this->bNameDetails) $sSQL .= 'null AS names, ';
364 $sSQL .= ' st_x(centroid) AS lon, ';
365 $sSQL .= ' st_y(centroid) AS lat, ';
366 // slightly smaller than the importance for normal houses
367 $sSQL .= ' -0.1 AS importance, ';
368 $sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id');
369 $sSQL .= ' null AS extra_place ';
372 $sSQL .= ' osm_id, ';
373 $sSQL .= ' place_id, ';
374 $sSQL .= ' country_code, ';
375 $sSQL .= ' CASE '; // interpolate the housenumbers here
376 $sSQL .= ' WHEN startnumber != endnumber ';
377 $sSQL .= ' THEN ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) ';
378 $sSQL .= ' ELSE ST_LineInterpolatePoint(linegeo, 0.5) ';
379 $sSQL .= ' END as centroid, ';
380 $sSQL .= ' parent_place_id, ';
381 $sSQL .= ' housenumber_for_place ';
383 $sSQL .= ' location_property_osmline ';
384 $sSQL .= ' JOIN (values '.$sHousenumbers.') AS housenumbers(place_id, housenumber_for_place) USING(place_id)';
386 $sSQL .= ' WHERE housenumber_for_place >= 0 ';
387 $sSQL .= ' ) as blub'; //postgres wants an alias here
389 $aSubSelects[] = $sSQL;
392 if (CONST_Use_Aux_Location_data) {
393 $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_AUX);
395 $sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_AUX);
397 $sSQL .= " 'L' AS osm_type, ";
398 $sSQL .= ' place_id AS osm_id, ';
399 $sSQL .= " 'place' AS class,";
400 $sSQL .= " 'house' AS type, ";
401 $sSQL .= ' null AS admin_level, ';
402 $sSQL .= ' 30 AS rank_search,';
403 $sSQL .= ' 30 AS rank_address, ';
404 $sSQL .= ' place_id,';
405 $sSQL .= ' parent_place_id, ';
406 $sSQL .= ' housenumber,';
407 $sSQL .= " 'us' AS country_code, ";
408 $sSQL .= $this->langAddressSql('-1');
409 $sSQL .= ' null AS placename, ';
410 $sSQL .= ' null AS ref, ';
411 if ($this->bExtraTags) $sSQL .= 'null AS extra, ';
412 if ($this->bNameDetails) $sSQL .= 'null AS names, ';
413 $sSQL .= ' ST_X(centroid) AS lon, ';
414 $sSQL .= ' ST_Y(centroid) AS lat, ';
415 $sSQL .= ' -1.10 AS importance, ';
416 $sSQL .= $this->addressImportanceSql(
418 'location_property_aux.parent_place_id'
420 $sSQL .= ' null AS extra_place ';
421 $sSQL .= ' FROM location_property_aux ';
422 $sSQL .= " WHERE place_id in ($sPlaceIDs) ";
424 $aSubSelects[] = $sSQL;
429 if (empty($aSubSelects)) {
433 $sSQL = join(' UNION ', $aSubSelects);
434 Debug::printSQL($sSQL);
435 $aPlaces = chksql($this->oDB->getAll($sSQL), 'Could not lookup place');
437 $aClassType = getClassTypes();
438 foreach ($aPlaces as &$aPlace) {
439 if ($this->bAddressDetails) {
440 // to get addressdetails for tiger data, the housenumber is needed
441 $aPlace['aAddress'] = $this->getAddressNames(
443 $aPlace['housenumber']
447 if ($this->bAddressAdminLevels) {
448 $aPlace['aAddressAdminLevels'] = $this->getAddressAdminLevels(
450 $aPlace['housenumber']
454 if ($this->bExtraTags) {
455 if ($aPlace['extra']) {
456 $aPlace['sExtraTags'] = json_decode($aPlace['extra']);
458 $aPlace['sExtraTags'] = (object) array();
462 if ($this->bNameDetails) {
463 if ($aPlace['names']) {
464 $aPlace['sNameDetails'] = json_decode($aPlace['names']);
466 $aPlace['sNameDetails'] = (object) array();
471 $sClassType = $aPlace['class'].':'.$aPlace['type'].':'.$aPlace['admin_level'];
472 if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel'])) {
473 $sAddressType = $aClassType[$aClassType]['simplelabel'];
475 $sClassType = $aPlace['class'].':'.$aPlace['type'];
476 if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel']))
477 $sAddressType = $aClassType[$sClassType]['simplelabel'];
478 else $sAddressType = $aPlace['class'];
481 $aPlace['addresstype'] = $sAddressType;
484 Debug::printVar('Places', $aPlaces);
489 public function getAddressDetails($iPlaceID, $bAll = false, $sHousenumber = -1)
492 $sSQL .= ' get_name_by_language(name,'.$this->aLangPrefOrderSql.') as localname';
493 $sSQL .= ' FROM get_addressdata('.$iPlaceID.','.$sHousenumber.')';
495 $sSQL .= " WHERE isaddress OR type = 'country_code'";
497 $sSQL .= ' ORDER BY rank_address desc,isaddress DESC';
499 return chksql($this->oDB->getAll($sSQL));
502 public function getAddressNames($iPlaceID, $sHousenumber = null)
504 $aAddressLines = $this->getAddressDetails(
507 $sHousenumber === null ? -1 : $sHousenumber
511 $aFallback = array();
512 $aClassType = getClassTypes();
513 foreach ($aAddressLines as $aLine) {
516 if (isset($aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']])) {
517 $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type'].':'.$aLine['admin_level']];
518 } elseif (isset($aClassType[$aLine['class'].':'.$aLine['type']])) {
519 $aTypeLabel = $aClassType[$aLine['class'].':'.$aLine['type']];
520 } elseif (isset($aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))])) {
521 $aTypeLabel = $aClassType['boundary:administrative:'.((int)($aLine['rank_address']/2))];
524 $aTypeLabel = array('simplelabel' => 'address'.$aLine['rank_address']);
527 if ($aTypeLabel && ((isset($aLine['localname']) && $aLine['localname']) || (isset($aLine['housenumber']) && $aLine['housenumber']))) {
528 $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel'])?$aTypeLabel['simplelabel']:$aTypeLabel['label']);
529 $sTypeLabel = str_replace(' ', '_', $sTypeLabel);
530 if (!isset($aAddress[$sTypeLabel]) || (isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel]) || $aLine['class'] == 'place') {
531 $aAddress[$sTypeLabel] = $aLine['localname']?$aLine['localname']:$aLine['housenumber'];
533 $aFallback[$sTypeLabel] = $bFallback;
539 /* "Downing Street, London"
541 * "level15" => "Covent Garden",
542 * "level8" => "Westminster",
543 * "level6" => "London",
544 * "level5" => "Greater London",
545 * "level4" => "England",
546 * "level2" => "United Kingdom"
550 public function getAddressAdminLevels($iPlaceID, $sHousenumber = null)
552 $aAddressLines = $this->getAddressDetails(
555 $sHousenumber === null ? -1 : $sHousenumber
559 foreach ($aAddressLines as $aLine) {
560 if (isset($aLine['admin_level'])) {
561 $aAddress['level'.$aLine['admin_level']] = $aLine['localname'];
568 /* returns an array which will contain the keys
570 * and may also contain one or more of the keys
580 public function getOutlines($iPlaceID, $fLon = null, $fLat = null, $fRadius = null)
583 $aOutlineResult = array();
584 if (!$iPlaceID) return $aOutlineResult;
586 if (CONST_Search_AreaPolygons) {
587 // Get the bounding box and outline polygon
588 $sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,';
589 $sSQL .= 'ST_Y(centroid) as centrelat,ST_X(centroid) as centrelon,';
590 $sSQL .= 'ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,';
591 $sSQL .= 'ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon';
592 if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson';
593 if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml';
594 if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg';
595 if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ',ST_AsText(geometry) as astext';
596 $sFrom = ' from placex where place_id = '.$iPlaceID;
597 if ($this->fPolygonSimplificationThreshold > 0) {
598 $sSQL .= ' from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry'.$sFrom.') as plx';
603 $aPointPolygon = chksql($this->oDB->getRow($sSQL), 'Could not get outline');
605 if ($aPointPolygon['place_id']) {
606 if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) {
607 $aOutlineResult['lat'] = $aPointPolygon['centrelat'];
608 $aOutlineResult['lon'] = $aPointPolygon['centrelon'];
611 if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson'];
612 if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml'];
613 if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg'];
614 if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext'];
615 if ($this->bIncludePolygonAsPoints) $aOutlineResult['aPolyPoints'] = geometryText2Points($aPointPolygon['astext'], $fRadius);
618 if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) {
619 $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
620 $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
623 if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) {
624 $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
625 $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
628 $aOutlineResult['aBoundingBox'] = array(
629 (string)$aPointPolygon['minlat'],
630 (string)$aPointPolygon['maxlat'],
631 (string)$aPointPolygon['minlon'],
632 (string)$aPointPolygon['maxlon']
637 // as a fallback we generate a bounding box without knowing the size of the geometry
638 if ((!isset($aOutlineResult['aBoundingBox'])) && isset($fLon)) {
640 if ($this->bIncludePolygonAsPoints) {
641 $sGeometryText = 'POINT('.$fLon.','.$fLat.')';
642 $aOutlineResult['aPolyPoints'] = geometryText2Points($sGeometryText, $fRadius);
646 $aBounds['minlat'] = $fLat - $fRadius;
647 $aBounds['maxlat'] = $fLat + $fRadius;
648 $aBounds['minlon'] = $fLon - $fRadius;
649 $aBounds['maxlon'] = $fLon + $fRadius;
651 $aOutlineResult['aBoundingBox'] = array(
652 (string)$aBounds['minlat'],
653 (string)$aBounds['maxlat'],
654 (string)$aBounds['minlon'],
655 (string)$aBounds['maxlon']
658 return $aOutlineResult;