--- a/labs/tripPlannerTester.kml.php +++ b/labs/tripPlannerTester.kml.php @@ -1,10 +1,61 @@ > 16; + $theG0 = ($theColorBegin & 0x00ff00) >> 8; + $theB0 = ($theColorBegin & 0x0000ff) >> 0; + $theR1 = ($theColorEnd & 0xff0000) >> 16; + $theG1 = ($theColorEnd & 0x00ff00) >> 8; + $theB1 = ($theColorEnd & 0x0000ff) >> 0; + $GradientColors = array(); + // generate gradient swathe now + for ($i = 0; $i <= $theNumSteps; $i++) { + $theR = interpolate($theR0, $theR1, $i, $theNumSteps); + $theG = interpolate($theG0, $theG1, $i, $theNumSteps); + $theB = interpolate($theB0, $theB1, $i, $theNumSteps); + $theVal = ((($theR << 8) | $theG) << 8) | $theB; + $GradientColors[] = sprintf("%06X", $theVal); + } + return $GradientColors; +} +function processLeg($legNumber, $leg) +{ + $legArray = object2array($leg); + if ($legArray["@mode"] === "BUS") { + return "bus {$legArray['@route']} " . str_replace("To", "towards", $legArray['@headsign']); + } + else { + return "walk"; + //$walkingstep = "walk "; + //if (strpos($step->streetName, "from") !== false && strpos($step->streetName, "way") !== false) { + // $walkingstep.= "footpath"; + //} + //else { + // $walkingstep.= $step->streetName; + //} + //$walkingstep.= floor($step->distance) . "m"; + //return $walkingstep; + } +} $csv = false; $kml = true; if ($kml) { - header('Content-Type: application/vnd.google-earth.kml+xml'); -echo ' + //header('Content-Type: application/vnd.google-earth.kml+xml'); + echo ' '; } include ('../include/common.inc.php'); @@ -16,50 +67,48 @@ "startlon" => 149.0295, "finishlat" => - 35.2630, "finishlon" => 149.1045, - ) , + ) , "north gungahlin civic" => Array( - "startlat" => - 35.2652, + "startlat" => - 35.1828, "startlon" => 149.1045, - "finishlat" => -35.2955, - "finishlon" => 149.1559, + "finishlat" => - 35.2955, + "finishlon" => 149.1559, ) , - "west duffy" => Array( - "startlat" => - 35.3252, - "startlon" => 149.0240, - "finishlat" => - 35.3997, - "finishlon" => 149.0676, - ) , - "central south" => Array( - "startlat" => - 35.3042, - "startlon" => 149.0762, - "finishlat" => - 35.3370, - "finishlon" => 149.1806, - ) , - "south" => Array( - "startlat" => - 35.3403, - "startlon" => 149.0714, - "finishlat" => - 35.4607, - "finishlon" => 149.1243, - ) - + //"west duffy" => Array( + // "startlat" => - 35.3252, + // "startlon" => 149.0240, + // "finishlat" => - 35.3997, + // "finishlon" => 149.0676, + //) , + //"central south" => Array( + // "startlat" => - 35.3042, + // "startlon" => 149.0762, + // "finishlat" => - 35.3370, + // "finishlon" => 149.1806, + //) , + //"south" => Array( + // "startlat" => - 35.3403, + // "startlon" => 149.0714, + // "finishlat" => - 35.4607, + // "finishlon" => 149.1243, + //) ); -$latdeltasize = 0.025; -$londeltasize = 0.025; -$from = "Barry Drive"; +$latdeltasize = 0.01; +$londeltasize = 0.01; +$from = "Wattle Street"; $fromPlace = (startsWith($from, "-") ? $from : geocode($from, false)); $startTime = "9:00 am"; -$startDate = "21/03/2011"; +$startDate = "03/21/2011"; // american dates, OTP does not validate! $counter = 0; $regionTimes = Array(); $testRegions = Array(); $useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; if ($csv) echo "
";
 if ($csv) echo "lat,lon,time,latdeltasize, londeltasize, region key name\n";
