0){ $itensrelTemp = explode(",",$itensrel); $itensrel = array(); $colunas = array(); $n = count($colunasTemp); for($i=0;$i<$n;$i++){ $colunas[$ordem[$i]] = $colunasTemp[$i]; $t1[$ordem[$i]] = $t1Temp[$i]; $itensrel[$ordem[$i]] = $itensrelTemp[$i]; } if(count($colunas) == count($colunasTemp)){ ksort($colunas); ksort($t1); ksort($itensrel); $itensrel = implode(",",$itensrel); } } else{ $colunas = $colunasTemp; $t1 = $t1Temp; } if($itemagruparel != "" && !in_array($itemagruparel,$colunas)) {$colunas[] = $itemagruparel;} $temp = explode(",",$itensrel); $itensrel = array(); foreach($temp as $t) { $t1=explode("|",$t); $itensrel[] = $t1[0]; } if($itemagruparel != "" && !in_array($itemagruparel,$itensrel)) {$itensrel[] = $itemagruparel;} $mapa = ms_newMapObj($map_file); if($ext && $ext != ""){ $e = explode(" ",$ext); $extatual = $mapa->extent; $extatual->setextent((min($e[0],$e[2])),(min($e[1],$e[3])),(max($e[0],$e[2])),(max($e[1],$e[3]))); } $layer = $mapa->getlayerbyname($temarel); $layer->set("template","none.html"); //$layer->set("data",$layer->data."options='-c client_encoding=LATIN1'"); $existesel = "nao"; /* if (file_exists($map_file."qy")) {$mapa->loadquery($map_file."qy");} */ carregaquery2($map_file,$layer,$mapa); if ($layer->getNumresults() > 0){$existesel = "sim";} if ($existesel == "nao") {$layer->querybyrect($mapa->extent);} $layer->open(); if(strtoupper($layer->getmetadata("convcaracter")) == "NAO") {$convC = false;} else {$convC = true;} //$registros[] = array(); $res_count = $layer->getNumresults(); for ($i = 0; $i < $res_count; $i++){ $valitem = array(); if($versao == 6){ $shape = $layer->getShape($layer->getResult($i)); } else{ $shape = $layer->getFeature($layer->getResult($i)->shapeindex); } $grupo = ""; foreach ($itensrel as $item){ $v = trim($shape->values[$item]); //$v = mb_convert_encoding($v,mb_detect_encoding($v),"ISO-8859-1"); if (function_exists("mb_convert_encoding") && $convC == true){ //$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(); restauraCon($map_file,$postgis_mapa); if(isset($tiporel) && $tiporel == "csv"){ echo "
";
	echo implode(";",explode(",",$nomesrel));
	if($arearel == "true")
	{echo ";área em ha \n";}
	else
	{echo "\n";}
	foreach ($registros as $linhas){
		echo converte(implode(";",$linhas))."\n";
	}
	exit;
}
?>




Relatório do tema: ".converte($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){ if(is_numeric(trim($v))){ echo ""; } else{ 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
".number_format($v,2,",",".")."".converte($v)."
soma".number_format($s,2,",",".")."
média".number_format(($s / $ocorrencias),2,",",".")."
"; } 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) { if(is_numeric(trim($v))) {echo "";} else {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
".number_format($v,2,",",".")."".converte($v)."
soma".number_format($s,2,",",".")."
média".number_format(($s / $ocorrencias),2,",",".")."
"; } } function calculaarea($geo) { global $postgis_con; $v = versao(); if (($v["principal"] < 5) && ($postgis_con == "")) {return ("erro. É necessária uma versão maior que 5.0 do Mapserver.");} $g = $geo->towkt(); $shape = ms_shapeObjFromWkt($g); $rect = $shape->bounds; $projInObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs"); $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 / 10000; } function converte($texto) { if (!mb_detect_encoding($texto,"UTF-8",true)) { $texto = mb_convert_encoding($texto,"UTF-8","ISO-8859-1"); } return $texto; } ?>