Browse files

Fixed several errors in geotagging code

- Wrong debugging code
- Insufficient checking for empty resultsets causing
  "undefined offsett" errors
- Refactor of other parts of Zoph not incorporated in
  Geotagging code.

Closes #31
  • Loading branch information...
1 parent bb41ce6 commit 994fb3a89a65b95a21a5fa73bd6738f4a2ad5a7c @jeroenrnl committed Sep 24, 2012
Showing with 36 additions and 19 deletions.
  1. +15 −11 php/photo.inc.php
  2. +14 −5 php/point.inc.php
  3. +7 −3 php/tracks.php
View
26 php/photo.inc.php
@@ -1489,6 +1489,8 @@ public function getLatLon(track $track=null, $max_time=300, $interpolate=true,
if($track) {
$track_id=$track->getId();
$where=" AND track_id=" . escape_string($track_id);
+ } else {
+ $where="";
}
$sql="SELECT * FROM " . DB_PREFIX . "point" .
@@ -1499,13 +1501,13 @@ public function getLatLon(track $track=null, $max_time=300, $interpolate=true,
" LIMIT 1";
$points=point::getRecordsFromQuery("point", $sql);
-
- $point=$points[0];
- if(get_class($piont)=="point") {
+ if(sizeof($points) > 0 && $points[0] instanceof point) {
+ $point=$points[0];
$pointtime=strtotime($point->get("datetime"));
} else {
// can't get a point, don't bother trying to interpolate.
- unset($interpolate);
+ $interpolate=false;
+ $point=null;
}
if($interpolate && ($pointtime != $utc)) {
@@ -1516,9 +1518,11 @@ public function getLatLon(track $track=null, $max_time=300, $interpolate=true,
$p1=$point->getPrev();
$p2=$point;
}
- $p3=$p1->interpolate($p2,$utc,$int_maxdist, $entity, $int_maxtime);
- if(get_class($p3)=="point") {
- $point=$p3;
+ if($p1 instanceof point && $p2 instanceof point) {
+ $p3=point::interpolate($p1,$p2,$utc,$int_maxdist, $entity, $int_maxtime);
+ if($p3 instanceof point) {
+ $point=$p3;
+ }
}
}
return $point;
@@ -1596,7 +1600,7 @@ public static function getSubset(array $photos, array $subset, $count) {
public static function removePhotosWithNoValidTZ(array $photos) {
$gphotos=array();
- log::msg("Number of photos before valid timezone check: " . count($photos), log::GEOTAG, log::DEBUG);
+ log::msg("Number of photos before valid timezone check: " . count($photos), log::DEBUG, log::GEOTAG);
foreach($photos as $photo) {
$photo->lookup();
@@ -1608,7 +1612,7 @@ public static function removePhotosWithNoValidTZ(array $photos) {
}
}
}
- log::msg("Number of photos after valid timezone check: " . count($gphotos), log::GEOTAG, log::DEBUG);
+ log::msg("Number of photos after valid timezone check: " . count($gphotos), log::DEBUG, log::GEOTAG);
return $gphotos;
}
@@ -1623,14 +1627,14 @@ public static function removePhotosWithNoValidTZ(array $photos) {
*/
public static function removePhotosWithLatLon($photos) {
$gphotos=array();
- log::msg("Number of photos before overwrite check: " . count($photos), log::GEOTAG, log::DEBUG);
+ log::msg("Number of photos before overwrite check: " . count($photos), log::DEBUG, log::GEOTAG);
foreach($photos as $photo) {
$photo->lookup();
if(!($photo->get("lat") or $photo->get("lon"))) {
$gphotos[]=$photo;
}
}
- log::msg("Number of photos after overwrite check: " . count($gphotos), log::GEOTAG, log::DEBUG);
+ log::msg("Number of photos after overwrite check: " . count($gphotos), log::DEBUG, log::GEOTAG);
return $gphotos;
}
View
19 php/point.inc.php
@@ -83,8 +83,12 @@ public function getNext() {
" track_id = " . escape_string($this->get("track_id")) . " AND " .
" datetime>\"" . escape_string($this->get("datetime")) . "\"" .
" ORDER BY datetime LIMIT 1";
- $point=point::getRecordsFromQuery("point", $sql);
- return $point[0];
+ $points=point::getRecordsFromQuery("point", $sql);
+ if(is_array($points) && sizeof($points) > 0) {
+ return $points[0];
+ } else {
+ return null;
+ }
}
/**
@@ -95,8 +99,13 @@ public function getPrev() {
" track_id = " . escape_string($this->get("track_id")) . " AND " .
" datetime<\"" . escape_string($this->get("datetime")) . "\"" .
" ORDER BY datetime DESC LIMIT 1";
- $point=point::getRecordsFromQuery("point", $sql);
- return $point[0];
+ $points=point::getRecordsFromQuery("point", $sql);
+ if(is_array($points) && sizeof($points) > 0) {
+ return $points[0];
+ } else {
+ return null;
+ }
+ return $points[0];
}
/**
@@ -178,7 +187,7 @@ public static function interpolate(point $p1, point $p2,
}
if($maxdist) {
- $p1->getDistanceTo($p2, $entity);
+ $dist=$p1->getDistanceTo($p2, $entity);
if ($dist > $maxdist) {
return false;
}
View
10 php/tracks.php
@@ -39,6 +39,8 @@
$vars=clean_request_vars($request_vars);
$new_vars=update_query_string($vars, "_action", "do_geotag", array("_test", "_testcount"));
$photos;
+ $totalPhotoCount = get_photos($vars, 0, 999999999, $photos, $user);
+ $num_photos=sizeof($photos);
}
if($_action=="" || $_action=="display") {
@@ -55,8 +57,6 @@
} else if ($_action=="geotag") {
- $totalPhotoCount = get_photos($vars, 0, 999999999, $photos, $user);
- $num_photos=sizeof($photos);
if ($num_photos<= 0) {
$content=translate("No photos were found matching your search criteria.") . "\n";
} else {
@@ -81,11 +81,15 @@
$interpolate=getvar("_interpolate");
$int_maxdist=getvar("_int_maxdist");
$int_maxtime=getvar("_int_maxtime");
+ $entity=getvar("_entity");
+ $tphotos=array();
if($tracks!="all") {
$track_id=getvar("_track");
$track=new track($track_id);
$track->lookup();
+ } else {
+ $track=null;
}
if($validtz) {
@@ -114,7 +118,7 @@
}
$tagged=count($tphotos);
if($tagged>0) {
- $js;
+ $js="";
foreach ($tphotos as $photo) {
$js.=$photo->getMarker($user);
}

0 comments on commit 994fb3a

Please sign in to comment.