}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit;
- header('Content-type: text/html; charset=utf-8');
- if (CONST_ClosedForIndexing && strpos(CONST_ClosedForIndexingExceptionIPs, ','.$_SERVER["REMOTE_ADDR"].',') === false)
- {
- echo "Closed for re-indexing...";
- exit;
- }
-
- $aBucketKeys = array();
-
- if (isset($_SERVER["HTTP_REFERER"])) $aBucketKeys[] = str_replace('www.','',strtolower(parse_url($_SERVER["HTTP_REFERER"], PHP_URL_HOST)));
- if (isset($_SERVER["REMOTE_ADDR"])) $aBucketKeys[] = $_SERVER["REMOTE_ADDR"];
- if (isset($_GET["email"])) $aBucketKeys[] = $_GET["email"];
-
- $fBucketVal = doBucket($aBucketKeys,
- (defined('CONST_ConnectionBucket_PageType')?constant('CONST_ConnectionBucket_Cost_'.CONST_ConnectionBucket_PageType):1) + user_busy_cost(),
- CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
-
- if ($fBucketVal > CONST_ConnectionBucket_WaitLimit && $fBucketVal < CONST_ConnectionBucket_BlockLimit)
- {
- $m = getBucketMemcache();
- $iCurrentSleeping = $m->increment('sleepCounter');
- if (false === $iCurrentSleeping)
- {
- $m->add('sleepCounter', 0);
- $iCurrentSleeping = $m->increment('sleepCounter');
- }
- if ($iCurrentSleeping >= CONST_ConnectionBucket_MaxSleeping || isBucketSleeping($aBucketKeys))
- {
- // Too many threads sleeping already. This becomes a hard block.
- $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_BlockLimit, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
- }
- else
- {
- setBucketSleeping($aBucketKeys, true);
- sleep(($fBucketVal - CONST_ConnectionBucket_WaitLimit)/CONST_ConnectionBucket_LeakRate);
- $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
- setBucketSleeping($aBucketKeys, false);
- }
- $m->decrement('sleepCounter');
- }
-
- if (strpos(CONST_BlockedIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false || $fBucketVal >= CONST_ConnectionBucket_BlockLimit)
- {
- header("HTTP/1.0 429 Too Many Requests");
- echo "Your IP has been blocked. \n";
- echo CONST_BlockMessage;
- exit;
- }
-
+ header('Content-type: text/html; charset=utf-8');
-
return array('lat' => $fQueryLat, 'lon' => $fQueryLon, 'query' => $sQuery);
}
- elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch))
+
+
+ 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));
+ $fStepSize = (2*pi())/$iSteps;
+ $aPolyPoints = array();
+ for($f = 0; $f < 2*pi(); $f += $fStepSize)
+ {
+ $aPolyPoints[] = array('', $fLon+($fRadius*sin($f)), $fLat+($fRadius*cos($f)) );
+ }
+ return $aPolyPoints;
+ }
require_once(CONST_BasePath.'/lib/PlaceLookup.php');
require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
- if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
- {
- $fLoadAvg = getLoadAverage();
- if ($fLoadAvg > 2) sleep(60);
- if ($fLoadAvg > 4) sleep(120);
- if ($fLoadAvg > 6)
- {
- echo "Bulk User: Temporary block due to high server load\n";
- exit;
- }
- }
-
-
+ $bAsPoints = false;
+ $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson'];
+ $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml'];
+ $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg'];
+ $bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text'];
+ if ( ( ($bAsGeoJSON?1:0)
+ + ($bAsKML?1:0)
+ + ($bAsSVG?1:0)
+ + ($bAsText?1:0)
+ + ($bAsPoints?1:0)
+ ) > CONST_PolygonOutput_MaximumTypes)
+ {
+ if (CONST_PolygonOutput_MaximumTypes)
+ {
+ userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
+ }
+ else
+ {
+ userError("Polygon output is disabled");
+ }
+ exit;
+ }
+
+
+ // Polygon simplification threshold (optional)
+ $fThreshold = 0.0;
+ if (isset($_GET['polygon_threshold'])) $fThreshold = (float)$_GET['polygon_threshold'];
+
+
$oDB =& getDB();
ini_set('memory_limit', '200M');