From 5f97c58e516d04c7fdfaee7b55e333903fa306d0 Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Thu, 28 Feb 2008 16:02:32 +0000 Subject: [PATCH] Incluida opção de geração de relatório na ferramenta tabela --- ferramentas/tabela/index.htm | 18 ++++++++++++++---- ferramentas/tabela/index.js | 2 ++ ferramentas/tabela/relatorio.php | 270 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+), 4 deletions(-) create mode 100644 ferramentas/tabela/relatorio.php diff --git a/ferramentas/tabela/index.htm b/ferramentas/tabela/index.htm index a2d273e..69a9844 100644 --- a/ferramentas/tabela/index.htm +++ b/ferramentas/tabela/index.htm @@ -11,7 +11,7 @@
Marcados
Operações
Gráficos
- +
Relatórios
@@ -88,19 +88,29 @@
- + Incluir cálculo de área
+
+ + Incluir cálculo de estatísticas +
+
+ Excluir das estatísticas o valor + +
diff --git a/ferramentas/tabela/index.js b/ferramentas/tabela/index.js index 3538338..1f85e44 100644 --- a/ferramentas/tabela/index.js +++ b/ferramentas/tabela/index.js @@ -1081,6 +1081,8 @@ function mostraFG(retorno) function gerarelatorio() { $i("arearel").value = $i("calculaarea").checked + $i("statrel").value = $i("calculaestat").checked + $i("excluirvalor").value = $i("excestat").value $i("temarel").value=tema $i("g_sid").value=g_sid $i("itemagruparel").value=$i("agrupaItem").value diff --git a/ferramentas/tabela/relatorio.php b/ferramentas/tabela/relatorio.php new file mode 100644 index 0000000..8a8c9bb --- /dev/null +++ b/ferramentas/tabela/relatorio.php @@ -0,0 +1,270 @@ +getlayerbyname($temarel); +$existesel = "nao"; +if (file_exists($map_file."qy")) +{$mapa->loadquery($map_file."qy");} +if ($layer->getNumresults() > 0){$existesel = "sim";} +if ($existesel == "nao") +{$layer->querybyrect($mapa->extent);} +$layer->open(); +//$registros[] = array(); +$res_count = $layer->getNumresults(); +for ($i = 0; $i < $res_count; $i++) +{ + $valitem = array(); + $result = $layer->getResult($i); + $shp_index = $result->shapeindex; + $shape = $layer->getshape(-1, $shp_index); + $grupo = ""; + foreach ($itensrel as $item) + { + $v = trim($shape->values[$item]); + if (function_exists("mb_convert_encoding")) + {$v = mb_convert_encoding($v,"UTF-8","ISO-8859-1");} + $valitem[$item] = $v; + } + if ($itemagruparel != "") + {$grupo = $valitem[$itemagruparel];} + if($arearel == "true") + { + $valitem["area"] = calculaarea($shape); + } + if ($itemagruparel == "") + $registros[] = $valitem; + else + { + if(!$registros[$grupo]) + $registros[$grupo]=array($valitem); + else + array_push($registros[$grupo],$valitem); + } +} +$fechou = $layer->close(); +?> + + + +i3Geo + + + +
+Relatório do tema: ".$layer->getmetadata("TEMA")."
"; +$ocorrencias = count($registros); +echo "ocorrências: ".$ocorrencias."
"; +if ($itemagruparel == "") +{ + echo ""; + $cor = "rgb(240,240,240)"; + echo ""; + if($statrel == "true"){echo "";} + foreach ($colunas as $c) + { + echo ""; + } + if($arearel == "true") + {echo "";} + foreach ($registros as $linhas) + { + if(count($linhas)>0) + { + echo ""; + if ($statrel == "true") + echo ""; + $conta = 0; + foreach($linhas as $v) + { + echo ""; + if ($statrel == "true") + { + $v = trim($v); + if(!is_numeric($v)){$v = 0;} + if ($v == $excluirvalor){$v = 0;} + $soma[$conta] = $soma[$conta] + $v; + } + $conta++; + } + echo ""; + if ($cor == "rgb(240,240,240)") + {$cor = "rgb(220,220,220)";} + else + {$cor = "rgb(240,240,240)";} + } + } + if ($statrel == "true") + { + echo ""; + echo ""; + foreach($soma as $s) + echo ""; + echo ""; + echo ""; + echo ""; + foreach($soma as $s) + echo ""; + echo ""; + } + echo "
$cárea em ha
$v
soma$s
média".($s / $ocorrencias)."
"; +} +else +{ + $conta = -1; + $chaves = array_keys($registros); + sort($chaves); + foreach ($chaves as $chave) + { + //if(count($registro) < 1){continue;} + //var_dump($registros[$conta]); + $ocorrencias = count($registros[$chave]); + echo "

".$itemagruparel.": ".$chave."
ocorrências: ".$ocorrencias."
"; + //echo "
";var_dump($registro);
+		echo "";
+		$cor = "rgb(240,240,240)";
+		echo "";
+		if ($statrel == "true")
+		echo "";
+		foreach ($colunas as $c)
+		{
+			echo "";
+		}
+		$soma = array();
+		if($arearel == "true")
+		{echo "";}
+		echo "";
+		foreach ($registros[$chave] as $linhas)
+		{
+			if (count($linhas) > 0 )
+			{
+				//echo "
";var_dump($linhas);
+				echo "
"; + if ($statrel == "true") + echo ""; + $conta = 0; + foreach($linhas as $v) + { + echo ""; + if ($statrel == "true") + { + $v = trim($v); + if(!is_numeric($v)){$v = 0;} + if ($v == $excluirvalor){$v = 0;} + $soma[$conta] = $soma[$conta] + $v; + } + $conta++; + } + echo ""; + if ($cor == "rgb(240,240,240)") + {$cor = "rgb(220,220,220)";} + else + {$cor = "rgb(240,240,240)";} + } + } + if ($statrel == "true" && $ocorrencias>1 ) + { + echo ""; + echo ""; + foreach($soma as $s) + echo ""; + echo ""; + echo ""; + echo ""; + foreach($soma as $s) + echo ""; + echo ""; + } + echo "
$cárea em ha
$v
soma$s
média".($s / $ocorrencias)."
"; + } + +} +function calculaarea($geo) +{ + global $postgis_con; + $v = versao(); + if (($v["principal"] != 5) && ($postgis_con == "")) + {return ("erro. Nao foi definida a conexao com o Postgis.");} + if ($v["principal"] != 5) + { + $pgconn = pg_connect($postgis_con); + $g = $geo->towkt(); + $sql = "select area(transform( GeomFromText('$g',4291),$srid_area))::float as aream"; + $result=pg_query($pgconn, $sql); + pg_close($pgconn); + $calculo = pg_fetch_all($result); + return $calculo[0]["aream"]; + } + else + { + $g = $geo->towkt(); + $shape = ms_shapeObjFromWkt($g); + $rect = $shape->bounds; + $projInObj = ms_newprojectionobj("proj=latlong"); + $projOutObj = ms_newprojectionobj("proj=laea,lat_0=".$rect->miny.",lon_0=".$rect->minx.",x_0=500000,y_0=10000000,ellps=GRS67,units=m,no_defs"); + $shape->project($projInObj, $projOutObj); + $s = $shape->towkt(); + $shape = ms_shapeObjFromWkt($s); + $area = $shape->getArea(); + return $area; + } +} +/* +function: versao + +Retorna a versão do Mapserver. +*/ + function versao() + { + $v = "5.0.0"; + $vs = explode(" ",ms_GetVersion()); + for ($i=0;$i<(count($vs));$i++) + { + if(strtolower($vs[$i]) == "version") + {$v = $vs[$i+1];} + } + $versao["completa"] = $v; + $v = explode(".",$v); + $versao["principal"] = $v[0]; + return $versao; + } +?> \ No newline at end of file -- libgit2 0.21.2