+ * Check if the search is geographically restricted.
+ *
+ * Searches are restricted if a reference point is given or if
+ * a bounded viewbox is set.
+ *
+ * @return bool True, if the search is geographically bounded.
+ */
+ public function isBoundedSearch()
+ {
+ return $this->hasNearPoint() || ($this->sqlViewboxSmall && $this->bViewboxBounded);
+ }
+
+ /**
+ * Set rectangular viewbox.
+ *
+ * The viewbox may be bounded which means that no search results
+ * must be outside the viewbox.
+ *
+ * @param float[4] $aViewBox Coordinates of the viewbox.
+ * @param bool $bBounded True if the viewbox is bounded.
+ *
+ * @return void
+ */
+ public function setViewboxFromBox(&$aViewBox, $bBounded)
+ {
+ $this->bViewboxBounded = $bBounded;
+ $this->sqlViewboxCentre = '';
+
+ $this->sqlViewboxSmall = sprintf(
+ 'ST_SetSRID(ST_MakeBox2D(ST_Point(%F,%F),ST_Point(%F,%F)),4326)',
+ $aViewBox[0],
+ $aViewBox[1],
+ $aViewBox[2],
+ $aViewBox[3]
+ );
+
+ $fHeight = abs($aViewBox[0] - $aViewBox[2]);
+ $fWidth = abs($aViewBox[1] - $aViewBox[3]);
+
+ $this->sqlViewboxLarge = sprintf(
+ 'ST_SetSRID(ST_MakeBox2D(ST_Point(%F,%F),ST_Point(%F,%F)),4326)',
+ max($aViewBox[0], $aViewBox[2]) + $fHeight,
+ max($aViewBox[1], $aViewBox[3]) + $fWidth,
+ min($aViewBox[0], $aViewBox[2]) - $fHeight,
+ min($aViewBox[1], $aViewBox[3]) - $fWidth
+ );
+ }
+
+ /**
+ * Set viewbox along a route.
+ *
+ * The viewbox may be bounded which means that no search results
+ * must be outside the viewbox.
+ *
+ * @param object $oDB Nominatim::DB instance to use for computing the box.
+ * @param string[] $aRoutePoints List of x,y coordinates along a route.
+ * @param float $fRouteWidth Buffer around the route to use.
+ * @param bool $bBounded True if the viewbox bounded.
+ *
+ * @return void
+ */
+ public function setViewboxFromRoute(&$oDB, $aRoutePoints, $fRouteWidth, $bBounded)
+ {
+ $this->bViewboxBounded = $bBounded;
+ $this->sqlViewboxCentre = "ST_SetSRID('LINESTRING(";
+ $sSep = '';
+ foreach ($aRoutePoints as $aPoint) {
+ $fPoint = (float)$aPoint;
+ $this->sqlViewboxCentre .= $sSep.$fPoint;
+ $sSep = ($sSep == ' ') ? ',' : ' ';
+ }
+ $this->sqlViewboxCentre .= ")'::geometry,4326)";
+
+ $sSQL = 'ST_BUFFER('.$this->sqlViewboxCentre.','.($fRouteWidth/69).')';
+ $sGeom = $oDB->getOne('select '.$sSQL, null, 'Could not get small viewbox');
+ $this->sqlViewboxSmall = "'".$sGeom."'::geometry";
+
+ $sSQL = 'ST_BUFFER('.$this->sqlViewboxCentre.','.($fRouteWidth/30).')';
+ $sGeom = $oDB->getOne('select '.$sSQL, null, 'Could not get large viewbox');
+ $this->sqlViewboxLarge = "'".$sGeom."'::geometry";
+ }
+
+ /**
+ * Set list of excluded place IDs.
+ *
+ * @param integer[] $aExcluded List of IDs.
+ *
+ * @return void
+ */
+ public function setExcludeList($aExcluded)
+ {
+ $this->sqlExcludeList = ' not in ('.join(',', $aExcluded).')';
+ }
+
+ /**
+ * Set list of countries to restrict search to.
+ *
+ * @param string[] $aCountries List of two-letter lower-case country codes.
+ *
+ * @return void
+ */
+ public function setCountryList($aCountries)
+ {
+ $this->sqlCountryList = '('.join(',', array_map('addQuotes', $aCountries)).')';
+ }
+
+ /**
+ * Extract a reference point from a query string.