2012-04-24 09:58:09 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class VisualController extends Zend_Controller_Action
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
function preDispatch()
|
|
|
|
|
{
|
|
|
|
|
$this->view->config = Zend_Registry::get('config');
|
|
|
|
|
$this->db=Zend_Registry::get('db');
|
2012-04-24 16:16:27 +00:00
|
|
|
|
$this->dbh = new PDO("pgsql:dbname=qinghaihu;host=localhost", "gis", "gispassword" );
|
2012-04-24 09:58:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function indexAction()
|
|
|
|
|
{
|
|
|
|
|
|
2012-04-25 03:37:48 +00:00
|
|
|
|
}
|
2012-04-24 09:58:09 +00:00
|
|
|
|
|
2012-04-25 03:37:48 +00:00
|
|
|
|
/*
|
|
|
|
|
* getMeteorologyValueByStation 按站点查询变量
|
|
|
|
|
*
|
|
|
|
|
* param int $sid 站点编号
|
|
|
|
|
* param string $field 变量类型
|
|
|
|
|
*
|
|
|
|
|
* return array
|
|
|
|
|
*/
|
|
|
|
|
function getMeteorologyValueByStation($sid,$field)
|
2012-04-24 09:58:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
2012-04-25 03:37:48 +00:00
|
|
|
|
$sql = "select id,station_id as sid,date,$field as v from daily_meteorological_data where station_id=$sid";
|
2012-04-24 09:58:09 +00:00
|
|
|
|
|
|
|
|
|
$sth = $this->dbh->prepare($sql);
|
|
|
|
|
$sth->execute();
|
|
|
|
|
$temp = $sth->fetchAll();
|
|
|
|
|
|
|
|
|
|
$dataSet = array();
|
|
|
|
|
|
|
|
|
|
foreach ($temp as $k=>$v)
|
|
|
|
|
{
|
2012-04-25 03:37:48 +00:00
|
|
|
|
$dataSet[] = array(strtotime($v['date'])*1000,$v['v']);
|
2012-04-24 09:58:09 +00:00
|
|
|
|
}
|
|
|
|
|
unset($temp);
|
|
|
|
|
|
|
|
|
|
return $dataSet;
|
|
|
|
|
|
2012-04-25 03:37:48 +00:00
|
|
|
|
}// getMeteorologyValueByStation 按站点查询变量
|
2012-04-24 09:58:09 +00:00
|
|
|
|
|
2012-04-25 03:37:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* createMeteorologyDataSet 创建气象数据
|
|
|
|
|
*
|
|
|
|
|
* param int $sid 站点id
|
|
|
|
|
* param string $valuetype 请求变量类型
|
|
|
|
|
* param String $labe 单位
|
|
|
|
|
* param int $round 数据精确度(小数点后位数)
|
|
|
|
|
*
|
|
|
|
|
* return array
|
|
|
|
|
*/
|
|
|
|
|
function createMeteorologyDataSet($sid,$valuetype,$label,$round=1)
|
2012-04-24 09:58:09 +00:00
|
|
|
|
{
|
2012-04-25 03:37:48 +00:00
|
|
|
|
if(empty($label))
|
|
|
|
|
{
|
|
|
|
|
$label="";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$varField = array(
|
|
|
|
|
'temperature' => 'avg_air_temperature', //日平均气温
|
|
|
|
|
'windspeed' => 'avg_wind_speed', //日平均风速
|
|
|
|
|
'precipitation' => 'sum_precipitation', //日合计降水量
|
|
|
|
|
'sunshine' => 'sunshine_hours' //日照小时数
|
|
|
|
|
);
|
|
|
|
|
|
2012-04-24 09:58:09 +00:00
|
|
|
|
$data = array(
|
|
|
|
|
"name"=>"站点:$sid",
|
2012-04-25 03:37:48 +00:00
|
|
|
|
"data"=>$this->getMeteorologyValueByStation($sid,$varField[$valuetype]),
|
2012-04-24 09:58:09 +00:00
|
|
|
|
"tooltip"=>array(
|
2012-04-25 03:37:48 +00:00
|
|
|
|
"valueDecimals"=> $round,
|
|
|
|
|
"valueSuffix"=> $label
|
2012-04-24 09:58:09 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $data;
|
2012-04-25 03:37:48 +00:00
|
|
|
|
}// createMeteorologyDataSet 创建气象数据
|
2012-04-24 09:58:09 +00:00
|
|
|
|
|
2012-04-25 03:37:48 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* getMeteorologyDataByStationId 获得变量值
|
|
|
|
|
*
|
|
|
|
|
* param string $valuetype 变量类型
|
|
|
|
|
* param string $label 单位
|
|
|
|
|
* param int $sid 可选,为空则查询所有站点
|
|
|
|
|
* param int $round 数值精确度,小数点后位数
|
|
|
|
|
*
|
|
|
|
|
* return array
|
|
|
|
|
*/
|
|
|
|
|
function getMeteorologyDataByStationId($valuetype,$label,$sid=0,$round=1)
|
|
|
|
|
{
|
|
|
|
|
if(empty($sid))
|
|
|
|
|
{
|
|
|
|
|
$sql = "select station_id as sid from daily_meteorological_data group by station_id";
|
|
|
|
|
|
|
|
|
|
$sth = $this->dbh->prepare($sql);
|
|
|
|
|
$sth->execute();
|
|
|
|
|
$stations = $sth->fetchAll();
|
|
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
|
|
foreach ($stations as $v)
|
|
|
|
|
{
|
|
|
|
|
$data[] = $this->createMeteorologyDataSet($v['sid'],$valuetype,$label,$round);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return $this->createMeteorologyDataSet($sid,$valuetype,$label,$round=1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}//getMeteorologyDataByStationId 获得变量值
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* dataAction() ajax获取数据(用于绘图)
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-04-24 09:58:09 +00:00
|
|
|
|
function dataAction()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$this->_helper->layout->disableLayout();
|
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
|
|
2012-04-25 03:37:48 +00:00
|
|
|
|
$ac = $this->_request->getParam('ac');
|
|
|
|
|
$base = $this->_request->getParam('dt');
|
|
|
|
|
|
|
|
|
|
if(!in_array($base,array('meteorology','hydrology')))
|
|
|
|
|
{
|
|
|
|
|
$data = array(
|
|
|
|
|
"error"=>"参数错误"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->jsonexit($data);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 09:58:09 +00:00
|
|
|
|
$sql = "select station_id as sid from daily_meteorological_data group by station_id";
|
|
|
|
|
|
|
|
|
|
$sth = $this->dbh->prepare($sql);
|
|
|
|
|
$sth->execute();
|
|
|
|
|
$stations = $sth->fetchAll();
|
|
|
|
|
|
|
|
|
|
$datas = array();
|
2012-04-25 03:37:48 +00:00
|
|
|
|
$label = "";
|
|
|
|
|
$title = "";
|
|
|
|
|
|
2012-04-24 09:58:09 +00:00
|
|
|
|
|
2012-04-25 03:37:48 +00:00
|
|
|
|
if($base == "meteorology")
|
2012-04-24 09:58:09 +00:00
|
|
|
|
{
|
2012-04-25 03:37:48 +00:00
|
|
|
|
if($ac=='temperature')
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$title = "日平均温度";
|
|
|
|
|
$label = "℃";
|
|
|
|
|
|
|
|
|
|
$datas = $this->getMeteorologyDataByStationId($ac,$label);
|
|
|
|
|
|
|
|
|
|
}//日平均温度
|
|
|
|
|
|
|
|
|
|
if($ac == 'windspeed')
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$title = "日平均风速";
|
|
|
|
|
$label = "m/s";
|
|
|
|
|
|
|
|
|
|
$datas = $this->getMeteorologyDataByStationId($ac,$label);
|
|
|
|
|
|
|
|
|
|
}//日平均风速 m/s
|
|
|
|
|
|
|
|
|
|
if($ac == 'precipitation')
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$title = "日合计降水量";
|
|
|
|
|
$label = "mm";
|
|
|
|
|
|
|
|
|
|
$datas = $this->getMeteorologyDataByStationId($ac,$label);
|
|
|
|
|
|
|
|
|
|
}//日合计降水量 mm
|
|
|
|
|
|
|
|
|
|
if($ac == 'sunshine')
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$title = "日照小时数";
|
|
|
|
|
$label = "h";
|
|
|
|
|
|
|
|
|
|
$datas = $this->getMeteorologyDataByStationId($ac,$label);
|
|
|
|
|
|
|
|
|
|
}//日照小时数 h
|
|
|
|
|
|
|
|
|
|
}//气象数据
|
|
|
|
|
|
2012-04-24 09:58:09 +00:00
|
|
|
|
|
|
|
|
|
$data = array(
|
2012-04-25 03:37:48 +00:00
|
|
|
|
"label"=>$label,
|
|
|
|
|
"title"=>$title,
|
2012-04-24 09:58:09 +00:00
|
|
|
|
"datas"=>$datas
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->jsonexit($data);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function utcMsTime($time=''){
|
|
|
|
|
if(empty($time))
|
|
|
|
|
return (time()+8*3600)*1000;
|
|
|
|
|
else
|
|
|
|
|
return $time*1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* jsonexit() 退出并返回json数据
|
|
|
|
|
*
|
|
|
|
|
* param array $data 要返回的JSON数据,可以是任意数组
|
|
|
|
|
*
|
|
|
|
|
* return application/JSON
|
|
|
|
|
*/
|
|
|
|
|
public function jsonexit($data){
|
|
|
|
|
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
|
|
|
|
|
return true;
|
|
|
|
|
}//jsonexit() 退出并返回json数据
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
数据模型
|
|
|
|
|
"data"=>array(
|
|
|
|
|
|
|
|
|
|
//第一条曲线
|
|
|
|
|
"data1"=>array(
|
|
|
|
|
"title"=>"5米风速",
|
|
|
|
|
"unit"=>"m/s",
|
|
|
|
|
"sensor"=>"传感器XXX",
|
|
|
|
|
"sensor_type"=>"传感器类型",
|
|
|
|
|
"datas"=>array(
|
|
|
|
|
array($this->utcMsTime(),26.0),
|
|
|
|
|
array($this->utcMsTime()+3600*1000,28.1),
|
|
|
|
|
array($this->utcMsTime()+7200*1000,30.9),
|
|
|
|
|
array($this->utcMsTime()+10800*1000,32.0),
|
|
|
|
|
array($this->utcMsTime()+12800*1000,28.0),
|
|
|
|
|
array($this->utcMsTime()+13800*1000,22.0)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//第二条曲线
|
|
|
|
|
"data2"=>array(
|
|
|
|
|
"title"=>"10米风速",
|
|
|
|
|
"unit"=>"m/s",
|
|
|
|
|
"sensor"=>"传感器XXX",
|
|
|
|
|
"sensor_type"=>"传感器类型",
|
|
|
|
|
"datas"=>array(
|
|
|
|
|
array($this->utcMsTime(),26.0),
|
|
|
|
|
array($this->utcMsTime()+5600*1000,22.1),
|
|
|
|
|
array($this->utcMsTime()+8200*1000,35.9),
|
|
|
|
|
array($this->utcMsTime()+11800*1000,32.0),
|
|
|
|
|
array($this->utcMsTime()+13900*1000,22.0),
|
|
|
|
|
array($this->utcMsTime()+16800*1000,21.0)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
//第三条.......
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|