}
$this->oPlaceLookup->loadParamArray($oParams, $sForceGeometryType);
- $this->oPlaceLookup->setIncludePolygonAsPoints($oParams->getBool('polygon'));
$this->oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', false));
}
protected $bExtraTags = false;
protected $bNameDetails = false;
- protected $bIncludePolygonAsPoints = false;
protected $bIncludePolygonAsText = false;
protected $bIncludePolygonAsGeoJSON = false;
protected $bIncludePolygonAsKML = false;
return $this->bDeDupe;
}
- public function setIncludePolygonAsPoints($b = true)
- {
- $this->bIncludePolygonAsPoints = $b;
- }
-
public function setIncludeAddressDetails($b)
{
$this->bAddressDetails = $b;
if ($sGeomType === null || $sGeomType == 'geojson') {
$this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
- $this->bIncludePolygonAsPoints = false;
}
if ($oParams->getString('format', '') !== 'geojson') {
if ($this->bExtraTags) $aParams['extratags'] = '1';
if ($this->bNameDetails) $aParams['namedetails'] = '1';
- if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
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';
+ if ($this->bIncludePolygonAsText) $sSQL .= ',ST_AsText(geometry) as astext';
if ($fLonReverse != null && $fLatReverse != null) {
$sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN ';
$sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))';
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;
// 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;
+ $aBounds = array(
+ 'minlat' => $fLat - $fRadius,
+ 'maxlat' => $fLat + $fRadius,
+ 'minlon' => $fLon - $fRadius,
+ 'maxlon' => $fLon + $fRadius
+ );
$aOutlineResult['aBoundingBox'] = array(
(string)$aBounds['minlat'],
return array($sFound, $fQueryLat, $fQueryLon);
}
-
-function geometryText2Points($geometry_as_text, $fRadius)
-{
- $aPolyPoints = null;
- if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
- //
- preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
- //
- } elseif (preg_match('#LINESTRING\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
- //
- preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
- //
- } 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));
$aPointDetails['aBoundingBox'][2],
$aPointDetails['aBoundingBox'][3]
);
-
- if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons) {
- $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
- }
}
if (isset($aPointDetails['zoom'])) {
if (isset($aPointDetails['aBoundingBox'])) {
$aPlace['boundingbox'] = $aPointDetails['aBoundingBox'];
-
- if (isset($aPointDetails['aPolyPoints'])) {
- $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
- }
}
if (isset($aPointDetails['zoom'])) {
echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'";
echo " querystring='".htmlspecialchars($sQuery, ENT_QUOTES)."'";
if (isset($aMoreParams['viewbox'])) echo " viewbox='".htmlspecialchars($aMoreParams['viewbox'], ENT_QUOTES)."'";
-echo " polygon='".(isset($aMoreParams['polygon'])?'true':'false')."'";
if (isset($aMoreParams['exclude_place_ids'])) {
echo " exclude_place_ids='".htmlspecialchars($aMoreParams['exclude_place_ids'])."'";
}
echo ' boundingbox="';
echo join(',', $aResult['aBoundingBox']);
echo '"';
-
- if (isset($aResult['aPolyPoints'])) {
- echo ' polygonpoints=\'';
- echo json_encode($aResult['aPolyPoints']);
- echo '\'';
- }
}
if (isset($aResult['asgeojson'])) {
| json | geotext |
| jsonv2 | geotext |
- Scenario Outline: Reverse Geocoding contains polygon-as-points geometry
- When sending <format> reverse coordinates 47.165989816710066,9.515774846076965
- | polygon |
- | 1 |
- Then result 0 has not attributes <response_attribute>
-
- Examples:
- | format | response_attribute |
- | xml | polygonpoints |
- | json | polygonpoints |
- | jsonv2 | polygonpoints |
-
Scenario Outline: Reverse Geocoding contains SVG geometry
When sending <format> reverse coordinates 47.165989816710066,9.515774846076965
| polygon_svg |
Scenario Outline: Reverse Geocoding in geojson format contains no non-geojson geometry
When sending geojson reverse coordinates 47.165989816710066,9.515774846076965
- | polygon_text | polygon | polygon_svg | polygon_geokml |
- | 1 | 1 | 1 | 1 |
+ | polygon_text | polygon_svg | polygon_geokml |
+ | 1 | 1 | 1 |
Then result 0 has not attributes <response_attribute>
Examples:
| polygonpoints |
| svg |
| geokml |
-
Examples:
| parameter | value |
- | polygon | 1 |
- | polygon | 0 |
| polygon_text | 1 |
| polygon_text | 0 |
| polygon_kml | 1 |
| json | geotext |
| jsonv2 | geotext |
- Scenario Outline: Search result contains polygon-as-points geometry
- When sending <format> search query "Highmore"
- | polygon |
- | 1 |
- Then result has attributes <response_attribute>
-
- Examples:
- | format | response_attribute |
- | xml | polygonpoints |
- | json | polygonpoints |
- | jsonv2 | polygonpoints |
-
Scenario Outline: Search result contains SVG geometry
When sending <format> search query "Highmore"
| polygon_svg |
Scenario Outline: Search result in geojson format contains no non-geojson geometry
When sending geojson search query "Highmore"
- | polygon_text | polygon | polygon_svg | polygon_geokml |
- | 1 | 1 | 1 | 1 |
+ | polygon_text | polygon_svg | polygon_geokml |
+ | 1 | 1 | 1 |
Then result 0 has not attributes <response_attribute>
Examples:
| parameter | value |
| addressdetails | 1 |
| addressdetails | 0 |
- | polygon | 1 |
- | polygon | 0 |
| polygon_text | 1 |
| polygon_text | 0 |
| polygon_kml | 1 |
Then result header contains
| attr | value |
| querystring | xnznxvcx |
- | polygon | false |
| more_url | .*q=xnznxvcx.*format=xml |
Scenario: Empty XML search with special XML characters
Then result header contains
| attr | value |
| querystring | xfdghn&zxn"xvbyx<vxx>cssdex |
- | polygon | false |
| more_url | .*q=xfdghn%26zxn%22xvbyx%3Cvxx%3Ecssdex.*format=xml |
Scenario: Empty XML search with viewbox
Then result header contains
| attr | value |
| querystring | xnznxvcx |
- | polygon | false |
| viewbox | 12,33,77,45.13 |
Scenario: Empty XML search with viewboxlbrt
Then result header contains
| attr | value |
| querystring | xnznxvcx |
- | polygon | false |
| viewbox | 12,34.13,77,45 |
Scenario: Empty XML search with viewboxlbrt and viewbox
Then result header contains
| attr | value |
| querystring | pub |
- | polygon | false |
| viewbox | 12,33,77,45.13 |
- Scenario Outline: Empty XML search with polygon values
- When sending xml search query "xnznxvcx"
- | param | value |
- | polygon | <polyval> |
- Then result header contains
- | attr | value |
- | polygon | <result> |
-
- Examples:
- | result | polyval |
- | false | 0 |
- | true | 1 |
- | true | True |
- | true | true |
- | true | false |
- | true | FALSE |
- | true | yes |
- | true | no |
- | true | '; delete from foobar; select ' |
-
Scenario: Empty XML search with exluded place ids
When sending xml search query "jghrleoxsbwjer"
| exclude_place_ids |
);
}
-
- public function testGeometryText2Points()
- {
- $fRadius = 1;
- // invalid value
- $this->assertEquals(
- null,
- geometryText2Points('', $fRadius)
- );
-
- // POINT
- $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
- $this->assertEquals(
- 101,
- count($aPoints)
- );
- $this->assertEquals(
- array(
- array(10, 21),
- array(10.062790519529, 20.998026728428),
- array(10.125333233564, 20.992114701314)
- ),
- array_splice($aPoints, 0, 3)
- );
-
- // POLYGON
- $this->assertEquals(
- array(
- array('30', '10'),
- array('40', '40'),
- array('20', '40'),
- array('10', '20'),
- array('30', '10')
- ),
- geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
- );
-
- // MULTIPOLYGON
- $this->assertEquals(
- array(
- array('30', '20'), // first polygon only
- array('45', '40'),
- array('10', '40'),
- array('30', '20'),
- ),
- geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)
- );
- }
-
public function testParseLatLon()
{
// no coordinates expected