[Linpha-cvs] SF.net SVN: linpha: [4847] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <bz...@us...> - 2008-02-01 18:08:19
|
Revision: 4847 http://linpha.svn.sourceforge.net/linpha/?rev=4847&view=rev Author: bzrudi Date: 2008-02-01 10:08:14 -0800 (Fri, 01 Feb 2008) Log Message: ----------- Add new file modules.geodata.php Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/index.php trunk/linpha2/lib/plugins/maps/module.maps.php trunk/linpha2/lib/plugins/maps/xml_parser.class.php Added Paths: ----------- trunk/linpha2/lib/modules/module.geodata.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2008-02-01 13:37:03 UTC (rev 4846) +++ trunk/linpha2/ChangeLog 2008-02-01 18:08:14 UTC (rev 4847) @@ -3,6 +3,8 @@ for getting all required timestamps (starttime/endtime) from xml file as well as the image EXIF datetimeoriginal tag from all images in folder. * Add some required new methods to LinMetaData() class + * Add new file modules.geodata.php for testing all geodata stuff + * some basic test work alright now 2008-01-31 bzrudi * Maps plugin Modified: trunk/linpha2/index.php =================================================================== --- trunk/linpha2/index.php 2008-02-01 13:37:03 UTC (rev 4846) +++ trunk/linpha2/index.php 2008-02-01 18:08:14 UTC (rev 4847) @@ -64,6 +64,9 @@ case 'download': require_once(LINPHA_DIR.'/lib/modules/module.download.php'); break; +case 'geodata': + require_once(LINPHA_DIR.'/lib/modules/module.geodata.php'); + break; case 'empty': require_once(LINPHA_DIR.'/lib/modules/module.empty.php'); break; Added: trunk/linpha2/lib/modules/module.geodata.php =================================================================== --- trunk/linpha2/lib/modules/module.geodata.php (rev 0) +++ trunk/linpha2/lib/modules/module.geodata.php 2008-02-01 18:08:14 UTC (rev 4847) @@ -0,0 +1,44 @@ +<?php +/* + * Copyright (c) 2005 Heiko Rutenbeck <bz...@tu...> + * Florian Angehrn + * + * 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 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +if (!defined('LINPHA_DIR')) { exit (1); } +include_once LINPHA_DIR.'/lib/plugins/maps/xml_parser.class.php'; + +$GPXData = new LinXmlParser(); +$array_with_gpx = $GPXData->readXmlFile('/tmp/sample.gpx'); +$track_times = $GPXData->getGpxTimeRange($array_with_gpx); +$image_times = $GPXData->getImageTimeRange(41); //parent_id linpha_photos + +echo "<br>***OFFSET CHECKING***"; + +if($GPXData->compareTimeRanges($track_times, $image_times)) +{ + echo "<br>Time range OK, going checking offset<br>"; + $GPXData->fixImagesOffset($track_times, $image_times); +} +else +{ + echo "<br>Time Range error - images time range is larger than track time"; + echo "ABORT"; +} + + +//echo "<pre>", print_r($array_with_gpx), "</pre>"; +?> \ No newline at end of file Modified: trunk/linpha2/lib/plugins/maps/module.maps.php =================================================================== --- trunk/linpha2/lib/plugins/maps/module.maps.php 2008-02-01 13:37:03 UTC (rev 4846) +++ trunk/linpha2/lib/plugins/maps/module.maps.php 2008-02-01 18:08:14 UTC (rev 4847) @@ -23,23 +23,7 @@ * @package Plugins */ if(!defined('LINPHA_DIR')) { exit(1); } -include_once LINPHA_DIR.'/lib/plugins/maps/xml_parser.class.php'; -$GPXData = new LinXmlParser(); -$array_with_gpx = $GPXData->readXmlFile('/tmp/sample.gpx'); -$track_times = $GPXData->getGpxTimeRange($array_with_gpx); -$image_times = $GPXData->getImageTimeRange(19); -if($GPXData->compareTimeRanges($track_times, $image_times)) -{ - echo " ALL OK"; - } - else - { - echo "TRACK ERROR"; - } - -//echo "<pre>", print_r($array_with_gpx), "</pre>"; - /** * xml load/save stuff */ @@ -146,7 +130,7 @@ { if( !isset($_POST['linInputZoom']) OR empty($_POST['linInputZoom']) ) { - $_POST['linInputZoom'] = $GLOBALS['linpha']->sql->config->value['plugins_maps_defaultMarkerZoom']; + //echo "<pre>", print_r($array_with_gpx), "</pre>"; $_POST['linInputZoom'] = $GLOBALS['linpha']->sql->config->value['plugins_maps_defaultMarkerZoom']; } if( $_POST['cmd'] == 'saveMarker' ) Modified: trunk/linpha2/lib/plugins/maps/xml_parser.class.php =================================================================== --- trunk/linpha2/lib/plugins/maps/xml_parser.class.php 2008-02-01 13:37:03 UTC (rev 4846) +++ trunk/linpha2/lib/plugins/maps/xml_parser.class.php 2008-02-01 18:08:14 UTC (rev 4847) @@ -163,19 +163,19 @@ } } - echo "MIN ".$date_min." -- "; - echo "MAX ".$date_max; - echo " DIFF ".($date_max - $date_min)."<br>"; - echo "TRACK START AM:".date("Y-m-d, H-i-s", $date_min); - echo " TRACK ENDE UM:".date("Y-m-d, H-i-s", $date_max)."<br>"; - + echo "**TRACK INFO**<br>"; + echo "min ".$date_min." -- "; + echo "max ".$date_max; + echo " length ".($date_max - $date_min)."<br>"; + echo "track starts from: ".date("Y:m:d H:i:s", $date_min); + echo " track ends at: ".date("Y:m:d H:i:s", $date_max)."<br><br>"; + return array("starttime" => $date_min, "endtime" => $date_max); } - - + /** - * This method checks parses all images in folder and get's start and - * end date/time. + * This method checks parses all images in folder and get's start and + * end date/time. * @param int parent_id for images to parse * @return array (starttime, endtime); * @author bzrudi @@ -201,6 +201,12 @@ $current_time = $metaData->getDateTimeOriginal($filename); $current_time = $this->date2unixTime($current_time); + /** + * Buffer data, so we don't need to read image header again + * and again + */ + $geodata[$current_time] = $filename; + if($current_time < $date_min) { $date_min = $current_time; @@ -211,14 +217,15 @@ } } } - echo "MIN ".$date_min." -- "; - echo "MAX ".$date_max; - echo "DIFF ".($date_max - $date_min)."<br>"; - - echo "IMAGE START AM:".date("Y-m-d, H-i-s", $date_min); - echo " IMAGE ENDE UM:".date("Y-m-d, H-i-s", $date_max); - - return array("starttime" => $date_min, "endtime" => $date_max); + echo "**IMAGE INFO**<br>"; + echo "min ".$date_min." -- "; + echo "max ".$date_max; + echo " length ".($date_max - $date_min)."<br>"; + + echo "images start from: ".date("Y:m:d H:i:s", $date_min); + echo " images end at: ".date("Y:m:d H:i:s", $date_max)."<br>"; + + return array("starttime" => $date_min, "endtime" => $date_max, "geodata" => $geodata); } /** @@ -235,7 +242,7 @@ * Example EXIF 2007:07:17 09:25:16 */ unset($time_unix); - + $year = substr($datetime, 0, 4); $month = substr($datetime, 5, 2); $day = substr($datetime, 8, 2); @@ -245,9 +252,9 @@ $time_unix = mktime($hour, $min, $sec, $month, $day, $year); return $time_unix; } - + /** - * Compare time ranges for track and images. E.g time range for images + * Compare time ranges for track and images. E.g time range for images * must be smaller than the range for tracks. * @param $array start/endtime track * @param $array start/endtime images @@ -258,7 +265,7 @@ { $time_track = ($track['endtime'] - $track['starttime']); $time_images = ($images['endtime'] - $images['starttime']); - + if($time_images <= $time_track) { return true; @@ -267,8 +274,84 @@ { return false; } - } + } + /** + * Check for offset. E.g. all images must be taken within track time range + * + */ + public function fixImagesOffset($track, $images) + { + /** + * Number off imges out of sync + */ + $no_offsync = '0'; + + if($images['starttime'] < $track['starttime']) + { + echo "Offset detected, images start earlier...<br>"; + print_r($images['geodata']); + } + elseif($images['endtime'] > $track['endtime']) + { + echo "Offset detected, images end later...<br>"; + + $number = count($images['geodata']); + + while(list($image_time, $filename) = each($images['geodata'])) + { + if($image_time > $track['endtime']) + { + $no_offsync++; + $files_offsync[] = $filename; + } + } + echo "$no_offsync "."out of ".$number ." images are out of sync...<br>"; + echo "We have an offset of ".($images['endtime']-$track['endtime'])." " . + "seconds, which is about ".(($images['endtime']-$track['endtime'])/3600)." hours"; + echo "<br>Calibrating...<br>"; + + if($no_offsync > '0') + { + $full_hour = round(($images['endtime']-$track['endtime'])/3600, '0'); + + if($full_hour != '0') + { + echo "Usually offset is because of wrong UTC/GMT settings, so " . + "trying full hours first<br>"; + echo "Setting full hour offset to ".$full_hour." h<br>"; + echo "Faking image times... new setting -$full_hour h<br>"; + + $offset = ($full_hour*3600); + + } + else + { + echo "Danm, looks like we have an time skew < 1h - not so good<br>"; + echo "Setting offset to 5 min...<br>"; + echo "Faking image times... new setting -5 min<br>"; + + $offset = '300'; + } + + foreach($images['geodata'] AS $image_time => $filename) + { + $geo_tmp[($image_time-$offset)] = $filename; + } + + $image_tmp = array("starttime" => ($images['starttime'] - $offset), + "endtime" => ($images['endtime'] - $offset), + "geodata" => $geo_tmp ); + + echo "Rerunning offset test...<br>"; + $this->fixImagesOffset($track, $image_tmp); + } + } + else + { + echo "***BINGO ALL IMAGES ARE NOW WITHIN TRACK TIME RANGE***<br>"; + } + } }// end class /* vi: set ts=4 sw=4 sts=4 */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |