From 965f17fc989413f6e68f0d463257b6196747299b Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Thu, 17 Dec 2015 12:51:33 +0000 Subject: [PATCH] Correção na projecao de dados em projecao AUTO e download --- admin/admin.db | Bin 323584 -> 0 bytes classesphp/classe_analise.php | 29 ++++++++++++----------------- classesphp/funcoes_gerais.php | 82 ++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------- 3 files changed, 60 insertions(+), 51 deletions(-) diff --git a/admin/admin.db b/admin/admin.db index aa404fb..7b5223b 100644 Binary files a/admin/admin.db and b/admin/admin.db differ diff --git a/classesphp/classe_analise.php b/classesphp/classe_analise.php index a94f7e7..023d674 100644 --- a/classesphp/classe_analise.php +++ b/classesphp/classe_analise.php @@ -1274,8 +1274,7 @@ class Analise $layerdestino->close(); $rect = $this->mapa->extent; $projInObj = $layerorigem->getProjection(); - if ($projInObj == "") - { + if ($projInObj == ""){ $projInObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs"); } $projOutObj = ms_newprojectionobj("proj=poly,ellps=GRS67,lat_0=".$rect->miny.",lon_0=".$rect->minx.",x_0=5000000,y_0=10000000"); @@ -1291,12 +1290,11 @@ class Analise $def[] = array("dist_m","N","10","2"); $def[] = array("origem","C","255"); $def[] = array("destino","C","255"); - if($this->dbaseExiste == false) - { + if($this->dbaseExiste == false){ $db = xbase_create($nomeshp.".dbf", $def);xbase_close($db); } - else - {$db = dbase_create($nomeshp.".dbf", $def);dbase_close($db); + else{ + $db = dbase_create($nomeshp.".dbf", $def);dbase_close($db); } //acrescenta os pontos no novo shapefile $dbname = $nomeshp.".dbf"; @@ -1304,26 +1302,23 @@ class Analise $db=xbase_open($dbname,2); else $db=dbase_open($dbname,2); - foreach ($shapesorigem as $sorigem) - { - if($itemorigem != "") - { + foreach ($shapesorigem as $sorigem){ + if($itemorigem != ""){ $valororigem = $sorigem->values[$itemorigem]; } - else - {$valororigem = ""; + else{ + $valororigem = ""; } foreach ($shapesdestino as $sdestino) { $linha = ms_newLineObj(); $linha->add($sorigem->getCentroid()); $linha->add($sdestino->getCentroid()); - if($itemdestino != "") - { + if($itemdestino != ""){ $valordestino = $sdestino->values[$itemdestino]; } - else - {$valordestino = ""; + else{ + $valordestino = ""; } $ShapeObj = ms_newShapeObj(MS_SHAPE_LINE); $ShapeObj->add($linha); @@ -1619,7 +1614,7 @@ class Analise $nomeCentroides = nomeRandomico(); $nomeshp = $this->diretorio."/".$nomeCentroides; $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa); - + //$shapes = $shape[0]; foreach($shapes as $shape){ $LineObj = ms_newLineObj(); diff --git a/classesphp/funcoes_gerais.php b/classesphp/funcoes_gerais.php index 9b3147d..f7f5466 100644 --- a/classesphp/funcoes_gerais.php +++ b/classesphp/funcoes_gerais.php @@ -1395,11 +1395,13 @@ $dir_tmp {string} - Diretório temporário $nomeRand {boleano} - Gera um nome randomico para o shapefile (TRUE) ou utiliza o nome do tema (FALSE) +$prj {string} - String que sera gravada no arquivo prj + Retorno: {string} - nome do arquivo criado ou false se ocorrer erro */ -function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) +function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE,$prj="") { $versao = versao(); $versao = $versao["principal"]; @@ -1412,6 +1414,18 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) } $map = @ms_newMapObj($map_file); $layer = $map->getlayerbyname($tema); + //e necessario abrir ou nao vai projetar + $layer->open(); + $prjMapa = $map->getProjection(); + $prjTema = $layer->getProjection(); + if($prjTema != ""){ + $projInObj = new projectionObj($prjTema); + $projOutObj = new projectionObj($prjMapa); + } + else{ + $projInObj = ""; + $projOutObj = ""; + } $layer->set("template","none.htm"); $diretorio = dirname($dir_tmp); @@ -1468,7 +1482,7 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) $resultadoFinal = true; } else{ - $shapesSel = retornaShapesSelecionados($layer,$map_file,$map); + $shapesSel = retornaShapesSelecionados($layer,$map_file,$map,false); $items = pegaItens($layer); // cria o dbf $def = array(); @@ -1482,10 +1496,12 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) $def[] = array($temp,"C","254"); $cni = $cni + 1; } - if(!function_exists("dbase_create")) - {$db = xbase_create($nomeshp.".dbf", $def);} - else - {$db = dbase_create($nomeshp.".dbf", $def);} + if(!function_exists("dbase_create")){ + $db = xbase_create($nomeshp.".dbf", $def); + } + else{ + $db = dbase_create($nomeshp.".dbf", $def); + } $dbname = $nomeshp.".dbf"; $reg = array(); $novoshpf = ms_newShapefileObj($nomeshp.".shp", -2); @@ -1494,8 +1510,8 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) if ($res_count > 0){ for ($i = 0; $i < $res_count; ++$i){ $shape = $shapesSel[$i]; - foreach ($items as $ni) - { + $shape->project($projInObj, $projOutObj); + foreach ($items as $ni){ $vreg = $shape->values[$ni]; if(strlen($vreg) > 255){ $vreg = substr($vreg,0,255); @@ -1513,7 +1529,6 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) xbase_close($db); else dbase_close($db); - $layer->close(); // //verifica a quantidade de registros no final // @@ -1538,6 +1553,8 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) {unlink($nomeshp.".shp");} if(file_exists($nomeshp.".shx")) {unlink($nomeshp.".shx");} + if(file_exists($nomeshp.".prj")) + {unlink($nomeshp.".prj");} $resultadoFinal = false; } } @@ -1550,20 +1567,9 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) } else{ //gera o arquivo prj - /* - if(!file_exists($nomeshp.".prj")){ - $projecao = $layer->getProjection(); - if($projecao == ""){ - $projecao = $map->getProjection(); - } - include($locaplic."/pacotes/proj4php-proj4php5.2/src/proj4php/proj4php.php"); - - $proj4 = new Proj4php(); - $projWGS84 = new Proj4phpProj('EPSG:4326',$proj4); - echo $projWGS84->projection;exit; - + if($prj != ""){ + gravaDados(array($prj),$nomeshp.".prj"); } - */ return $nomeshp; } } @@ -1618,7 +1624,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) //cria o arquivo mapfile, caso ele não exista, que servirá de base para obtenção dos dados // $nomeRand = true; - //echo $versao;exit; + $projecao = pegaProjecaoDefault(); if (($map_file == "") || (!@ms_newMapObj($map_file))){ //a funcao foi chamada do aplicativo datadownload if($base == "" or !isset($base)){ $base = ""; @@ -1647,6 +1653,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) } $map_tmp = ms_newMapObj($base); $map_file = $dir_tmp."/".nomerandomico(20).".map"; + $map_tmp->setProjection($projecao["proj4"]); $map_tmp->save($map_file); $nomeRand = false; } @@ -1830,12 +1837,19 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) } // //se nao existir selecao seleciona por box + //o box vem do mapfile original // if(!file_exists($sel->qyfile) || $numSel < 1){ $box = $rectextent->minx." ".$rectextent->miny." ".$rectextent->maxx." ".$rectextent->maxy; $sel->selecaoBOX("novo",$box); + //reaproveita arquivo anterior + $nomeRand = false; + } + $nomeshp = criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand,$projecao["prj"]); + //remove o arquivo de selecao se ele foi criado apenas para pegar todos os elementos + if($nomeRand == false){ + $sel->selecaoLimpa(); } - $nomeshp = criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand); if($nomeshp == false){ return array("arquivos"=>"Ocorreu um erro, tente novamente","nreg"=>0); } @@ -1847,6 +1861,9 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) $resultado[] = str_replace($radtmp."/","",$nomeshp).".dbf"; $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".dbf")); + + $resultado[] = str_replace($radtmp."/","",$nomeshp).".prj"; + $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".prj")); } } } @@ -2500,17 +2517,17 @@ function retornaShapesMapext($objLayer,$objMapa){ function retornaShapesSelecionados($objLayer,$map_file,$objMapa,$indexado=false){ $shapes = array(); $qyfile = dirname($map_file)."/".$objLayer->name.".php"; - - if(!file_exists($qyfile)) - {return $shapes;} + if(!file_exists($qyfile)){ + return $shapes; + } $handle = fopen ($qyfile, "r"); $conteudo = fread ($handle, filesize ($qyfile)); fclose ($handle); $listaDeIndices = unserialize($conteudo); - //echo count($listaDeIndices);exit; - if(count($listaDeIndices) == 0) - {return $shapes;} + if(count($listaDeIndices) == 0){ + return $shapes; + } $versao = versao(); $versao = $versao["principal"]; @@ -2521,14 +2538,11 @@ function retornaShapesSelecionados($objLayer,$map_file,$objMapa,$indexado=false) $sopen = $objLayer->open(); if($sopen == MS_FAILURE){return "erro";} - $objLayer->open(); $res_count = $objLayer->getNumresults(); $centroides = array(); $shapes = array(); //pega um shape especifico - - for ($i = 0; $i < $res_count; ++$i) - { + for ($i = 0; $i < $res_count; ++$i){ if($versao >= 6){ $shape = $objLayer->getShape($objLayer->getResult($i)); $shp_index = $shape->index; -- libgit2 0.21.2