From 9289b7e937c559ddad6e49744c733de7ae3d70e0 Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Wed, 22 Oct 2008 00:36:49 +0000 Subject: [PATCH] validação dasopções de getlayrbyname e layer->open --- classesphp/atlas_controle.php | 6 +++--- classesphp/classe_alteraclasse.php | 11 ++++++++++- classesphp/classe_analise.php | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------- classesphp/classe_atributos.php | 25 ++++++++++++++++++------- classesphp/classe_legenda.php | 11 +++++++++-- classesphp/classe_mapa.php | 11 +++++++---- classesphp/classe_navegacao.php | 8 ++++---- classesphp/classe_selecao.php | 19 +++++++++++++++++-- classesphp/classe_shp.php | 18 +++++++----------- classesphp/classe_temas.php | 18 +++++++++++++----- classesphp/classe_toponimia.php | 4 ++++ classesphp/flamingoogc.php | 6 +++--- classesphp/funcoes_gerais.php | 18 +++++++++++++----- 13 files changed, 191 insertions(+), 129 deletions(-) diff --git a/classesphp/atlas_controle.php b/classesphp/atlas_controle.php index 76f92b2..663ecb9 100644 --- a/classesphp/atlas_controle.php +++ b/classesphp/atlas_controle.php @@ -212,10 +212,10 @@ function gravaid() $_SESSION["utilizacgi"] = "nao"; $_SESSION["atlasxml"] = $atlasxmltemp; $m = ms_newMapObj($tmpfname); - $nomes = $m->getalllayernames(); - foreach($nomes as $n) + $c = $m->numlayers; + for ($i=0;$i < $c;++$i) { - $l = $m->getlayerbyname($n); + $l = $m->getlayer($i); $l->setmetadata("ATLAS","nao"); $l->setmetadata("TIP",""); } diff --git a/classesphp/classe_alteraclasse.php b/classesphp/classe_alteraclasse.php index 259ef05..9767064 100644 --- a/classesphp/classe_alteraclasse.php +++ b/classesphp/classe_alteraclasse.php @@ -83,7 +83,7 @@ $tema - nome do tema $this->mapa = ms_newMapObj($map_file); $this->arquivo = $map_file; $this->layer = ""; - if($tema != "") + if($tema != "" && @$this->mapa->getlayerbyname($tema)) $this->layer = $this->mapa->getlayerbyname($tema); $this->nome = $tema; } @@ -106,6 +106,7 @@ Todos os elementos passarão a ser desenhados conforme essa primeira classe, uma */ function simbolounico() { + if(!$this->layer){return "erro";} $numclasses = $this->layer->numclasses; if ($numclasses > 0) { @@ -197,6 +198,7 @@ $ignorar - valor que será ignorado na listagem final */ function intervalosiguais($item,$nclasses,$ignorar) { + if(!$this->layer){return "erro";} $valores = pegaValores($this->mapa,$this->layer,$item,true,$ignorar); if (count($valores) > 0) { @@ -257,6 +259,7 @@ Include: */ function quartis($item,$ignorar) { + if(!$this->layer){return "erro";} $valores = pegaValores($this->mapa,$this->layer,$item,true,$ignorar); if (count($valores) > 0) { @@ -315,6 +318,7 @@ $ignorar - valor que será ignorado na listagem final */ function valorunico($item,$ignorar) { + if(!$this->layer){return "erro";} // pega valores $valoresu = array_unique(pegaValores($this->mapa,$this->layer,$item,false,$ignorar)); // processa array com os valores @@ -367,6 +371,7 @@ A nova classe será uma cópia da classe 0. */ function adicionaclasse() { + if(!$this->layer){return "erro";} $classe = $this->layer->getclass(0); $c = ms_newClassObj($this->layer, $classe); //$classe = $this->layer->getclass(0); @@ -388,6 +393,7 @@ Include: */ function alteraCoresClasses($cori,$corf) { + if(!$this->layer){return "erro";} if(file_exists($this->locaplic."/class.palette.php")) include_once($this->locaplic."/class.palette.php"); else @@ -419,6 +425,7 @@ Inverte as cores da legenda de um tema. */ function inverteCoresClasses() { + if(!$this->layer){return "erro";} $numclasses = $this->layer->numclasses; for($i=0;$i<$numclasses;++$i) { @@ -444,6 +451,7 @@ Calcula o tamanho dos estilos das classes, alterando o tamanho do símbolo. */ function calculaTamanhoClasses() { + if(!$this->layer){return "erro";} $numclasses = $this->layer->numclasses; for($i=0;$i<$numclasses;++$i) { @@ -474,6 +482,7 @@ $classe - id da classe */ function statusClasse($classe) { + if(!$this->layer){return "erro";} $classe = $this->layer->getclass($classe); $status = $classe->status; if ($status == MS_OFF) diff --git a/classesphp/classe_analise.php b/classesphp/classe_analise.php index 65e1744..4dd14f8 100644 --- a/classesphp/classe_analise.php +++ b/classesphp/classe_analise.php @@ -85,7 +85,7 @@ $tema - Nome do tema que será processado $this->locaplic = $locaplic; $this->mapa = ms_newMapObj($map_file); $this->arquivo = $map_file; - if($tema != "") + if($tema != "" && @$this->mapa->getlayerbyname($tema)) $this->layer = $this->mapa->getlayerbyname($tema); $this->nome = $tema; $this->diretorio = dirname($this->arquivo); @@ -906,7 +906,8 @@ $locaplic - Localização do I3geo. $res_count = $layerPt->getNumresults(); $pontos = array(); //pega um shape especifico - $layerPt->open(); + $sopen = $layerPt->open(); + if($sopen == MS_FAILURE){return "erro";} for ($i = 0; $i < $res_count; ++$i) { $result = $layerPt->getResult($i); @@ -947,7 +948,8 @@ $locaplic - Localização do I3geo. $dbname = $nomeshp.".dbf"; foreach($pontos as $ponto) { - $layerPt->open(); + $sopen = $layerPt->open(); + if($sopen == MS_FAILURE){return "erro";} foreach ($itemspt as $ni) {$reg[] = $ponto->values[$ni];} $layerPt->close(); @@ -963,7 +965,8 @@ $locaplic - Localização do I3geo. $ident = @$layer->queryByPoint($pt, 0, 0); $itens = pegaItens($layer); $res_count = $layer->getNumresults(); - $layer->open(); + $sopen = $layer->open(); + if($sopen == MS_FAILURE){return "erro";} if ($res_count > 0) { $result = $layer->getResult(0); @@ -1037,38 +1040,30 @@ function distanciaptpt($temaorigem,$temadestino,$temaoverlay,$locaplic,$itemorig $layerorigem = $this->mapa->getlayerbyname($temaorigem); $layerdestino = $this->mapa->getlayerbyname($temadestino); $layeroverlay = $this->mapa->getlayerbyname($temaoverlay); - if (@$layerorigem->open() == MS_SUCCESS) + $sopen = $layerorigem->open(); + if($sopen == MS_FAILURE){return "erro";} + $res_count = $layerorigem->getNumresults(); + for ($i = 0; $i < $res_count; ++$i) { - $layerorigem->open(); - $res_count = $layerorigem->getNumresults(); - for ($i = 0; $i < $res_count; ++$i) - { - $result = $layerorigem->getResult($i); - $shp_index = $result->shapeindex; - $shapesorigem[] = $layerorigem->getshape(-1, $shp_index); - } - $layerorigem->close(); + $result = $layerorigem->getResult($i); + $shp_index = $result->shapeindex; + $shapesorigem[] = $layerorigem->getshape(-1, $shp_index); } - else - {return "erro";} + $layerorigem->close(); $layeroverlay->set("tolerance",0); $layerdestino->set("tolerance",0); $layeroverlay->queryByrect($this->mapa->extent); $layerdestino->queryByFeatures($layeroverlay->index); - if (@$layerdestino->open() == MS_SUCCESS) + $sopen = $layerdestino->open(); + if($sopen == MS_FAILURE){return "erro";} + $res_count = $layerdestino->getNumresults(); + for ($i = 0; $i < $res_count; ++$i) { - $layerdestino->open(); - $res_count = $layerdestino->getNumresults(); - for ($i = 0; $i < $res_count; ++$i) - { - $result = $layerdestino->getResult($i); - $shp_index = $result->shapeindex; - $shapesdestino[] = $layerdestino->getshape(-1, $shp_index); - } - $layerdestino->close(); + $result = $layerdestino->getResult($i); + $shp_index = $result->shapeindex; + $shapesdestino[] = $layerdestino->getshape(-1, $shp_index); } - else - {return "erro";} + $layerdestino->close(); $rect = $this->mapa->extent; $projInObj = $layerorigem->getProjection(); if ($projInObj == "") @@ -1148,6 +1143,7 @@ nome do layer criado com o buffer. */ function criaBuffer($distancia,$locaplic,$unir="nao") { + if(!$this->layer){return "erro";} set_time_limit(180); //para manipular dbf if(file_exists($this->locaplic."/pacotes/phpxbase/api_conversion.php")) @@ -1159,37 +1155,36 @@ nome do layer criado com o buffer. //pega os shapes selecionados if (file_exists(($this->arquivo)."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} - if (@$this->layer->open() == MS_SUCCESS) + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} + $items = pegaItens($this->layer); + $this->layer->open(); + $res_count = $this->layer->getNumresults(); + $buffers = array(); + //pega um shape especifico + for ($i = 0; $i < $res_count; ++$i) { - $items = pegaItens($this->layer); - $this->layer->open(); - $res_count = $this->layer->getNumresults(); - $buffers = array(); - //pega um shape especifico - for ($i = 0; $i < $res_count; ++$i) - { - $result = $this->layer->getResult($i); - $shp_index = $result->shapeindex; - $shape = $this->layer->getshape(-1, $shp_index); - //calcula a extensão geografica - $rect = $shape->bounds; - $projInObj = ms_newprojectionobj("proj=latlong"); - $projOutObj = ms_newprojectionobj("proj=poly,ellps=GRS67,lat_0=".$rect->miny.",lon_0=".$rect->minx.",x_0=5000000,y_0=10000000"); - $poPoint = ms_newpointobj(); - $poPoint->setXY($rect->minx, $rect->miny); - $dd1 = ms_newpointobj(); - $dd1->setXY($rect->minx, $rect->miny); - $poPoint->project($projInObj, $projOutObj); - $dd2 = ms_newpointobj(); - $dd2->setXY(($poPoint->x + $distancia), $poPoint->y); - $dd2->project($projOutObj,$projInObj); - $d = $dd1->distanceToPoint($dd2); - if ($distancia < 0){$d = $d * -1;} - //calcula a distancia 29100 - //gera o buffer - $buffers[] = $shape->buffer($d); - $shapes[] = $shape; - } + $result = $this->layer->getResult($i); + $shp_index = $result->shapeindex; + $shape = $this->layer->getshape(-1, $shp_index); + //calcula a extensão geografica + $rect = $shape->bounds; + $projInObj = ms_newprojectionobj("proj=latlong"); + $projOutObj = ms_newprojectionobj("proj=poly,ellps=GRS67,lat_0=".$rect->miny.",lon_0=".$rect->minx.",x_0=5000000,y_0=10000000"); + $poPoint = ms_newpointobj(); + $poPoint->setXY($rect->minx, $rect->miny); + $dd1 = ms_newpointobj(); + $dd1->setXY($rect->minx, $rect->miny); + $poPoint->project($projInObj, $projOutObj); + $dd2 = ms_newpointobj(); + $dd2->setXY(($poPoint->x + $distancia), $poPoint->y); + $dd2->project($projOutObj,$projInObj); + $d = $dd1->distanceToPoint($dd2); + if ($distancia < 0){$d = $d * -1;} + //calcula a distancia 29100 + //gera o buffer + $buffers[] = $shape->buffer($d); + $shapes[] = $shape; } //faz a união dos elementos se necessário if($unir == "sim") @@ -1241,7 +1236,6 @@ nome do layer criado com o buffer. $cor->setrgb(255,0,0); $coro = $estilo->outlinecolor; $coro->setrgb(255,0,0); - return($novolayer->name); } /* @@ -1257,6 +1251,7 @@ $locaplic - Localização do I3geo. */ function criaCentroide($locaplic) { + if(!$this->layer){return "erro";} set_time_limit(180); //para manipular dbf if(file_exists($this->locaplic."/pacotes/phpxbase/api_conversion.php")) @@ -1268,26 +1263,25 @@ $locaplic - Localização do I3geo. //pega os shapes selecionados if (file_exists(($this->arquivo)."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} - if (@$this->layer->open() == MS_SUCCESS) + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} + $items = pegaItens($this->layer); + $this->layer->open(); + $res_count = $this->layer->getNumresults(); + $centroides = array(); + $shapes = array(); + //pega um shape especifico + for ($i = 0; $i < $res_count; ++$i) { - $items = pegaItens($this->layer); - $this->layer->open(); - $res_count = $this->layer->getNumresults(); - $centroides = array(); - $shapes = array(); - //pega um shape especifico - for ($i = 0; $i < $res_count; ++$i) - { - $result = $this->layer->getResult($i); - $shp_index = $result->shapeindex; - $shape = $this->layer->getshape(-1, $shp_index); - $LineObj = ms_newLineObj(); - $LineObj->add($shape->getCentroid()); - $ShapeObj = ms_newShapeObj(MS_SHAPE_POINT); - $ShapeObj->add($LineObj); - $centroides[] = $ShapeObj; - $shapes[] = $shape; - } + $result = $this->layer->getResult($i); + $shp_index = $result->shapeindex; + $shape = $this->layer->getshape(-1, $shp_index); + $LineObj = ms_newLineObj(); + $LineObj->add($shape->getCentroid()); + $ShapeObj = ms_newShapeObj(MS_SHAPE_POINT); + $ShapeObj->add($LineObj); + $centroides[] = $ShapeObj; + $shapes[] = $shape; } $fechou = $this->layer->close(); //gera o novo arquivo shape file @@ -1763,7 +1757,8 @@ $locaplic - Localização do I3geo $def[] = array("npontos","N","10","0"); $db = xbase_create($nomeshp.".dbf", $def); $dbname = $nomeshp.".dbf"; - $layerPo->open(); + $sopen = $layerPo->open(); + if($sopen == MS_FAILURE){return "erro";} $layerPo->whichShapes($this->mapa->extent); while ($shape = $layerPo->nextShape()) { @@ -1796,6 +1791,7 @@ Salva o mapa acrescentando um novo layer com o resultado. */ function agrupaElementos($item,$locaplic) { + if(!$this->layer){return "erro";} set_time_limit(180); //para manipular dbf if(!isset($item)){$item="";} @@ -1806,7 +1802,8 @@ Salva o mapa acrescentando um novo layer com o resultado. //define o nome do novo shapefile que será criado if (file_exists(($this->arquivo)."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} - $this->layer->open(); + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} $res_count = $this->layer->getNumresults(); // //pega os indices dos poligonos por classe de atributo @@ -1909,6 +1906,7 @@ $locaplic - Localização do I3geo */ function dissolvePoligono($item,$locaplic) { + if(!$this->layer){return "erro";} set_time_limit(180); //para manipular dbf if(!isset($item)){$item="";} @@ -1919,7 +1917,8 @@ $locaplic - Localização do I3geo //define o nome do novo shapefile que será criado if (file_exists(($this->arquivo)."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} - $this->layer->open(); + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} $res_count = $this->layer->getNumresults(); // //pega os indices dos poligonos por classe de atributo @@ -2305,7 +2304,9 @@ function gravaCoordenadasPt($tema,$limitepontos="TRUE") $res_count = $layerPt->getNumresults(); $pontos = array(); //pega um shape especifico - $layerPt->open(); + $sopen = $layerPt->open(); + if($sopen == MS_FAILURE){return "erro";} + if (($prjTema != "") && ($prjMapa != $prjTema)) { $projInObj = ms_newprojectionobj($prjTema); diff --git a/classesphp/classe_atributos.php b/classesphp/classe_atributos.php index 99a435f..25d1c3c 100644 --- a/classesphp/classe_atributos.php +++ b/classesphp/classe_atributos.php @@ -77,7 +77,7 @@ $tema - nome do tema $this->locaplic = $locaplic; $this->mapa = ms_newMapObj($map_file); $this->arquivo = $map_file; - if($tema != "") + if($tema != "" && @$this->mapa->getlayerbyname($tema)) $this->layer = $this->mapa->getlayerbyname($tema); $this->nome = $tema; } @@ -106,6 +106,7 @@ xmin ymin xmax ymax separados por espaço. */ function extensaoShape($shape) { + if(!$this->layer){return "erro";} $prjMapa = $this->mapa->getProjection(); $prjTema = $this->layer->getProjection(); $ret = $shape->bounds; @@ -141,6 +142,7 @@ $registro - Índice do registro que será consultado. */ function extensaoRegistro($registro) { + if(!$this->layer){return "erro";} $this->layer->set("template","none.htm"); $this->layer->setfilter(""); $ext = ""; @@ -201,6 +203,7 @@ $tipo - Tipo de busca brasil|null */ function itensTexto($tipo) { + if(!$this->layer){return "erro";} if ($tipo == "brasil") {$this->mapa = extPadrao($this->mapa);} $this->layer->set("template","none.htm"); @@ -213,7 +216,8 @@ $tipo - Tipo de busca brasil|null if ($this->layer->getNumresults() > 0){$existesel = "sim";} if ($existesel == "nao") {$this->layer->querybyrect($this->mapa->extent);} - $this->layer->open(); + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} $registros[] = array(); $res_count = $this->layer->getNumresults(); for ($i = 0; $i < $res_count; ++$i) @@ -256,6 +260,7 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona */ function listaRegistros($itemtema,$tipo,$unico,$inicio,$fim,$tipolista) { + if(!$this->layer){return "erro";} $resultadoFinal = array(); if ((!isset($tipolista)) || ($tipolista=="")){$tipolista = "tudo";} if (!isset($inicio)){$inicio = 0;} @@ -276,7 +281,8 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona if (file_exists($this->arquivo."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} $indxlayer = $this->layer->index; - $this->layer->open(); + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} $res_count = $this->layer->getNumresults(); $registros = array(); //lista apenas os selecionados @@ -323,7 +329,8 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona if (($res_count >= $fim) && ($fim < $res_count)) {$res_count = $fim;} } - $this->layer->open(); + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} for ($i = $inicio; $i < $res_count; ++$i) { $valitem = array(); @@ -406,7 +413,8 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) if ($filtro != ""){$l->setfilter("");} $buscas = "ÁÃÓÕÔáàãâóòôõúûíéêç"; $trocas = "AAOOOaaaaoooouuieec"; - $l->open(); + $sopen = $l->open(); + if($sopen == MS_FAILURE){return "erro";} $l->whichShapes($this->mapa->extent); $fr = array(); while ($shape = $l->nextShape()) @@ -465,6 +473,7 @@ Include: */ function estatDescritivas($item,$exclui) { + if(!$this->layer){return "erro";} $this->layer->set("template","none.htm"); $items = pegaItens($this->layer); $valores = array(); @@ -477,7 +486,8 @@ Include: if ($this->layer->getNumresults() > 0){$existesel = "sim";} if ($existesel == "nao") {$this->layer->queryByrect($this->mapa->extent);} - $abriu = $this->layer->open(); + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} $res_count = $this->layer->getNumresults(); //pega os valores for ($i = 0; $i < $res_count; ++$i) @@ -837,7 +847,8 @@ function identificaQBP($tema,$x,$y,$map_file,$resolucao,$item="",$tiporetorno="" } } $res_count = $layer->getNumresults(); - $layer->open(); + $sopen = $layer->open(); + if($sopen == MS_FAILURE){return "erro";} for ($i = 0; $i < $res_count; ++$i) { $valori = array(); diff --git a/classesphp/classe_legenda.php b/classesphp/classe_legenda.php index 9b82442..3024fff 100644 --- a/classesphp/classe_legenda.php +++ b/classesphp/classe_legenda.php @@ -116,7 +116,7 @@ $template - nome do template para processar a legenda $this->mapa = ms_newMapObj($map_file); $this->arquivo = $map_file; $this->localaplicacao = $locaplic; - if ($tema != "") + if($tema != "" && @$this->mapa->getlayerbyname($tema)) { $this->layer = $this->mapa->getlayerbyname($tema); $this->nome = $tema; @@ -296,7 +296,8 @@ array if (($totaliza=="sim") && ($nc > 1)) { $layer->set("template","none.htm"); - $layer->open(); + $sopen = $layer->open(); + if($sopen == MS_FAILURE){return "erro";} $itens = $layer->getitems(); $total = 0; $nreg = array(); @@ -354,6 +355,7 @@ Exclui um estilo de uma classe. */ function excluiEstilo($classe,$estilo) { + if(!$this->layer){return "erro";} $classe = $this->layer->getclass($classe); $classe->deletestyle($estilo); } @@ -367,6 +369,7 @@ objeto estilo */ function adicionaEstilo($classe,$estilo) { + if(!$this->layer){return "erro";} $classe = $this->layer->getclass($classe); $estilo = $classe->getstyle($estilo); $e = ms_newStyleObj($classe,$estilo); @@ -384,6 +387,7 @@ $estilo - Índice do estilo de uma classe que será clonado. */ function sobeEstilo($classe,$estilo) { + if(!$this->layer){return "erro";} $classe = $this->layer->getclass($classe); $classe->movestyleup($estilo); } @@ -399,6 +403,7 @@ $estilo - Índice do estilo de uma classe que será clonado. */ function desceEstilo($classe,$estilo) { + if(!$this->layer){return "erro";} $classe = $this->layer->getclass($classe); $classe->movestyledown($estilo); } @@ -480,6 +485,7 @@ string com o tipo do layer,id do estilo,outlinecolor,backgroundcolor,color,symbo */ function pegaParametros($classe) { + if(!$this->layer){return "erro";} $tipoLayer = $this->layer->type; $classe = $this->layer->getclass($classe); $numestilos = $classe->numstyles; @@ -520,6 +526,7 @@ $size - Tamanho que será aplicado ao símbolo. */ function aplicaParametro($classe,$estilo,$outlinecolor,$backgroundcolor,$color,$symbolname,$size) { + if(!$this->layer){return "erro";} $classe = $this->layer->getclass($classe); $estilo = $classe->getstyle($estilo); if (isset($outlinecolor)) diff --git a/classesphp/classe_mapa.php b/classesphp/classe_mapa.php index b7b077f..e7ebccc 100644 --- a/classesphp/classe_mapa.php +++ b/classesphp/classe_mapa.php @@ -142,10 +142,13 @@ string - javascript com os parametros $sel = "nao"; if ($qy) //verifica se existe alguma selecao no tema { - $oLayer->open(); - $res_count = $oLayer->getNumresults(); - $oLayer->close(); - if ($res_count > 0){$sel = "sim";$existesel = true;} + $sopen = $oLayer->open(); + if($sopen != MS_FAILURE) + { + $res_count = $oLayer->getNumresults(); + $oLayer->close(); + if ($res_count > 0){$sel = "sim";$existesel = true;} + } } if ((strtoupper($oLayer->getmetadata("tema")) != "NAO") && ($oLayer->getmetadata("escondido") == "")) { diff --git a/classesphp/classe_navegacao.php b/classesphp/classe_navegacao.php index 31e76a3..690d186 100644 --- a/classesphp/classe_navegacao.php +++ b/classesphp/classe_navegacao.php @@ -140,10 +140,10 @@ Desliga o status das camadas raster */ function desabilitaRASTER() { - $ls = $this->mapa->getalllayernames(); - foreach ($ls as $l) - { - $layer = $this->mapa->getlayerbyname($l); + $c = $this->mapa->numlayers; + for ($i=0;$i < $c;++$i) + { + $layer = $this->mapa->getlayer($i); if ($layer->type == MS_LAYER_RASTER) {$layer->set("status",MS_OFF);} } diff --git a/classesphp/classe_selecao.php b/classesphp/classe_selecao.php index 1d467cf..9604857 100644 --- a/classesphp/classe_selecao.php +++ b/classesphp/classe_selecao.php @@ -76,6 +76,7 @@ $tema - nome do tema //error_reporting(E_ALL); $this->mapa = ms_newMapObj($map_file); $this->arquivo = $map_file; + if($tema != "" && @$this->mapa->getlayerbyname($tema)) $this->layer = $this->mapa->getlayerbyname($tema); $this->nome = $tema; } @@ -104,6 +105,7 @@ $ys - lista de coordenadas y separadas por virgula */ function selecaoPorPoligono($tipo,$xs,$ys) { + if(!$this->layer){return "erro";} $this->layer->set("tolerance",0); if ($tipo == "limpa") {return($this->selecaoLimpa());} @@ -160,6 +162,7 @@ $tipo - Tipo de operação adiciona|retira|inverte|limpa */ function selecaoTema($temao,$tipo) { + if(!$this->layer){return "erro";} $this->layer->set("tolerance",0); if ($tipo == "limpa") {return($this->selecaoLimpa());} @@ -191,7 +194,8 @@ $tipo - Tipo de operação adiciona|retira|inverte|limpa $selecao = ""; if (($selecao != "ok") && ($layero->data != "")) { - $layero->open(); + $sopen = $layero->open(); + if($sopen == MS_FAILURE){return "erro";} $res_count = $layero->getNumresults(); for ($i = 0; $i < $res_count; ++$i) { @@ -245,7 +249,8 @@ $tipo - Tipo de operação adiciona|retira|inverte|limpa if (($selecao != "ok") && ($layero->data == "")) { $layero->queryByRect($this->mapa->extent); - $layero->open(); + $sopen = $layero->open(); + if($sopen == MS_FAILURE){return "erro";} $conta = $layero->getNumresults(); for ($k = 0; $k < $conta; $k++) { @@ -319,6 +324,7 @@ $valor - Valor. {return($this->selecaoLimpa());} if ($tipo == "inverte") {return($this->selecaoInverte());} + if(!$this->layer){return "erro";} $operador = explode(",",$operador); $operador = $operador[1]; $this->layer->set("template","none.htm"); @@ -373,6 +379,7 @@ $tipo - Tipo de operação adiciona|retira|inverte|limpa {return ($this->selecaoLimpa());} if ($tipo == "inverte") {return ($this->selecaoInverte());} + if(!$this->layer){return "erro";} $this->layer->set("template","none.htm"); if (file_exists(($this->arquivo)."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} @@ -449,6 +456,7 @@ Limpa a seleção do tema. { if ($this->nome != "") //limpa de um tema { + if(!$this->layer){return "erro";} if (file_exists(($this->arquivo)."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} $indxlayer = $this->layer->index; @@ -470,6 +478,7 @@ Inverte seleção do tema. */ function selecaoInverte() { + if(!$this->layer){return "erro";} $this->layer->set("template","none.htm"); if (file_exists(($this->arquivo)."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} @@ -513,6 +522,7 @@ $shp_atual - Indices dos elementos já selecionados. */ function selecaoAdiciona($shpi,$shp_atual) { + if(!$this->layer){return "erro";} $this->layer->set("template","none.htm"); $indxlayer = $this->layer->index; $shp = array_merge($shpi,$shp_atual); @@ -536,6 +546,7 @@ $shp_atual - Indices dos elementos já selecionados. */ function selecaoRetira($shpi,$shp_atual) { + if(!$this->layer){return "erro";} $this->layer->set("template","none.htm"); $indxlayer = $this->layer->index; $this->mapa->freequery($indxlayer); @@ -560,6 +571,7 @@ $ids - Ids separados por vírgula correspondendo aos registros. */ function incluiSel($ids) { + if(!$this->layer){return "erro";} $this->layer->set("template","none.htm"); if (file_exists(($this->arquivo)."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} @@ -583,6 +595,7 @@ $dir_tmp - localização do diretório temporário */ function selecao2tema($locaplic,$dir_tmp) { + if(!$this->layer){return "erro";} $this->layer->set("template","none.htm"); $this->layer->setfilter(""); $nomeshp = criaSHP($this->nome,$this->arquivo,$locaplic,$dir_tmp); @@ -611,6 +624,7 @@ $tipo - Tipo de operação adiciona|retira|inverte|limpa */ function selecaoEXT($tipo) { + if(!$this->layer){return "erro";} $this->layer->set("tolerance",0); if ($tipo == "limpa") {return ($this->selecaoLimpa());} @@ -659,6 +673,7 @@ $ext - coordenadas separadas por espaços no estilo xmin ymin xmax ymax */ function selecaoBOX($tipo,$ext) { + if(!$this->layer){return "erro";} $this->layer->set("tolerance",0); if ($tipo == "limpa") {return ($this->selecaoLimpa());} diff --git a/classesphp/classe_shp.php b/classesphp/classe_shp.php index cf9ab70..9eaea1b 100644 --- a/classesphp/classe_shp.php +++ b/classesphp/classe_shp.php @@ -75,13 +75,11 @@ $tema - nome do tema $this->mapa = ms_newMapObj($map_file); $this->arquivo = $map_file; $this->tema = $tema; - if ($tema != "") + if($tema != "" && @$this->mapa->getlayerbyname($tema)) { $this->layer = $this->mapa->getlayerbyname($tema); - $this->nome = $tema; } - else - {$this->layer = "";} + $this->nome = $tema; } /* function: salva @@ -146,8 +144,7 @@ $projecao - código epsg da projeção das coordenadas */ function insereSHP($xy,$projecao,$item="",$valor="") { - if($this->layer == "") - {return("erro");} + if(!$this->layer){return "erro";} if(file_exists($this->locaplic."/pacotes/phpxbase/api_conversion.php")) include_once($this->locaplic."/pacotes/phpxbase/api_conversion.php"); else @@ -287,9 +284,9 @@ string - xy */ function listaPontosShape() { - if($this->layer == "") - {return("erro");} - $this->layer->open(); + if(!$this->layer){return "erro";} + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} $this->layer->whichShapes($this->mapa->extent); $xy = array(); while ($shape = $this->layer->nextShape()) @@ -318,8 +315,7 @@ $para - linha|poligono include_once($this->locaplic."/pacotes/phpxbase/api_conversion.php"); else include_once "../pacotes/phpxbase/api_conversion.php"; - if($this->layer == "") - {return("erro");} + if(!$this->layer){return "erro";} $this->layer->set("template","none.htm"); $diretorio = dirname($this->arquivo); $tipol = MS_SHP_ARC; diff --git a/classesphp/classe_temas.php b/classesphp/classe_temas.php index be38a9c..1a990aa 100644 --- a/classesphp/classe_temas.php +++ b/classesphp/classe_temas.php @@ -97,9 +97,9 @@ $tema - nome do tema que será processado $this->locaplic = $locaplic; $this->mapa = ms_newMapObj($map_file); $this->arquivo = $map_file; - if (isset($tema)) + if($tema != "" && @$this->mapa->getlayerbyname($tema)) { - $this->layer = @$this->mapa->getlayerbyname($tema); + $this->layer = $this->mapa->getlayerbyname($tema); $this->nome = $tema; $vermultilayer = new vermultilayer(); $vermultilayer->verifica($map_file,$tema); @@ -136,6 +136,7 @@ $lista - lista de processos separados por | */ function aplicaProcessos($lista) { + if(!$this->layer){return "erro";} if ($this->layer->num_processing > 0) {$this->layer->clearProcessing();} $lista = str_replace('"',"",$lista); @@ -342,6 +343,7 @@ Calcula a extensão geográfica de um tema e ajusta o mapa para essa extensão. */ function zoomTema() { + if(!$this->layer){return "erro";} $prjMapa = ""; $prjTema = ""; if($this->layer->type != MS_LAYER_RASTER) @@ -382,6 +384,7 @@ string Filtro. */ function pegaFiltro() { + if(!$this->layer){return "erro";} $fil = $this->layer->getfilter(); if ($this->layer->getfilter() == '"(null)"'){return " ";} if (function_exists("mb_convert_encoding")) @@ -402,6 +405,7 @@ $testa - Testa o filtro e retorna uma imagem. */ function insereFiltro($filtro,$testa="") { + if(!$this->layer){return "erro";} $fil = $this->layer->getfilter(); $filtro = str_replace("|","'",$filtro); if ($this->layer->connectiontype == MS_POSTGIS) @@ -536,7 +540,7 @@ $fonte - Fonte. //verifica se j'a existe um layer criado anteriormente com o mesmo nome e apaga se existir if ($tipo == "limpaponto") { - if ($this->layer != "") + if ($this->layer) { $this->layer->set("status",MS_DELETE); $this->layer->set("name","pindelete"); @@ -544,7 +548,7 @@ $fonte - Fonte. } } //se o novo layer nao existir, cria um novo copiando o layer "pin" que ja deve existir no map file (no map file que iniciou a aplicacao) - if ($this->layer == "") + if (!$this->layer) { $pinlayer = criaLayer($this->mapa,MS_LAYER_LINE,MS_DEFAULT,"Ins",$metaClasse="SIM"); $c = $pinlayer->getclass(0); @@ -674,6 +678,7 @@ $nome - nome que será dado a geometria */ function capturaGeometrias($dir_tmp,$imgdir,$nome="") { + if(!$this->layer){return "erro";} $this->mapa->setsize(30,30); $ext = $this->mapa->extent; $sb = $this->mapa->scalebar; @@ -681,7 +686,9 @@ $nome - nome que será dado a geometria if (file_exists($this->arquivo."qy")) {$this->mapa->loadquery(($this->arquivo)."qy");} $items = pegaItens($this->layer); - $this->layer->open(); + $sopen = $this->layer->open(); + if($sopen == MS_FAILURE){return "erro";} + $res_count = $this->layer->getNumresults(); $final["layer"] = pegaNome($this->layer); $registros = array(); @@ -791,6 +798,7 @@ lista - lista de item e cores de cada parte do grafico */ function graficotema($lista,$tamanho="50",$tipo="PIE",$outlinecolor="",$offset=0) { + if(!$this->layer){return "erro";} $nome = pegaNome($this->layer); $novolayer = ms_newLayerObj($this->mapa, $this->layer); $nomer = nomeRandomico(); diff --git a/classesphp/classe_toponimia.php b/classesphp/classe_toponimia.php index c70b4f9..53d35c9 100644 --- a/classesphp/classe_toponimia.php +++ b/classesphp/classe_toponimia.php @@ -81,6 +81,7 @@ $tema - nome do tema que será processado include_once("funcoes_gerais.php"); $this->mapa = ms_newMapObj($map_file); $this->arquivo = $map_file; + if($tema != "" && @$this->mapa->getlayerbyname($tema)) $this->layer = $this->mapa->getlayerbyname($tema); $this->nome = $tema; } @@ -144,6 +145,7 @@ $tipo Tipo teste| */ function criaToponimia($item,$position,$partials,$offsetx,$offsety,$minfeaturesize,$mindistance,$force,$shadowcolor,$shadowsizex,$shadowsizey,$outlinecolor,$cor,$sombray,$sombrax,$sombra,$fundo,$angulo,$tamanho,$fonte,$tipo) { + if(!$this->layer){return "erro";} if (!isset($tipo)){$tipo = "";} if ($item != "") //o layer nao tem tabela mas tem toponimia { @@ -230,6 +232,7 @@ $item Item que será utilizado. */ function ativaEtiquetas($item) { + if(!$this->layer){return "erro";} $this->layer->setmetadata("TIP",$item); return("ok"); } @@ -241,6 +244,7 @@ remove a inclusão de etiquetas em um tema. */ function removeEtiquetas() { + if(!$this->layer){return "erro";} $this->layer->setmetadata("TIP",""); return("ok"); } diff --git a/classesphp/flamingoogc.php b/classesphp/flamingoogc.php index 401dce3..121d0b7 100644 --- a/classesphp/flamingoogc.php +++ b/classesphp/flamingoogc.php @@ -92,10 +92,10 @@ foreach(array_keys($_SESSION) as $k) } $postgis_mapa = $_SESSION["postgis_mapa"]; $nmap = ms_newMapobj($map_file); -$ts = $nmap->getalllayernames(); -foreach ($ts as $t) +$c = $nmap->numlayers; +for ($i=0;$i < $c;++$i) { - $l = $nmap->getlayerbyname($t); + $l = $nmap->getlayer($i);} if($l->connectiontype != MS_WMS) { $l->setmetadata("ows_title",pegaNome($l)); diff --git a/classesphp/funcoes_gerais.php b/classesphp/funcoes_gerais.php index 30407ba..feeeda4 100644 --- a/classesphp/funcoes_gerais.php +++ b/classesphp/funcoes_gerais.php @@ -1020,7 +1020,8 @@ function pegaValores($mapa,$layer,$item,$numerico=false,$ignorar="") $layer->setfilter(""); if (@$layer->queryByrect($mapa->extent) == MS_SUCCESS) { - $layer->open(); + $sopen = $layer->open(); + if($sopen == MS_FAILURE){return "erro";} $res_count = $layer->getNumresults(); $valitem = array(); for ($i=0;$i<$res_count;++$i) @@ -1083,7 +1084,8 @@ function pegaValoresM($mapa,$layer,$itens,$exclui="nulo",$selecionados="nao") //pega os valores dos indices dos elementos selecionados para comparacao posterior if ($selecionados == "sim") { - $layer->open(); + $sopen = $layer->open(); + if($sopen == MS_FAILURE){return "erro";} $res_count = $layer->getNumresults(); for ($i = 0; $i < $res_count; ++$i) { @@ -1095,7 +1097,9 @@ function pegaValoresM($mapa,$layer,$itens,$exclui="nulo",$selecionados="nao") $valores = array(); if (@$layer->queryByrect($mapa->extent) == MS_SUCCESS) { - $layer->open(); + $sopen = $layer->open(); + if($sopen == MS_FAILURE){return "erro";} + $res_count = $layer->getNumresults(); for ($i=0;$i<$res_count;++$i) { @@ -1616,7 +1620,9 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) $res_count = $layer->getNumresults(); if ($res_count > 0) { - $abriu = $layer->open(); + $sopen = $layer->open(); + if($sopen == MS_FAILURE){return "erro";} + for ($i = 0; $i < $res_count; ++$i) { $result = $layer->getResult($i); @@ -1932,7 +1938,9 @@ function autoClasses(&$nlayer,$mapa) $ret->setextent($temp[0],$temp[1],$temp[2],$temp[3]); } // - $nlayer->open(); + $sopen = $nlayer->open(); + if($sopen == MS_FAILURE){return "erro";} + $status = $nlayer->whichShapes($ret); $parametrosClasses = array(); if ($status == 0) -- libgit2 0.21.2