File "view_map_t.php"

Full path: /www/ansys/qgis/006_haneda/view_map_t.php
File size: 17.26 KiB (17677 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//	自動でクラスを参照する
//	関数名	:	__autoload()
//	備考	:	参照先は./class/XXX.phpとする
//	更新	:	2012/10/19 KMK-Teraoka
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

function __autoload($className)
{
	$fPath = "./class/" . str_replace("_", "/", $className) . ".php";
	require_once $fPath;
}
/*
//===============================================
//	DEBUG_MODE
//	備考		:	
//	更新		:	2012/10/19 KMK-Teraoka
//===============================================
define("DEBUG_MODE", "0");
cDebug::setMode(DEBUG_MODE);
if (DEBUG_MODE == 1)
{
	cStopwatch::start();
}
*/
//===============================================
//	CommonUtilities
//	備考		:	
//	更新		:	2012/11/29 KMK-Teraoka
//===============================================
$SCRIPT_TITLE = "運行管理システム 東京国際空港C誘導路中央部他地盤改良工事";
$PENTA_OCEAN = "五洋建設株式会社";
$TAIL_PENTA_OCEAN = "penta-ocean";

$HOST = "192.168.100.153";
$DB = "ansys";
$USER = "postgres";
$PASS = "am#71ZJ*";
$LOG_FILE = "./log/view_position.log";

$CONST_ID = 9;
$APPLICATION_ID = 16;
$MAP_NAME = "./map/haneda2.png";

$VIEW_LIST = array(
	"0"		=>	array("head"	=>	"id",			"object"	=>	"android_id",		"width"		=>	"12%"),
	"1"		=>	array("head"	=>	"端末名称",		"object"	=>	"terminal_name",	"width"		=>	"12%"),
	"2"		=>	array("head"	=>	"緯度",			"object"	=>	"lat",				"width"		=>	"10%"),
	"3"		=>	array("head"	=>	"経度",			"object"	=>	"lon",				"width"		=>	"10%"),
	"4"		=>	array("head"	=>	"精度",			"object"	=>	"acc",				"width"		=>	"8%"),
	"5"		=>	array("head"	=>	"速度",			"object"	=>	"spd",				"width"		=>	"8%"),
	"6"		=>	array("head"	=>	"測位時間",		"object"	=>	"mesdatetime",		"width"		=>	"20%"),
	"7"		=>	array("head"	=>	"更新時間",		"object"	=>	"upddatetime",		"width"		=>	"20%"),
);

//===============================================
//	HTML-HEAD-
//	備考		:	
//	更新		:	2012/10/18 KMK-Teraoka
//===============================================
/*
print "<html>";
print "<head>";
//print "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">";
print "<meta http-equiv=\"Refresh\" content=\"6000\">";
print "<title>". $SCRIPT_TITLE. "</title>";
print "<style type=\"text/css\">";
print "html {font-size: 80%; font-family:\"MS ゴシック\"; overflow-y:scroll;}";
print "table {font-size: 100%; font-family:\"MS ゴシック\"; text-align:center;}";
print "input {font-size: 100%; font-family:\"MS ゴシック\";}";
print "select {font-size: 100%; font-family:\"MS ゴシック\";}";
print "pre {font-size: 100%; font-family:\"MS ゴシック\";}";
print "</style>";

print "<SCRIPT LANGUAGE='JavaScript'>";
print "function RefreshImg(filen)";
print "{";
print "uniq = new Date();";
print "uniq = \"?\"+uniq.getTime();";
print "newImage = document.imgToLoad.src;";
print "index = newImage.indexOf(\"?\", 0);";
print "		    if (index > 0)";
print "		        {";
print "		            newImage = newImage.substr(0, index);";
print "		        }";
print "		    document.imgToLoad.src = filen+uniq;";
print "}";
print "</SCRIPT>";


print "</head>";
*/
//===============================================
//	HTML-BODY部開始-
//	備考		:	
//	更新		:	2012/10/18 KMK-Teraoka
//===============================================
//print "<body>";

//for(;;)
//{

try
{
	$mLog = new cLog($LOG_FILE);
	
	// ===============================================
	// 画像情報の取得
	// 備考		:	
	// 更新		:	2012/11/29 KMK-Teraoka
	// ===============================================
	$imgSize = getimagesize($MAP_NAME);
	//$imgFileName = "./tmp/". $CONST_ID. "_". $APPLICATION_ID. "_". md5(uniqid(rand(), true)) .image_type_to_extension($imgSize[2]);
	$imgFileName = "view_map.php";
		
	// ===============================================
	// 基準点情報
	// 備考		:	
	// 更新		:	2012/11/29 KMK-Teraoka
	// ===============================================
//	$ltLon = 4562.620;						//経度(左上)
//	$ltLat = 2861.367;						//緯度(左上)
//	$rbLon = 5838.176;						//経度(右下)
//	$rbLat = 2489.424;						//緯度(右下)
	
//	$ltX = 279;								// 左上X座標
//	$ltY = 287;								// 左上Y座標
//	$rbX = 901;								// 右下X座標
//	$rbY = 468;								// 右下Y座標

	$ltLon = 1776.520;						//経度(左上)
	$ltLat = 2223.108;						//緯度(左上)
	$rbLon = 5822.263;						//経度(右下)
	$rbLat = 3694.629;						//緯度(右下)
	
	$ltX = 350;								// 左上X座標
	$ltY = 434;								// 左上Y座標
	$rbX = 1361;								// 右下X座標
	$rbY = 66;								// 右下Y座標


	
	$diffX = $rbX - $ltX;					// X座標ピクセルの差を求める
	$diffY = $rbY - $ltY;					// Y座標ピクセルの差を求める
	
	$spX = number_format(($rbLon - $ltLon) / $diffX, 10);		// X座標の倍率を求める
	$spY = number_format(($ltLat - $rbLat) / $diffY, 10);		// Y座標の倍率を求める
	
	// ■
	// 座標変換の為の準備
	$angle = pi() * (-59.884236) / 180.0;
	cPos2Loc::init(9);
	echo cPos2Loc::init(9);
	print "aaaa";
	// ===============================================
	// GD処理準備
	// 備考		:	
	// 更新		:	2010/09/08 KMK T.Teraoka
	// ===============================================
	$src = ImageCreateFromPNG($MAP_NAME);						//パレットへ貼り付ける画像指定(地図画像)
	$img = imagecreatetruecolor($imgSize[0]+350,$imgSize[1]);			//パレットの作成
	imagecopy($img, $src, 0, 0, 0, 0, $imgSize[0], $imgSize[1]);	//画像をパレットへ貼り付け
	
	//1479 + 350
	//1013
	
	$font1 = "/usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf";
	imagesetthickness($img, $THIC);
	
	// 使用色の準備
	$Black = imagecolorallocate($img, 0,0,0);
	$White = imagecolorallocate($img, 255, 255, 255);
	$Red =  imagecolorallocate($img, 255, 0, 0);
	$Green =  imagecolorallocate($img, 0, 128, 0);
	$Blue = imagecolorallocate($img, 0, 0, 255);
	
	// 更新時間をマップに表示する
	$up_check = date("H:i:s" ,time());
	imagefilledpolygon($img, array(10, 10, 10, 20, 55, 20, 55, 10), 4, $White);
	ImageTTFText ($img, 8, 0, 10, 20, $Black, $font1, $up_check);

	//端末の一覧表示
	imagefilledrectangle($img, $imgSize[0], 0, $imgSize[0]+348, $imgSize[1]-2, $White);
	imagerectangle($img, $imgSize[0], 0, $imgSize[0]+348, $imgSize[1]-2, imagecolorallocate($img, 0, 0, 0));
	imagerectangle($img, $imgSize[0], 0, $imgSize[0]+348, 250, imagecolorallocate($img, 0, 0, 0));
	imagefilledellipse ($img, $imgSize[0]+105, 80, 25, 25, $Blue);
	imagefilledellipse ($img, $imgSize[0]+105, 120, 25, 25, $Green);
	imagefilledellipse ($img, $imgSize[0]+105, 160, 25, 25, $Red);
	imageellipse ($img, $imgSize[0]+105, 200, 25, 25, $Black);
	ImageTTFText ($img, 20, 0, $imgSize[0]+135, 90, $Blue, $font1, "施工場所");
	ImageTTFText ($img, 20, 0, $imgSize[0]+135, 130, $Green, $font1, "ヤード");
	ImageTTFText ($img, 20, 0, $imgSize[0]+135, 170, $Red, $font1, "その他範囲内");
	ImageTTFText ($img, 20, 0, $imgSize[0]+135, 210, $Black, $font1, "通信なし");

	
	//================================================
	//	データベース接続
	//	備考		:	
	//	更新		:	2012/11/29 KMK-Teraoka
	//================================================
	$conn = pg_connect("
		host	=	". $HOST. "
		dbname	=	". $DB. "
		user	=	". $USER. "
		password=	". $PASS. "
	");
	if (!$conn)
	{
		throw new Exception("データベースへの接続に失敗しました");
	}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// ===============================================
	// エリア判定
	// 備考		:	
	// 更新		:	2014/02/07 K.Kikuchi
	// ===============================================
	//----------■エリア1------------------------------

	$AreaJudge[0] = "SELECT * FROM qgis.ts_terminal WHERE const_id = 9 AND NOT android_id ='7d0d4dc45397b57e' AND point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[0] .= "(1397934290,355515150),";
	$AreaJudge[0] .= "(1397934290,355615150),";
	$AreaJudge[0] .= "(1397934350,355515150),";
	$AreaJudge[0] .= "(1397934350,355615150)";
	$AreaJudge[0] .= ")' ORDER BY terminal_name;";

	$ResPoint[0] = pg_query($conn, $AreaJudge[0]) or die("SQL ERROR!!<br />". $AreaJudge[0].pg_last_error());
	$CountPoint[0] = pg_num_rows($ResPoint[0]);

	//----------■エリア2------------------------------
	$AreaJudge[1] = "SELECT * FROM qgis.ts_terminal WHERE const_id = 9 AND NOT android_id ='7d0d4dc45397b57e' AND ";
	$AreaJudge[1] .= "point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[1] .= "(1397718380,355677008),";
	$AreaJudge[1] .= "(1397735772,355666758),";
	$AreaJudge[1] .= "(1397722997,355651800),"; 
	$AreaJudge[1] .= "(1397704866,355661588)";
	$AreaJudge[1] .= ")'";
	$AreaJudge[1] .= " OR ";
	$AreaJudge[1] .= "point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[1] .= "(1397593011,355635275),";
	$AreaJudge[1] .= "(1397615977,355608202),";
	$AreaJudge[1] .= "(1397596002,355596897),"; 
	$AreaJudge[1] .= "(1397573036,355623969)";
	$AreaJudge[1] .= ")'";
	$AreaJudge[1] .= " OR ";
	$AreaJudge[1] .= "point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[1] .= "(1397566980,355629002),";
	$AreaJudge[1] .= "(1397569269,355626347),";
	$AreaJudge[1] .= "(1397561530,355621897),"; 
	$AreaJudge[1] .= "(1397559241,355624555)";
	$AreaJudge[1] .= ")'";
	$AreaJudge[1] .= " ORDER BY terminal_name;";
	
	$ResPoint[1] = pg_query($conn, $AreaJudge[1]) or die("SQL ERROR!!<br />". $AreaJudge[1].pg_last_error());
	$CountPoint[1] = pg_num_rows($ResPoint[1]);



	//----------■エリア3------------------------------
	$AreaJudge[2] = "SELECT * FROM qgis.ts_terminal WHERE const_id = 9 AND NOT android_id ='7d0d4dc45397b57e' AND ";
	$AreaJudge[2] .= "NOT ";
	$AreaJudge[2] .= "point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[2] .= "(1399385346,369000000),";
	$AreaJudge[2] .= "(1399385346,369100000),";
	$AreaJudge[2] .= "(1399385348,369000000),";
	$AreaJudge[2] .= "(1399385348,369100000)";
	$AreaJudge[2] .= ")'";
	$AreaJudge[2] .= " AND ";
	$AreaJudge[2] .= " NOT ";
	$AreaJudge[2] .= "point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[2] .= "(1397569269,355626347),";
	$AreaJudge[2] .= "(1397735772,355666758),";
	$AreaJudge[2] .= "(1397722997,355651800),";
	$AreaJudge[2] .= "(1397704866,355661588)";
	$AreaJudge[2] .= ")'"; 
	$AreaJudge[2] .= " AND ";
	$AreaJudge[2] .= " NOT ";
	$AreaJudge[2] .= "point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[2] .= "(1397593011,355635275),";
	$AreaJudge[2] .= "(1397615977,355608202),";
	$AreaJudge[2] .= "(1397596002,355596897),"; 
	$AreaJudge[2] .= "(1397573036,355623969)";
	$AreaJudge[2] .= ")'";
	$AreaJudge[2] .= " AND ";
	$AreaJudge[2] .= " NOT ";
	$AreaJudge[2] .= "point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[2] .= "(1397566980,355629002),";
	$AreaJudge[2] .= "(1397569269,355626347),";
	$AreaJudge[2] .= "(1397561530,355621897),";
	$AreaJudge[2] .= "(1397559241,355624555)"; 
	$AreaJudge[2] .= ")'";
	$AreaJudge[2] .= " ORDER BY terminal_name;";

	$ResPoint[2] = pg_query($conn, $AreaJudge[2]) or die("SQL ERROR!!<br />". $AreaJudge[2].pg_last_error());
	$CountPoint[2] = pg_num_rows($ResPoint[2]);

	$AreaCount = count($AreaJudge);

	for($a = 0;$a < $AreaCount;$a++)
	{
		$row_ = array();
		for($h=0;$h < $CountPoint[$a];$h++)
		{
			$row_ = pg_fetch_array($ResPoint[$a],$h);
			//print "BAA";
			$DataTime = strtotime($row_['mesdatetime']);
			$DataCheck = time() - $DataTime;
			//if($DataCheck > 600) $Judge[$row_['terminal_name']] = 99;
			
			if(!$Judge[$row_['terminal_name']]) $Judge[$row_['terminal_name']] = $a + 1;
			//print $row_['terminal_name'] ."<br>";

		}
	}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	var_dump($Judge);
	// ===============================================
	// 位置を取得する
	// 備考		:	
	// 更新		:	2012/11/29 KMK T.Teraoka
	// ===============================================
	$selTerm = "SELECT * FROM qgis.ts_terminal";
	$selTerm .= " WHERE const_id='". $CONST_ID. "'";
	$selTerm .= " AND app_id='". $APPLICATION_ID. "'";
	$selTerm .= " AND NOT terminal_name = 'haneda_test'";
//	$selTerm .= " AND android_id='17ce47ebbb69e091'";
//	$selTerm .= " OR android_id='2550f5978ffbcca7'";
//	$selTerm .= " OR android_id='444117a90e1f3a0'";
//	$selTerm .= " OR android_id='62f9075986d6b0e7'";
//	$selTerm .= " ORDER BY android_id";
	$selTerm .= " ORDER BY terminal_name";

	$selTerm .= ";";
	$mLog->writeLog($selTerm. "\n");
	if (!($resTerm = pg_query($conn, $selTerm)))
	{
		throw new Exception("データ取得に失敗<br />". $resTerm. "<br />". pg_last_error(). "<br />");
	}
	
	$row = pg_num_rows($resTerm);
	
	for($iCount = 0; $iCount < $row; $iCount++)
	{
		$rowTerm = pg_fetch_array($resTerm, $iCount, PGSQL_ASSOC);
		
		//●端末一覧表示
		$Data = sprintf("%02d", $rowTerm["terminal_name"] - 150);
		switch($Judge[$rowTerm["terminal_name"]])
		{
			case 1:
				imagefilledellipse ($img, $imgSize[0]+25 + $SetX, 270 + $SetY *30, 20, 20, $Blue);
				ImageTTFText ($img, 18, 0, $imgSize[0]+45+ $SetX, 280 + $SetY *30, $Black, $font1, $Data);
				break;

			case 2:
				imagefilledellipse ($img, $imgSize[0]+25 + $SetX, 270 + $SetY *30, 20, 20, $Green);
				ImageTTFText ($img, 18, 0, $imgSize[0]+45+ $SetX, 280 + $SetY *30, $Black, $font1, $Data);
				break;

			case 3:
				imagefilledellipse ($img, $imgSize[0]+25 + $SetX, 270 + $SetY *30, 20, 20, $Red);
				ImageTTFText ($img, 18, 0, $imgSize[0]+45+ $SetX, 280 + $SetY *30, $Black, $font1, $Data);
				break;

    			default:
				imageellipse ($img, $imgSize[0]+25 + $SetX, 270 + $SetY *30, 20, 20, $Black);
				ImageTTFText ($img, 18, 0, $imgSize[0]+45+ $SetX, 280 + $SetY *30, $Black, $font1, $Data);

		}
		
		if(($iCount+1) % 25 == 0)
		{
			$SetX = $SetX +80 ;
			$SetY = 0;
		}
		else
		{
			$SetY++ ;
		}
		

		if (0 != strcmp($rowTerm["lat"], "") && 0 != strcmp($rowTerm["lon"], ""))
		{
			// ■
			// 座標変換
			//$lon = 139.7917966;
			//$lat =  35.5407766;
			//$local = cPos2Loc::convert($lat, $lon);
			
			
			//print $iCount. ",";
			/*
			switch($iCount)
			{
			case 0:
				$rowTerm["lat"] = "35.551515";
				$rowTerm["lon"] = "139.793429";
				break;
			case 1:
				$rowTerm["lat"] = "35.566020";
				$rowTerm["lon"] = "139.771083";
				break;
//			case 2:
//				$rowTerm["lat"] = "35.5336";
//				$rowTerm["lon"] = "139.793306";
//				break;
			case 2:
				$rowTerm["lat"] = "35.533667";
				$rowTerm["lon"] = "139.79327";
				break;
			case 3:
				$rowTerm["lat"] = "35.534515";
				$rowTerm["lon"] = "139.793003";
				break;
			default:
				continue;
			}
			*/
			
			$local = cPos2Loc::convert($rowTerm["lat"], $rowTerm["lon"]);
			$hanedaLoc = array();
			$hanedaLoc["0"] = $local["0"] - 738.0151;
			$hanedaLoc["1"] = $local["1"] +1092.2038;
			
			$hanedaLoc2 = array();
			$hanedaLoc2["0"] = 2000 + ($hanedaLoc["0"] * cos($angle)) - ($hanedaLoc["1"] * sin($angle));
			$hanedaLoc2["1"] = 2000 + ($hanedaLoc["1"] * cos($angle)) + ($hanedaLoc["0"] * sin($angle));
			
			$posX = ($hanedaLoc2["1"] - $ltLon) / $spX + $ltX;
			$posY = ($ltLat - $hanedaLoc2["0"]) / $spY + $ltY;
			
			// 現在位置の描画
			/*
			switch($iCount % 4)
			{
			case 0:
				$col = imagecolorallocate($img, 255, 0, 0);
				break;
			case 1:
				$col = imagecolorallocate($img, 250, 100, 0);
				break;
			case 2:
				$col = imagecolorallocate($img, 0, 100, 255);
				break;
			case 3:
				$col = imagecolorallocate($img, 0, 255, 0);
				break;
			}
			*/
			//print "rowterm=" .$rowTerm['terminal_name'] ."////jud=" .$Judge[$rowTerm['terminal_name']] ."<BR>";
			switch($Judge[$rowTerm["terminal_name"]])
			{
				case 1:
					$col = imagecolorallocate($img, 0, 0, 255);
					break;

				case 2:
					$col = imagecolorallocate($img, 0, 128, 0);
					break;

				case 3:
					$col = imagecolorallocate($img, 255, 0, 0);
					break;

	    			default:
					$col = imagecolorallocate($img, 255, 255, 255);
			}
			
			$ellipSize = 8;
			//print $posX. ",". $posY;
			Imagefilledellipse($img, $posX, $posY, $ellipSize, $ellipSize, $col);
			if($Judge[$rowTerm["terminal_name"]] == 0) Imageellipse($img, $posX, $posY, $ellipSize, $ellipSize, $col);
			// 端末番号表示の吹き出し
			imagefilledrectangle($img, $posX + 5, $posY - 23, $posX + 22, $posY - 7, imagecolorallocate($img, 255, 255, 255));
			imagerectangle($img, $posX + 5, $posY - 23, $posX + 22, $posY - 7, imagecolorallocate($img, 0, 0, 0));
			
			$sepName = sprintf("%02d",$rowTerm["terminal_name"] - 150);
			
			imagettftext($img, 8, 0, $posX + 8, $posY - 11, imagecolorallocate($img, 0, 0, 0), $font1, mb_convert_encoding($sepName, "SJIS", "UTF8"));
		}
	}
	

	// ===============================================
	// 描画した画像を保存 & パレットを削除
	// 備考		:	
	// 更新		:	2010/09/08 KMK T.Teraoka
	// ===============================================
//	header('Content-Type: image/png');

//	imagepng($img, $imgFileName);
//	imagepng($img);
//	imagedestroy($img);
//	imagedestroy($src);


}
catch(Exception $exc)
{
	$mLog->writeLog($exc->getMessage(). "\n");
}


//===============================================
//	Postgresql終了処理
//	備考		:	
//	更新		:	2012/10/19 KMK-Teraoka
//===============================================
pg_close($conn);

//===============================================
//	HTML終了処理
//	備考		:	
//	更新		:	2012/10/18 KMK-Teraoka
//===============================================
//print "</body>";
//print "</html>";

?>

PHP File Manager