".$asSpan["EndTS"]." OR IFNULL(EndDate,-1)=-1) AND CarPK=".$lCarPK; if($oResult=$this->oSystem->oDB->goQuery($sQuery)) { return $oResult->gaaGetAllRecords(); } return false; } function CGISCatfinder(&$oSystem) { $this->oSystem=&$oSystem; $this->oDB=new CDatabase("gis"); } function gbLoadGeoCoder() { $sFile=PATHFW."GisCatfinder/geocode/class.gis.geocode.php"; if(!class_exists("CGISGeoCode")) { if(file_exists($sFile)) require_once($sFile); } if(class_exists("CGISGeoCode")) { $oGeoCoder=new CGISGeoCode($this->oSystem,$this->oDB); return $oGeoCoder; } return false; } function gLoadCatFinder($oCar) { $sQuery="SELECT * FROM tdCatFinder WHERE CatfinderPK=".$oCar->GISCatfinderPK; if($oResult=$this->oDB->goQuery($sQuery)) { $this->oCatfinder=$oResult->goGetRecord(); $this->oCatfinder->TITLEBOX=$oCar->QSExternalCarName; $this->oCatfinder->ContractPK=str_pad($oCar->ContractPK,8,"0",STR_PAD_LEFT); return true; } return false; } function goGetCatfinderCurrent($lCatfinderPK) { // erwartet die CatfinderPK in der Positionsdatenbank, entspricht der RemotePK in den anderens Systemen! $sQuery="SELECT * FROM tdCatFinder WHERE CatfinderPK=".$lCatfinderPK; if($oResult=$this->oDB->goQuery($sQuery)) { if($oCatfinder=$oResult->goGetRecord()) { return $oCatfinder; } else { } } return false; } function gsGetImageVerlauf($lStartTime,$lEndTime,$x,$y) { $sQuery="SELECT *,SQRT(POWER(".$this->oCatfinder->Longitude."-(LonOL+((LonUR-LonOL)/2)),2)+POWER(".$this->oCatfinder->Latitude."-(LatUR+((LatOL-LatUR)/2)),2)) as LEN1 FROM tdMapFiles WHERE ".$this->oCatfinder->Latitude."oCatfinder->Latitude.">latUR and ".$this->oCatfinder->Longitude.">lonOL and ".$this->oCatfinder->Longitude."oDB->goQuery($sQuery)) { $oMap=$oResult->goGetRecord(); $sTableName="tdPositions_".date("Ymd",$this->oCatfinder->LastGPSTS); $sQuery="SELECT * FROM $sTableName WHERE CatfinderPK=".$this->oCatfinder->CatfinderPK." AND GPS_TS>".$lStartTime; if($oResult=$this->oDB->goQuery($sQuery)) { $aoTour=$oResult->gaoGetAllRecords(); } $oIMG=new CMapImage($this->oCatfinder,$oMap,$x,$y,$aoTour); } } function gsGetImagePosition($x,$y) { $sQuery="SELECT *,SQRT(POWER(".$this->oCatfinder->Longitude."-(LonOL+((LonUR-LonOL)/2)),2)+POWER(".$this->oCatfinder->Latitude."-(LatUR+((LatOL-LatUR)/2)),2)) as LEN1 FROM tdMapFiles WHERE ".$this->oCatfinder->Latitude."oCatfinder->Latitude.">latUR and ".$this->oCatfinder->Longitude.">lonOL and ".$this->oCatfinder->Longitude."oDB->goQuery($sQuery)) { $oMap=$oResult->goGetRecord(); $oIMG=new CMapImage($this->oCatfinder,$oMap,$x,$y,false); } } function gasGetVerlaufsData($lStartTime,$lEndTime) { $asTableList=$this->gasGetRelevantTables($lStartTime,$lEndTime); } function gaoLoadSpanData($as,$bSavePositions=false) { if($bSavePositions===true) { $this->aoPositions=array(); } // $as["StartTS"] [EndTS] $aoReturn=array(); if($as[0]["CatfinderPK"]=="132") { } if($aoResultSets=$this->gasLoadSpan($as)) { foreach($aoResultSets as $sKey=>$oResultSet) { if($oResultSet["ResultSet"]!==false) { $oCatfinder=$this->goGetCatfinderCurrent($oResultSet["CatfinderPK"]); $oDatahandler=$this->goLoadCatfinderDatahandler($oCatfinder); if($oDatahandler->gbSetPositionObjects($oResultSet["ResultSet"])) { $aoReturn[$sKey]=$oDatahandler->gaoGetSpanData($bSavePositions); if($bSavePositions===true) { $this->aoPositions=$this->aoPositions+$oDatahandler->aoPositions; } } unset($oDatahandler); } else { $aoReturn[$sKey]=false; } } } return $aoReturn; } function goGetHistogrammData($asSpan) { $aoData=$this->gaoLoadSpanData($asSpan,true); // positionsdaten speichern $oHistogram=new CHistogrammData($aoData,$this->aoPositions); return $oHistogram; } function gasLoadSpan($asZeiten) { // asZeiten :: UTC $aoResult=array(); foreach($asZeiten as $sKey=>$asSpan) { $asQueries=$this->gasGetQueries($asSpan["CatfinderPK"],$asSpan["StartTS"],$asSpan["EndTS"]); if(is_array($asQueries)) { $sQuery=join("\n UNION \n",$asQueries); $sQuery.="ORDER BY GPS_TS"; $aoResult[$sKey]["CatfinderPK"]=$asSpan["CatfinderPK"]; $aoResult[$sKey]["ResultSet"]=$oResult=$this->oDB->goQuery($sQuery); if($aoResult[$sKey]["ResultSet"]===false ||$aoResult[$sKey]["ResultSet"]->glGetNumberOfRecords()==0) { $aoResult[$sKey]["error"]=utf8_encode("Für den Zeitraum vom ".CDateTime::gsGetDateFromUTCStampUser($asSpan["StartTS"])." bis ".CDateTime::gsGetDateFromUTCStampUser($asSpan["EndTS"])." liegen keine Daten vor."); } } } if(sizeof($aoResult)==0) return false; return $aoResult; } function goLoadCatfinderDatahandler($oCatfinder) { $sName=$oCatfinder->DataHandler==""?"Standard":$oCatfinder->DataHandler; $sClassName="CGISCatFinderDataHandler".$sName; if(!class_exists($sClassName)) { $sFile=PATHFW."GisCatfinder/datahandler/class.".strtolower($sName).".php"; if(file_exists($sFile)) require_once($sFile); } if(class_exists($sClassName)) return new $sClassName($this->oSystem,$this->oDB,$oCatfinder); return false; } function gSwap(&$a,&$b) { $buffer=$a; $a=$b; $b=$buffer; } function gasGetQueries($lCatfinderPK,$lStart,$lEnd) { if($lEnd<$lStart) $lEnd=$this->gSwap($lStart,$lEnd); if($lEnd>CDateTime::glGetUTCFromTS()) $lEnd=CDateTime::glGetUTCFromTS(); $sEnd=date("Ymd",$lEnd); $lCurrent=$lStart; $sCurrent=date("Ymd",$lCurrent); $bBreak=false; $i=0; while($sCurrent!=$sEnd && $bBreak===false) { $i++; if($i>20) $bBreak=true; if($lCatfinderPK==132 || $this->oDB->glGetNumberOfRecords("tdPositionStores","CatfinderPK=".$lCatfinderPK." AND StoreTable='tdPositions_".$sCurrent."'")>0) { $asReturn[]=$this->getQuery("tdPositions_".$sCurrent,$lCatfinderPK,$lStart,$lEnd); } else { } $lCurrent=$lCurrent+86400; $sCurrent=date("Ymd",$lCurrent); } if($lCatfinderPK==132 || $this->oDB->glGetNumberOfRecords("tdPositionStores","CatfinderPK=".$lCatfinderPK." AND StoreTable='tdPositions_".$sEnd."'")>0) $asReturn[]=$this->getQuery("tdPositions_".$sEnd,$lCatfinderPK,$lStart,$lEnd); else { //mail("thorsten.k@kk-gbr.de","Fehlerx",mysql_error().$this->oDB->msQuery); } return $asReturn; } function gAddCoord($oCoord) { if($this->mlIndex-10>=0) unset($this->moCoords[$this->mlIndex-10]); $this->moCoords[$this->mlIndex]=$oCoord; $this->mlIndex++; } function getQuery($sTable,$lCatfinderPK,$lStart,$lEnd) { return "(SELECT *,IF(IFNULL(HDOP,-1)=-1,'false',HDOP) as HDOP,IFNULL(MaxSpeed,Speed) as MaxSpeed,IFNULL(MinSpeed,Speed) as MinSpeed,'".$sTable."' as TableName FROM ".$sTable." WHERE CatfinderPK=".$lCatfinderPK." AND GPS_TS>=".$lStart." AND GPS_TS<=".$lEnd.")"; } function goGetPositionType($oCoord,$oPrev) { //$this->gAddCoord($oCoord); if($oCoord->Speed==0) { if($oPrev!==false) { //$o=$this->gbGetStopPunkt(); return new CPositionType(1,"Stoppunkt\n".$o->dblMax."\n".$o->dblMin."\n".$oCoord->DistanceToPrevious." km\n".sizeof($this->moCoords),$oCoord); } return new CPositionType(1,"Stoppunkt",$oCoord); } return new CPositionType(0,"Stoppunkt",$oCoord); } function gbGetStopPunkt() { $lGesamt=sizeof($this->moCoords); if($lGesamt>0) { foreach($this->moCoords as $oCoord) { $sumLat+=$oCoord->Latitude; $sumLon+=$oCoord->Longitude; } $avgLat=$sumLat/$lGesamt; $avgLon=$sumLon/$lGesamt; $oMinMax=$this->goGetMinMaxDistance($avgLat,$avgLon); return $oMinMax; } } function goGetMinMaxDistance($bezugLat,$bezugLon) { // startbedingungen $oCoord=$this->moCoords[$this->mlIndex-1]; $dblMin=$this->getDistance($oCoord,$bezugLat,$bezugLon); $dblMax=$dblMin; foreach($this->moCoords as $oCoord) { $dblDistance=$this->getDistance($oCoord,$bezugLat,$bezugLon); $dblMin=$dblMin>$dblDistance?$dblDistance:$dblMin; $dblMax=$dblMax<$dblDistance?$dblDistance:$dblMax; } return new CMinMax($dblMin,$dblMax); } function getDistance($oCoord,$dblLat,$dblLon) { if($oCoord===false) return "0"; $lat1=(double)$oCoord->Latitude; $lon1=(double)$oCoord->Longitude; $lat2=(double)$dblLat; $lon2=(double)$dblLon; $lEarthRadius=6367.452024; $lat1=($lat1/180) * M_PI; $lat2=($lat2/180) * M_PI; $lon1=($lon1/180)*M_PI; $lon2=($lon2/180)*M_PI; $distance=acos(sin($lat1)*sin($lat2)+(cos($lat1)*cos($lat2) * cos($lon2-$lon1)))*$lEarthRadius; if((string)$distance=="NAN") return 0; return $distance; } } class CMinMax { var $dblMin=0; var $dblMax=0; function CMinMax($dblMin,$dblMax) { $this->dblMin=$dblMin; $this->dblMax=$dblMax; } } class CPositionType { var $sType; var $sText; var $masPositions=array(); function CPositionType($sType,$sText,$oCoord,$asPositions=array()) { $this->sType=$sType; $this->sText=$sText; $this->oCoord=$oCoord; $this->masPositions=$asPositions; } function gbHasPositions() { // tritt dann ein, wenn ein Stopppunkt verworfen wurde return sizeof($this->masPositions)>0; } function goGetPosition() { return array_shift($this->masPositions); } } class CPunktWolke { var $oFirstCoord; var $mlIndex=0; var $masCoords=array(); function CPunktWolke(&$oCatfinder) { $this->oCatfinder=$oCatfinder; } function setFirstCoord($oCoord,$oPrev) { $this->oFirstCoord=$oCoord; $this->oPrevFirstCoord=$oPrev; } function setCoord($oCoord) { $this->masCoords[$this->mlIndex]=$oCoord; $this->mlCurrentIndex=$this->mlIndex; $this->mlIndex++; } } class CMapImage { function CMapImage($oCatfinder,$oMap,$x,$y,$aoTour) { global $oSystem; $this->oSystem=$oSystem; $this->aoTour=$aoTour; $this->x=$x; $this->y=$y; $this->oMap=$oMap; $this->gesamtBreit=abs($this->oMap->latUR)-abs($this->oMap->latOL); $this->gesamtHoch=abs($this->oMap->lonUR)-abs($this->oMap->lonOL); $this->oCatfinder=$oCatfinder; $sMapFile=PATHMAPSERVICES."bitmaps/mp/png/".substr($oMap->MapFile,0,strrpos($oMap->MapFile,".")).".png"; $this->msFontFile=PATHMAPSERVICES."fonts/arial.ttf"; if(file_exists($sMapFile)) { $this->pImg=imagecreatefrompng($sMapFile); $this->putCurrentPos(); } else { } } function getyPosition($dblLatitude) { $olMinSuche=abs($this->oMap->latOL-$dblLatitude); return abs($olMinSuche/$this->gesamtBreit*1000); } function getxPosition($dblLongitude) { $olMinSuche=abs($this->oMap->lonOL-$dblLongitude); return abs($olMinSuche/$this->gesamtHoch*1000); } function putCurrentPos() { if($this->aoTour!=false) { imagesetthickness($this->pImg,3); $catColor=imagecolorallocate($this->pImg,255,255,0); $oPosPrev=array_shift($this->aoTour); foreach($this->aoTour as $oPos) { $x1=$this->getxPosition($oPosPrev->Longitude); $y1=$this->getyPosition($oPosPrev->Latitude); $x2=$this->getxPosition($oPos->Longitude); $y2=$this->getyPosition($oPos->Latitude); imageline($this->pImg,$x1,$y1,$x2,$y2,$catColor); $oPosPrev=$oPos; } } imagesetthickness($this->pImg,1); $y=$this->getyPosition($this->oCatfinder->Latitude);// abs($olMinSuche/$gesamtBreit*1000); $x=$this->getxPosition($this->oCatfinder->Longitude); $colBlack=imagecolorallocate($this->pImg,255,0,0); $colWhite=imagecolorallocate($this->pImg,0,0,0); /* imagearc($this->pImg,$x,$y,10,10 , 0,360,$colBlack); imagearc($this->pImg,$x,$y,200,200,0,360,$colBlack); imagearc($this->pImg,$x,$y,201,201,0,360,$colWhite); imagearc($this->pImg,$x,$y,400,400,0,360,$colBlack); imagearc($this->pImg,$x,$y,401,401,0,360,$colWhite); imagearc($this->pImg,$x,$y,402,402,0,360,$colBlack); imagearc($this->pImg,$x,$y,403,403,0,360,$colWhite); imageline($this->pImg,0,$y,999,$y,$colBlack); imageline($this->pImg,0,$y+1,999,$y+1,$colBlack); imageline($this->pImg,$x,0,$x,999,$colBlack); imageline($this->pImg,$x+1,0,$x+1,999,$colBlack); */ $this->setMessage($this->oCatfinder->TITLEBOX,"",$x,$y); header("Content-Type: image/png"); if($this->x===false) { imagepng($this->pImg); } else { header("Content-Type: text/html"); $xHalbe=$this->x/2; $yHalbe=$this->y/2; $im2=imagecreate($this->x,$this->y); $xSrc=$x-$xHalbe; if($xSrc<0) $xSrc=0; $ySrc=$y-$yHalbe; if($ySrc<0) $ySrc=0; imagecopy($im2,$this->pImg,0,0,$xSrc,$ySrc,$this->x,$this->y); imagepng($im2); } } function setMessage($sTitle,$sMessage,$xPos,$yPos) { $yBaseLine=$yPos-40; $xBase=$xPos; $black=imagecolorallocate($this->pImg,0,0,0); $white=imagecolorallocate($this->pImg,255,255,255); if($this->x!==false) { $lxFaktor=.9; $lyFaktor=.8; } else { $lxFaktor=1; $lyFaktor=1; } $asPoly[0]=$xPos; $asPoly[1]=$yPos; $asPoly[2]=$xPos+(20*$lxFaktor); $asPoly[3]=$yPos-(40*$lyFaktor); $asPoly[4]=$xPos-(20*$lxFaktor);; $asPoly[5]=$yPos-(40*$lyFaktor); $asPoly[6]=$xPos-(20*$lxFaktor);; $asPoly[7]=$yPos-(80*$lyFaktor); $asPoly[8]=$xPos+(100*$lxFaktor); $asPoly[9]=$yPos-(80*$lyFaktor); $asPoly[10]=$xPos+(100*$lxFaktor); $asPoly[11]=$yPos-(40*$lyFaktor); $asPoly[12]=$xPos+(40*$lxFaktor); $asPoly[13]=$yPos-(40*$lyFaktor); $asPoly[14]=$xPos; $asPoly[15]=$yPos; $red=imagecolorallocate($this->pImg,255,0,0); imagefilledellipse($this->pImg,$xPos,$yPos,6,6,$red); imageellipse($this->pImg,$xPos,$yPos,6,6,$black); imagefilledpolygon($this->pImg,$asPoly,8,$white); imagepolygon($this->pImg,$asPoly,8,$black); $lSize=8*$lyFaktor; imagettftext($this->pImg,$lSize,0,$xPos+3-(20*$lxFaktor),$yPos-(68*$lyFaktor),$black,$this->msFontFile,$this->oCatfinder->TITLEBOX); if($this->oSystem->oClientData->gvGetVariable("xxx",false)=="CLIENT") { $sString=CDatetime::gsGetDateFromUTCStamp($this->oCatfinder->LastGPSTS,"t: d.m.y H:i"); imagettftext($this->pImg,$lSize,0,$xPos+3-(20*$lxFaktor),$yPos-(56*$lyFaktor),$black,$this->msFontFile,$sString); imagettftext($this->pImg,$lSize,0,$xPos+3-(20*$lxFaktor),$yPos-(44*$lyFaktor),$black,$this->msFontFile,"v:".$this->oCatfinder->CurrentSpeed." km/h"); } else { $sString=CDatetime::gsGetDateFromUTCStamp($this->oCatfinder->LastGPSTS,"\a\m d.m.y \u\m H:i"); imagettftext($this->pImg,$lSize,0,$xPos+3-(20*$lxFaktor),$yPos-(56*$lyFaktor),$black,$this->msFontFile,$sString); imagettftext($this->pImg,$lSize,0,$xPos+3-(20*$lxFaktor),$yPos-(44*$lyFaktor),$black,$this->msFontFile,"Tour: ".$this->oCatfinder->ContractPK." ".$this->oCatfinder->CurrentSpeed." km/h"); } } } class CPositionObject { // ist ein interface, b var $lStartTS; # var $lStopTS=false; # var $dblLatitude; # var $dblLongitude; # var $sNodeText; # var $lSpeed; var $lMaxSpeed; var $lMinSpeed; var $lDirection; function CPositionObject($oBegin,$oEnd,$lType,$lDistance,$dblLatitude,$dblLongitude,$lDirection,$sNodeText,$lSpeed=false,$lStartTS,$lStopTS=false,$lMaxSpeed=0,$lMinSpeed=0) { $this->oBeginCoord=$oBegin; $this->oEndCoord=$oEnd; $this->lStartTS =$lStartTS; $this->lStopTS =$lStopTS; $this->dblLatitude =$dblLatitude; $this->dblLongitude =$dblLongitude; $this->sNodeText =$sNodeText; $this->lSpeed =$lSpeed; $this->lMaxSpeed =$lMaxSpeed; $this->lType =$lType; $this->lMinSpeed =$lMinSpeed; $this->lDirection =$lDirection; $this->DistanceToPrevious=$lDistance; } function glGetLatest() { if($this->lStopTS!==false) { return $this->lStopTS; } else return $this->lStartTS; } function glGetFirstTS() { return $this->lStartTS; } function glGetLastTS() { } } class CGisMathHelper { function gsGetDauer($lDurance) { } function getDistanceFormCoordLatLon($oCoord,$dblLat,$dblLon) { if($oCoord===false) return "0"; $lat1=(double)$oCoord->Latitude; $lon1=(double)$oCoord->Longitude; $lat2=(double)$dblLat; $lon2=(double)$dblLon; return $this->getDistanceFromLatLon($lat1,$lon1,$lat2,$lon2); } function getDistanceFromCoords($oCoord1,$oCoord2) { $lat1=(double)$oCoord1->Latitude; $lon1=(double)$oCoord1->Longitude; $lat2=(double)$oCoord2->Latitude; $lon2=(double)$oCoord2->Longitude; return $this->getDistanceFromLatLon($lat1,$lon1,$lat2,$lon2); } function getDistanceFromLatLon($lat1,$lon1,$lat2,$lon2) { $lEarthRadius=6367.452024; $lat1=($lat1/180) * M_PI; $lat2=($lat2/180) * M_PI; $lon1=($lon1/180)*M_PI; $lon2=($lon2/180)*M_PI; $distance=acos(sin($lat1)*sin($lat2)+(cos($lat1)*cos($lat2) * cos($lon2-$lon1)))*$lEarthRadius; if((string)$distance=="NAN") return 0; return $distance; } function gdblGetAngle($oCoord1,$oCoord2,$oCoord3) { // system auf scheitelpunkt auf 0 beziehen $vektor1=$this->vektorSubstr($oCoord1,$oCoord2); $vektor2=$this->vektorSubstr($oCoord3,$oCoord2); $betrag1=$this->betrag($vektor1); $betrag2=$this->betrag($vektor2); if($betrag1==0) return false; if($betrag2==0) return false; $cosinusAlpha=$this->skalarProdukt($vektor1,$vektor2)/($betrag1*$betrag2); $winkelRadians=acos($cosinusAlpha); return rad2deg($winkelRadians); } function vektorSubstr($oCoord1,$basis) { return new CVektor($oCoord1->Latitude-$basis->Latitude,$oCoord1->Longitude-$basis->Longitude); } function skalarProdukt($oCoord1,$oCoord2) { return ($oCoord1->Longitude*$oCoord2->Longitude)+($oCoord1->Latitude*$oCoord2->Latitude); } function betrag($oCoord) { return sqrt(pow($oCoord->Latitude,2)+pow($oCoord->Longitude,2)); } } class CVektor { var $Latitude; var $Longitude; function CVektor($Latitude,$Longitude) { $this->Latitude=$Latitude; $this->Longitude=$Longitude; } } class CHistogrammData { function CHistogrammData($aoStopPos,$aoPositions) { $this->aoStopPositions=$aoStopPos; $this->aoPositions=$aoPositions; } }