[Linpha-cvs] SF.net SVN: linpha: [4848] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <bz...@us...> - 2008-02-02 13:11:43
|
Revision: 4848 http://linpha.svn.sourceforge.net/linpha/?rev=4848&view=rev Author: bzrudi Date: 2008-02-02 05:11:40 -0800 (Sat, 02 Feb 2008) Log Message: ----------- even more improvements to gpx stuff Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/lib/modules/module.geodata.php trunk/linpha2/lib/plugins/maps/xml_parser.class.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2008-02-01 18:08:14 UTC (rev 4847) +++ trunk/linpha2/ChangeLog 2008-02-02 13:11:40 UTC (rev 4848) @@ -1,3 +1,9 @@ +2008-02-02 bzrudi + * It should now be possible to auto adjust images to fit tracks AND to auto + assign images to closest/nearest trackpoint in GPX file using some offset + logic. + - add some new methods for this + 2008-02-01 bzrudi * More improvements to XML parser class. XML/GPX parsing works now, same for getting all required timestamps (starttime/endtime) from xml file as @@ -4,7 +10,7 @@ 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 + * some basic tests work alright now 2008-01-31 bzrudi * Maps plugin Modified: trunk/linpha2/lib/modules/module.geodata.php =================================================================== --- trunk/linpha2/lib/modules/module.geodata.php 2008-02-01 18:08:14 UTC (rev 4847) +++ trunk/linpha2/lib/modules/module.geodata.php 2008-02-02 13:11:40 UTC (rev 4848) @@ -21,8 +21,8 @@ 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'); +$GPXData = new LinXmlParser('/tmp/sample.gpx'); +$array_with_gpx = $GPXData->readXmlFile(); $track_times = $GPXData->getGpxTimeRange($array_with_gpx); $image_times = $GPXData->getImageTimeRange(41); //parent_id linpha_photos @@ -31,7 +31,7 @@ if($GPXData->compareTimeRanges($track_times, $image_times)) { echo "<br>Time range OK, going checking offset<br>"; - $GPXData->fixImagesOffset($track_times, $image_times); + $GPXData->fixImagesOffset($track_times, $image_times, $image_tmp=array()); } else { Modified: trunk/linpha2/lib/plugins/maps/xml_parser.class.php =================================================================== --- trunk/linpha2/lib/plugins/maps/xml_parser.class.php 2008-02-01 18:08:14 UTC (rev 4847) +++ trunk/linpha2/lib/plugins/maps/xml_parser.class.php 2008-02-02 13:11:40 UTC (rev 4848) @@ -31,9 +31,9 @@ private $data, $parser, $filename, $values, $index_array; private $data_range, $gpx, $xml_data , $meta_data; - function __construct() + function __construct($filename) { - + $this->filename = $filename; } /** @@ -56,12 +56,12 @@ * @param string $filename * @return array with all trackpoints */ - public function readXmlFile($filename) + public function readXmlFile() { /** * open and parse xml file for Track data */ - $this->data = file_get_contents($filename); + $this->data = file_get_contents($this->filename); $this->parser = xml_parser_create(); /** @@ -254,9 +254,10 @@ } /** - * 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 + * Check for offset. E.g. all images must be taken within track time range + * Delta t for the first and last image must be smaller than delta t for + * the gpx track, this method takes care of it. + * @param $array $track start/endtime track * @param $array start/endtime images * @return bool true/false * @author bzrudi @@ -277,13 +278,16 @@ } /** - * Check for offset. E.g. all images must be taken within track time range - * - */ - public function fixImagesOffset($track, $images) + * All images must be taken within track time range delta t. If we found + * images taken earlier or later, fix it! + * @param $array $track start/endtime track + * @param $array start/endtime images + * @author bzrudi + */ + public function fixImagesOffset($track, $images) //, $image_tmp { /** - * Number off imges out of sync + * Number of images out of sync */ $no_offsync = '0'; @@ -297,7 +301,7 @@ echo "Offset detected, images end later...<br>"; $number = count($images['geodata']); - + //print_r($images['geodata']); while(list($image_time, $filename) = each($images['geodata'])) { if($image_time > $track['endtime']) @@ -314,26 +318,26 @@ 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 " . + 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); - + 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'; + 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; @@ -342,16 +346,108 @@ $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>"; + echo "<br>***BINGO ALL IMAGES ARE NOW WITHIN TRACK TIME RANGE***<br>"; + $this->triggerImage2trkpt($images); } } + + /** + * This method is mainly a wrapper function for trkptradar() which does + * the main work when finding nearest trackpoint + * @param array $images with all data read from the files + * @author bzrudi + * @return none (yet) + */ + private function triggerImage2trkpt($images) + { + /** + * @todo mv to __constructor + */ + $gpx = $this->readXmlFile($this->filename); + + ksort($images['geodata']); + ksort($gpx); + + /** + * Create new array with all needed information sorted + */ + foreach($gpx AS $index => $value) + { + + $trkdata[$this->date2unixTime($value['time'])] = + array("time" => $this->date2unixTime($value['time']), + "lat" => $value['trkpt']['lat'], + "lon" => $value['trkpt']['lon']); + } + + echo "<br>***CALLING TRACKPOINT RADAR***<br>"; + + foreach($images['geodata'] AS $image_time => $image_filename) + { + echo "Trying to find match for: ".$image_time." ".$image_filename."<br>"; + + $offset = '1'; + $loop = true; + + while($loop === true) + { + $loop = $this->trkptRadar($trkdata, $image_time, $offset); + $offset++; + } + } + } + + /** + * Trackpoint radar. Try to find nearest trkpt for image + * We do this by adding an offset (positiv and negativ) of one second to + * the original image_time until we got key hit. + * + * @param array $trkdata array with time and lat lon from gpx track + * @param int $image_time current image timestamp + * @param int $offset current offset in seconds + * @author bzrudi + * @return bool + */ + private function trkptRadar($trkdata, $image_time, $offset) + { + if(array_key_exists($image_time, $trkdata)) + { + echo "Got hit after: 0 loops ".$image_time; + echo "<br>Connecting image ".$image_time." " . + "<br>to LAT: ".$trkdata[$image_time]['lat']."<br>and LON: " . + "".$trkdata[$image_time]['lon']."<br><br>"; + return false; + } + elseif(array_key_exists(($image_time + $offset), $trkdata)) + { + echo "Got hit after: +".$offset." loops ".$image_time; + echo "<br>Connecting image ".$image_time." " . + "<br>to LAT: ".$trkdata[$image_time + $offset]['lat']."<br>and LON: " . + "".$trkdata[$image_time + $offset]['lon']."<br><br>"; + return false; + } + elseif(array_key_exists(($image_time - $offset), $trkdata)) + { + echo "Got hit after: -".$offset." loops ".$image_time; + echo "<br>Connecting image ".$image_time." " . + "<br>to LAT: ".$trkdata[$image_time - $offset]['lat']."<br>and LON: " . + "".$trkdata[$image_time - $offset]['lon']."<br><br>"; + return false; + } + else + { + flush(); + return true; + } + + } }// 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. |