[Mapbender-commits] r9566 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Aug 31 08:06:25 PDT 2016


Author: armin11
Date: 2016-08-31 08:06:23 -0700 (Wed, 31 Aug 2016)
New Revision: 9566

Added:
   trunk/mapbender/http/php/mod_transformTimeDimension.php
Log:
First draft for a serverside module to transform wms time extent information into json conf files for javascript based timeline configurations

Added: trunk/mapbender/http/php/mod_transformTimeDimension.php
===================================================================
--- trunk/mapbender/http/php/mod_transformTimeDimension.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_transformTimeDimension.php	2016-08-31 15:06:23 UTC (rev 9566)
@@ -0,0 +1,110 @@
+<?php
+# 
+# http://www.mapbender.org/index.php/mod_transformTimeDimension.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Module to transform the wms time dimension extent element into a json configuration for an javascript timeline plugin via ajax calls
+# See http://visjs.org/examples/timeline/dataHandling/loadExternalData.html
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+$objDateTime = new DateTime('NOW');
+$maxEntries = 40;
+$kindOfExtent = "singleValue"; //interval, discreteValues, intervalWithDuration
+$extent = $objDateTime->format($objDateTime::ATOM);
+//http://stackoverflow.com/questions/21686539/regular-expression-for-full-iso-8601-date-syntax
+//http://stackoverflow.com/questions/12756159/regex-and-iso8601-formated-datetime
+$iso8601Pattern = '/^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$/i';	
+if (isset($_REQUEST["extent"]) & $_REQUEST["extent"] != "") {
+	$testMatch = $_REQUEST["extent"];
+	//search for comma
+	if (strpos($testMatch,',') !== false) {
+		//found single discrete values
+		$singleValues = explode(',',$testMatch);
+		//test format of each value 
+		foreach ($singleValues as $dateTime) {
+			if (!preg_match($iso8601Pattern,$dateTime)){
+				echo 'The value for the <b>extent</b> parameter is not csv list of a valid iso8601 dateTime strings.<br/>'; 
+				die(); 		
+ 			}
+		}
+		$kindOfExtent = "discreteValues";
+	} elseif (strpos($testMatch,'/') !== false) {
+		//found interval with duration
+		//extract values
+		if (count(explode('/',$testMatch)) !== 3 ) {
+			echo 'The value for the <b>extent</b> parameter is not a valid iso8601 time duration string.<br/>'; 
+			die(); 	
+		} else {
+			$singleValues = explode('/',$testMatch);
+			//check the first 2 entries for iso8601 strings	
+			for ($i=0; $i < 2; $i++) {
+				if (!preg_match($iso8601Pattern,$singleValues[$i])){
+					echo 'The first two parts of the value for the <b>extent</b> parameter are not valid iso8601 dateTime strings.<br/>'; 
+					die(); 		
+ 				}
+			}
+			//check duration string
+			$iso8601DurationPattern = '/^P(?=\w*\d)(?:\d+Y|Y)?(?:\d+M|M)?(?:\d+W|W)?(?:\d+D|D)?(?:T(?:\d+H|H)?(?:\d+M|M)?(?:\d+(?:\­.\d{1,2})?S|S)?)?$/';	
+			if (!preg_match($iso8601DurationPattern,$singleValues[2])) {
+				echo 'The third part of the value for the <b>extent</b> parameter is not a valid iso8601 duration string.<br/>'; 
+				die(); 	
+			}
+		}
+		$kindOfExtent = "intervalWithDuration";
+	} elseif (!preg_match($iso8601Pattern,$testMatch)) {
+		echo 'The value for the <b>extent</b> parameter is not a valid iso8601 dateTime string.<br/>'; 
+		die(); 	
+	}
+	//everything is allright
+	$extent = $testMatch;
+	$testMatch = NULL;
+	
+}
+switch ($kindOfExtent) {
+	case "intervalWithDuration":
+		//calculate discrete points
+		$interval = explode('/',$extent);
+		$startTime = new DateTime($interval[0]);
+		$endTime = new DateTime($interval[1]);
+		$duration = new DateInterval($interval[2]);
+		$diffTime = $startTime->diff($endTime);
+		$diffTimeSeconds = $diffTime->format('%R%a')*(3600*24);
+		//Problem: DateInterval cannot be directly converted into seconds - only days are possible
+		$seconds = $duration->s + $duration->i * 60 + $duration->h * 3600 + $duration->days * (3600*24); 
+		$numberOfDiscreteValues = $diffTimeSeconds / $seconds;
+		if ($numberOfDiscreteValues > $maxEntries) {
+			echo "Number of possible discrete values: ".$numberOfDiscreteValues." exeeds max allowed number for visualization of timeline: ".$maxEntries."!";
+			die();
+		} else {
+			//push json values 
+		}	
+		break;
+	case "discreteValues":
+		if (count(explode(',',$extent)) > $maxEntries) {
+			echo "Number of discrete values: ".count(explode(',',$extent))." exeeds max allowed number for visualization of timeline: ".$maxEntries."!";
+			die();
+		} else {
+			//push json values
+			echo $extent;
+		}
+		break;
+	case "singleValue":
+			//push json values
+			echo $extent;
+		break;
+}
+?>



More information about the Mapbender_commits mailing list