From 5d3989bc6bdefafcddfd2d406a3c12f26d751099 Mon Sep 17 00:00:00 2001 From: edmarmoretti Date: Mon, 8 Aug 2016 13:52:41 -0300 Subject: [PATCH] Atualização do código --- classesphp/classe_selecao.php | 75 +++++++++++++++++++++++++++++++++++++-------------------------------------- classesphp/funcoes_gerais.php | 30 ++++++++++++++++++++++++++++++ ferramentas/parametrossql/ogc.php | 19 ++++++++++++++----- ogc.php | 7 ++++--- 4 files changed, 85 insertions(+), 46 deletions(-) diff --git a/classesphp/classe_selecao.php b/classesphp/classe_selecao.php index b51c828..bf3fe46 100755 --- a/classesphp/classe_selecao.php +++ b/classesphp/classe_selecao.php @@ -99,6 +99,8 @@ $ext - extensão geográfica do mapa function __construct($map_file,$tema="",$ext="") { include_once(dirname(__FILE__)."/funcoes_gerais.php"); + include(dirname(__FILE__)."/../ms_configura.php"); + $this->postgis_mapa = $postgis_mapa; $this->v = versao(); $this->v = $this->v["principal"]; $this->qyfile = str_replace(".map",".qy",$map_file); @@ -108,7 +110,10 @@ $ext - extensão geográfica do mapa else{ $this->qyfileTema = ""; } + $this->mapa = ms_newMapObj($map_file); + substituiConObj($this->mapa,$postgis_mapa); + $this->arquivo = str_replace(".map","",$map_file).".map"; if($tema != "" && @$this->mapa->getlayerbyname($tema)) $this->layer = $this->mapa->getlayerbyname($tema); @@ -134,13 +139,12 @@ function: salva Salva o mapfile atual */ - function salva() - { - if($this->mapa->getmetadata("interface") == "googlemaps") - {$this->mapa->setProjection($this->projO);} + function salva(){ + if($this->mapa->getmetadata("interface") == "googlemaps"){ + $this->mapa->setProjection($this->projO); + } $this->mapa->save($this->arquivo); - include(dirname(__FILE__)."/../ms_configura.php"); - restauraCon($this->arquivo,$postgis_mapa); + restauraCon($this->arquivo,$this->postgis_mapa); } /* function: nSel @@ -165,7 +169,7 @@ $ys - lista de coordenadas y separadas por virgula $wkt - string wkt opcional ao uso de xs e ys -$buffer - buffer que será aplicado +$buffer - buffer que ser� aplicado */ function selecaoPorPoligono($tipo,$xs="",$ys="",$wkt="",$buffer=0) { @@ -730,10 +734,10 @@ $shp_atual - Indices dos elementos já selecionados. $indxlayer = $this->layer->index; $shp = array_merge($shpi,$shp_atual); $shp = array_unique($shp); + $this->mapa->freequery($indxlayer); foreach ($shp as $indx) {@$this->mapa->querybyindex($indxlayer,-1,$indx,MS_TRUE);} - //echo $this->layer->getNumresults(); $this->mapa->savequery($this->qyfile); $this->serializeQ($this->qyfileTema,$shp); return("ok"); @@ -891,58 +895,53 @@ $tipo - Tipo de operação adiciona|retira|inverte|limpa|novo $ext - coordenadas separadas por espaços no estilo xmin ymin xmax ymax */ - function selecaoBOX($tipo,$ext) - { - if ($tipo == "novo") - { + function selecaoBOX($tipo,$ext) { + if ($tipo == "novo"){ $this->selecaoLimpa(); $tipo = "adiciona"; } - if(!$this->layer){return "erro";} + if(!$this->layer){ + return "erro"; + } $this->layer->set("tolerance",0); - if ($tipo == "limpa") - {return ($this->selecaoLimpa());} - if ($tipo == "inverte") - {return ($this->selecaoInverte());} - if (file_exists($this->qyfile)) - {$this->mapa->loadquery($this->qyfile);} + if ($tipo == "limpa"){ + return ($this->selecaoLimpa()); + } + if ($tipo == "inverte") { + return ($this->selecaoInverte()); + } + if (file_exists($this->qyfile)) { + $this->mapa->loadquery($this->qyfile); + } $indxlayer = $this->layer->index; - /* - $res_count = $this->layer->getNumresults(); $shp_atual = array(); - for ($i = 0; $i < $res_count;++$i) - { - $rc = $this->layer->getResult($i); - $shp_atual[] = $rc->shapeindex; + if($this->qyfileTema != "" && file_exists($this->qyfileTema)) { + $shp_atual = $this->unserializeQ($this->qyfileTema); } - $this->mapa->freequery($indxlayer); - */ - $shp_atual = array(); - if($this->qyfileTema != "" && file_exists($this->qyfileTema)) - {$shp_atual = $this->unserializeQ($this->qyfileTema);} $shpi = array(); $temp = explode(" ",$ext); $rect = ms_newRectObj(); + $rect->set("minx",(min(array($temp[0],$temp[2])))); $rect->set("miny",(min(array($temp[1],$temp[3])))); $rect->set("maxx",(max(array($temp[0],$temp[2])))); $rect->set("maxy",(max(array($temp[1],$temp[3])))); $ident = $this->layer->queryByRect($rect); - if ($ident != 1) - { + if ($ident != 1){ $res_count = $this->layer->getNumresults(); $shpi = array(); - for ($i = 0; $i < $res_count; ++$i) - { + for ($i = 0; $i < $res_count; ++$i) { $result = $this->layer->getResult($i); $shpi[] = $result->shapeindex; } } - if ($tipo == "adiciona") - {return($this->selecaoAdiciona($shpi,$shp_atual));} - if ($tipo == "retira") - {return($this->selecaoRetira($shpi,$shp_atual));} + if ($tipo == "adiciona"){ + return($this->selecaoAdiciona($shpi,$shp_atual)); + } + if ($tipo == "retira"){ + return($this->selecaoRetira($shpi,$shp_atual)); + } } /* function unserializeQ diff --git a/classesphp/funcoes_gerais.php b/classesphp/funcoes_gerais.php index 0e250a7..cd06ca0 100755 --- a/classesphp/funcoes_gerais.php +++ b/classesphp/funcoes_gerais.php @@ -570,6 +570,36 @@ function substituiCon($map_file,$postgis_mapa) } return true; } +function substituiConObj($objMap,$postgis_mapa){ + error_reporting(0); + if (!empty($postgis_mapa)){ + $numlayers = $objMap->numlayers; + for ($i=0;$i < $numlayers;++$i) + { + $layer = $objMap->getlayer($i); + if ($layer->connectiontype == MS_POSTGIS) + { + $lcon = $layer->connection; + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))) + { + // + //o metadata CONEXAOORIGINAL guarda o valor original para posterior substituição + // + if(($lcon == " ") || ($lcon == "")) + { + $layer->set("connection",$postgis_mapa); + $layer->setmetadata("CONEXAOORIGINAL",$lcon); + } + else + { + $layer->set("connection",$postgis_mapa[$lcon]); + $layer->setmetadata("CONEXAOORIGINAL",$lcon); + } + } + } + } + } +} /* Function: restauraCon diff --git a/ferramentas/parametrossql/ogc.php b/ferramentas/parametrossql/ogc.php index 815e487..457aa2d 100755 --- a/ferramentas/parametrossql/ogc.php +++ b/ferramentas/parametrossql/ogc.php @@ -9,13 +9,16 @@ A diferenca e que esse servico processa o parametro "plugin", aplicando os filtr no plugin parametrossql */ $cache = true; -require_once(dirname(__FILE__)."/../../classesphp/carrega_ext.php"); +include(dirname(__FILE__)."/classesphp/sani_request.php"); include(dirname(__FILE__)."/../../ms_configura.php"); -include(dirname(__FILE__)."/../../classesphp/pega_variaveis.php"); include(dirname(__FILE__)."/../../classesphp/funcoes_gerais.php"); +$_GET = array_merge($_GET,$_POST); $projDefault = pegaProjecaoDefault(); -$temas = $tema; +$tema = basename($_GET["tema"]); +if($tema == ""){ + exit; +} if(isset($_GET["sld"]) || isset($_GET["filter"])){ $cache = false; } @@ -41,7 +44,7 @@ if($_GET["SRS"] == "EPSG:900913"){ $_GET["SRS"] = "EPSG:3857"; } $req = ms_newowsrequestobj(); -$_GET = array_merge($_GET,$_POST); + if(!isset($_GET["srs"]) && !isset($_GET["SRS"])){ $_GET["srs"] = "EPSG:".$projDefault["epsg"]; } @@ -72,13 +75,14 @@ $agora = intval(time() / 1000); if(isset($_GET["Z"]) && isset($_GET["X"])){ $agora .= "google"; } -$nomeMapfileTmp = $dir_tmp."/ogc_".md5($tema.$plugin.($req->getValueByName("SRS")))."_".$agora.".map"; +$nomeMapfileTmp = $dir_tmp."/ogcpsql_".md5($tema.$plugin.($req->getValueByName("SRS")))."_".$agora.".map"; $nomeMapfileTmp = str_replace(",","",$nomeMapfileTmp); $nomeMapfileTmp = str_replace(" ","",$nomeMapfileTmp); //essa variavel e usada para definir se a imagem final gerada devera ser cortada ou nao $cortePixels = 0; if(file_exists($nomeMapfileTmp)){ $oMap = ms_newMapobj($nomeMapfileTmp); + substituiConObj($oMap,$postgis_mapa); } else{ if(empty($ogcwsmap)){ @@ -218,12 +222,15 @@ else{ $oMap->setSymbolSet($locaplic."/symbols/".basename($oMap->symbolsetfilename)); $oMap->setFontSet($locaplic."/symbols/".basename($oMap->fontsetfilename)); + $nomeMapfileTmp = str_replace(".map","",$nomeMapfileTmp).".map"; $oMap->save($nomeMapfileTmp); + $oMap = ms_newMapobj($nomeMapfileTmp); } if(ob_get_contents ()){ ob_end_clean(); } +restauraCon($nomeMapfileTmp,$postgis_mapa); // //verifica se a requisicao e do tipo TMS. // @@ -570,6 +577,8 @@ function salvaCacheImagem($cachedir,$map,$tms, $plugin, $tema){ exit; } function execProg($prog){ + $prog = str_replace(".php","",$prog); + $prog = str_replace(".","",$prog).".php"; include($prog); //$retorno variavel deve ser retornada pelo programa $prog //veja como exemplo i3geo/aplicmap/daods/listaano.php diff --git a/ogc.php b/ogc.php index c4d7799..7b5cdc8 100755 --- a/ogc.php +++ b/ogc.php @@ -371,9 +371,11 @@ $cortePixels = 0; $ogcwsmap = $_GET["ogcwsmap"]; if(file_exists($nomeMapfileTmp) && $tipo == ""){ - substituiCon($nomeMapfileTmp,$postgis_mapa); + //substituiCon($nomeMapfileTmp,$postgis_mapa); + //$oMap = ms_newMapobj($nomeMapfileTmp); + //restauraCon($nomeMapfileTmp,$postgis_mapa); $oMap = ms_newMapobj($nomeMapfileTmp); - restauraCon($nomeMapfileTmp,$postgis_mapa); + substituiConObj($oMap,$postgis_mapa); } else{ if(empty($ogcwsmap)){ @@ -764,7 +766,6 @@ else{ $oMap->save($nomeMapfileTmp); validaAcessoTemas($nomeMapfileTmp,true); - substituiCon($nomeMapfileTmp,$postgis_mapa); $oMap = ms_newMapobj($nomeMapfileTmp); restauraCon($nomeMapfileTmp,$postgis_mapa); -- libgit2 0.21.2