-
 foreach ($boundingBoxes as $key => $boundingBox) {
 	for ($i = $boundingBox['startlat']; $i >= $boundingBox['finishlat']; $i-= $latdeltasize) {
 		for ($j = $boundingBox['startlon']; $j <= $boundingBox['finishlon']; $j+= $londeltasize) {
-			$url = $otpAPIurl . "ws/plan?date=" . urlencode($startDate) . "&time=" . urlencode($startTime) . "&mode=TRANSIT%2CWALK&optimize=QUICK&maxWalkDistance=840&wheelchair=false&toPlace=" . $i . "," . $j . "&fromPlace=$fromPlace&intermediatePlaces=";
+			$url = $otpAPIurl . "ws/plan?date=" . urlencode($startDate) . "&time=" . urlencode($startTime) . "&mode=TRANSIT%2CWALK&optimize=QUICK&maxWalkDistance=440&wheelchair=false&toPlace=" . $i . "," . $j . "&fromPlace=$fromPlace";
 			$ch = curl_init($url);
 			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 			curl_setopt($ch, CURLOPT_HEADER, 0);
@@ -74,102 +123,81 @@
 			else {
 				$tripplan = json_decode($page);
 				if (isset($tripplan->error)) var_dump($tripplan->error);
-				$times = Array();
+				$plans = Array();
 				if (is_array($tripplan->plan->itineraries->itinerary)) {
-					
 					foreach ($tripplan->plan->itineraries->itinerary as $itineraryNumber => $itinerary) {
-						$times[] = floor($itinerary->duration / 60000);
+						$plans[floor($itinerary->duration / 60000) ] = $itinerary;
 					}
-
 				}
 				else {
-					$times[] = floor($tripplan->plan->itineraries->itinerary->duration / 60000);
+					$plans[floor($tripplan->plan->itineraries->itinerary->duration / 60000) ] = $tripplan->plan->itineraries->itinerary;
 				}
-				if ($csv) echo "$i,$j," . min($times) . ",$latdeltasize, $londeltasize,$key\n";
+				if ($csv) echo "$i,$j," . min(array_keys($plans)) . ",$latdeltasize, $londeltasize,$key\n";
+				if ($kml) {
+					$time = min(array_keys($plans));
+					$plan = "";
+					if (is_array($plans[min(array_keys($plans)) ]->legs->leg)) {
+						foreach ($plans[min(array_keys($plans)) ]->legs->leg as $legNumber => $leg) {
+							$plan .= processLeg($legNumber, $leg).",";
+						}
+					}
+					else {
+						$plan .= processLeg(0, $plans[min(array_keys($plans)) ]->legs->leg);
+					}
+					$testRegions[] = Array(
+						"lat" => $i,
+						"lon" => $j,
+						"time" => $time,
+						"latdeltasize" => $latdeltasize,
+						"londeltasize" => $londeltasize,
+						"regionname" => $key,
+						"plan" => $plan . "
original plan" + ); + $regionTimes[] = $time; + } } flush(); ob_flush(); curl_close($ch); - $testRegions[] = Array ("lat" => $i, "lon" => $j, "time" => min($times), "latdeltasize" => $latdeltasize, "londeltasize" => $londeltasize, "regionname" => $key); - $regionTimes[] = min($times); - break; - } - break; - } -} - -// http://www.geekpedia.com/code163_Generate-Gradient-Within-Hex-Range-In-PHP.html -function Gradient($HexFrom, $HexTo, $ColorSteps) -{ - $FromRGB['r'] = hexdec(substr($HexFrom, 0, 2)); - $FromRGB['g'] = hexdec(substr($HexFrom, 2, 2)); - $FromRGB['b'] = hexdec(substr($HexFrom, 4, 2)); - - $ToRGB['r'] = hexdec(substr($HexTo, 0, 2)); - $ToRGB['g'] = hexdec(substr($HexTo, 2, 2)); - $ToRGB['b'] = hexdec(substr($HexTo, 4, 2)); - - $StepRGB['r'] = ($FromRGB['r'] - $ToRGB['r']) / ($ColorSteps - 1); - $StepRGB['g'] = ($FromRGB['g'] - $ToRGB['g']) / ($ColorSteps - 1); - $StepRGB['b'] = ($FromRGB['b'] - $ToRGB['b']) / ($ColorSteps - 1); - - $GradientColors = array(); - - for($i = 0; $i <= $ColorSteps; $i++) - { - $RGB['r'] = floor($FromRGB['r'] - ($StepRGB['r'] * $i)); - $RGB['g'] = floor($FromRGB['g'] - ($StepRGB['g'] * $i)); - $RGB['b'] = floor($FromRGB['b'] - ($StepRGB['b'] * $i)); - - $HexRGB['r'] = sprintf('%02x', ($RGB['r'])); - $HexRGB['g'] = sprintf('%02x', ($RGB['g'])); - $HexRGB['b'] = sprintf('%02x', ($RGB['b'])); - - $GradientColors[] = implode(NULL, $HexRGB); - } - return $GradientColors; -} - -if ($kml) { -$minTime = min($regionTimes); -$maxTime = max($regionTimes); -$rangeTime = $maxTime - $minTime; -$colorSteps = 32; -$deltaTime = $rangeTime / $colorSteps; - -$Gradients = Gradient("FF5B5B", "FFCA5B", $colorSteps); - -foreach ($testRegions as $testRegion) { - $band = (floor(($testRegion[time] - $minTime) / $deltaTime)); - echo " - ".$testRegion['regionname']." time {$testRegion[time]} band $band + } + } +} +if ($kml) { + $colorSteps = 18; + //$minTime = min($regionTimes); + //$maxTime = max($regionTimes); + //$rangeTime = $maxTime - $minTime; + //$deltaTime = $rangeTime / $colorSteps; + $Gradients = Gradient("66FF00", "FF0000", $colorSteps); + foreach ($testRegions as $testRegion) { + //$band = (floor(($testRegion[time] - $minTime) / $deltaTime)); + $band = (floor(($testRegion[time] / 10) *2)); + if ($band > $colorSteps) $band = $colorSteps; + echo " + " . $testRegion['regionname'] . " time {$testRegion['time']} band $band + {$testRegion['plan']} - 1 - relativeToGround +relativeToGround - ". ($testRegion['lon'] - ($testRegion['londeltasize']/2)) . "," . ($testRegion['lat'] - ($testRegion['latdeltasize']/2)).",0\n". - ($testRegion['lon'] - ($testRegion['londeltasize']/2)) . "," . ($testRegion['lat'] + ($testRegion['latdeltasize']/2)).",0\n". - ($testRegion['lon'] + ($testRegion['londeltasize']/2)) . "," . ($testRegion['lat'] + ($testRegion['latdeltasize']/2)).",0\n". - ($testRegion['lon'] + ($testRegion['londeltasize']/2)) . "," . ($testRegion['lat'] - ($testRegion['latdeltasize']/2)).",0\n". - ($testRegion['lon'] - ($testRegion['londeltasize']/2)) . "," . ($testRegion['lat'] - ($testRegion['latdeltasize']/2)).",0\n". - " + " . ($testRegion['lon'] - ($testRegion['londeltasize'] / 2)) . "," . ($testRegion['lat'] - ($testRegion['latdeltasize'] / 2)) . ",500\n" . ($testRegion['lon'] - ($testRegion['londeltasize'] / 2)) . "," . ($testRegion['lat'] + ($testRegion['latdeltasize'] / 2)) . ",500\n" . ($testRegion['lon'] + ($testRegion['londeltasize'] / 2)) . "," . ($testRegion['lat'] + ($testRegion['latdeltasize'] / 2)) . ",500\n" . ($testRegion['lon'] + ($testRegion['londeltasize'] / 2)) . "," . ($testRegion['lat'] - ($testRegion['latdeltasize'] / 2)) . ",500\n" . ($testRegion['lon'] - ($testRegion['londeltasize'] / 2)) . "," . ($testRegion['lat'] - ($testRegion['latdeltasize'] / 2)) . ",500\n" . " "; -} -echo "\n\n"; + } + echo "\n\n"; } if ($csv) echo "
"; - ?>