Commit 965f17fc989413f6e68f0d463257b6196747299b

Authored by Edmar Moretti
1 parent 50159d0b

Correção na projecao de dados em projecao AUTO e download

admin/admin.db
No preview for this file type
classesphp/classe_analise.php
... ... @@ -1274,8 +1274,7 @@ class Analise
1274 1274 $layerdestino->close();
1275 1275 $rect = $this->mapa->extent;
1276 1276 $projInObj = $layerorigem->getProjection();
1277   - if ($projInObj == "")
1278   - {
  1277 + if ($projInObj == ""){
1279 1278 $projInObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs");
1280 1279 }
1281 1280 $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
1291 1290 $def[] = array("dist_m","N","10","2");
1292 1291 $def[] = array("origem","C","255");
1293 1292 $def[] = array("destino","C","255");
1294   - if($this->dbaseExiste == false)
1295   - {
  1293 + if($this->dbaseExiste == false){
1296 1294 $db = xbase_create($nomeshp.".dbf", $def);xbase_close($db);
1297 1295 }
1298   - else
1299   - {$db = dbase_create($nomeshp.".dbf", $def);dbase_close($db);
  1296 + else{
  1297 + $db = dbase_create($nomeshp.".dbf", $def);dbase_close($db);
1300 1298 }
1301 1299 //acrescenta os pontos no novo shapefile
1302 1300 $dbname = $nomeshp.".dbf";
... ... @@ -1304,26 +1302,23 @@ class Analise
1304 1302 $db=xbase_open($dbname,2);
1305 1303 else
1306 1304 $db=dbase_open($dbname,2);
1307   - foreach ($shapesorigem as $sorigem)
1308   - {
1309   - if($itemorigem != "")
1310   - {
  1305 + foreach ($shapesorigem as $sorigem){
  1306 + if($itemorigem != ""){
1311 1307 $valororigem = $sorigem->values[$itemorigem];
1312 1308 }
1313   - else
1314   - {$valororigem = "";
  1309 + else{
  1310 + $valororigem = "";
1315 1311 }
1316 1312 foreach ($shapesdestino as $sdestino)
1317 1313 {
1318 1314 $linha = ms_newLineObj();
1319 1315 $linha->add($sorigem->getCentroid());
1320 1316 $linha->add($sdestino->getCentroid());
1321   - if($itemdestino != "")
1322   - {
  1317 + if($itemdestino != ""){
1323 1318 $valordestino = $sdestino->values[$itemdestino];
1324 1319 }
1325   - else
1326   - {$valordestino = "";
  1320 + else{
  1321 + $valordestino = "";
1327 1322 }
1328 1323 $ShapeObj = ms_newShapeObj(MS_SHAPE_LINE);
1329 1324 $ShapeObj->add($linha);
... ... @@ -1619,7 +1614,7 @@ class Analise
1619 1614 $nomeCentroides = nomeRandomico();
1620 1615 $nomeshp = $this->diretorio."/".$nomeCentroides;
1621 1616 $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
1622   -
  1617 +
1623 1618 //$shapes = $shape[0];
1624 1619 foreach($shapes as $shape){
1625 1620 $LineObj = ms_newLineObj();
... ...
classesphp/funcoes_gerais.php
... ... @@ -1395,11 +1395,13 @@ $dir_tmp {string} - Diretório temporário
1395 1395  
1396 1396 $nomeRand {boleano} - Gera um nome randomico para o shapefile (TRUE) ou utiliza o nome do tema (FALSE)
1397 1397  
  1398 +$prj {string} - String que sera gravada no arquivo prj
  1399 +
1398 1400 Retorno:
1399 1401  
1400 1402 {string} - nome do arquivo criado ou false se ocorrer erro
1401 1403 */
1402   -function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE)
  1404 +function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE,$prj="")
1403 1405 {
1404 1406 $versao = versao();
1405 1407 $versao = $versao["principal"];
... ... @@ -1412,6 +1414,18 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE)
1412 1414 }
1413 1415 $map = @ms_newMapObj($map_file);
1414 1416 $layer = $map->getlayerbyname($tema);
  1417 + //e necessario abrir ou nao vai projetar
  1418 + $layer->open();
  1419 + $prjMapa = $map->getProjection();
  1420 + $prjTema = $layer->getProjection();
  1421 + if($prjTema != ""){
  1422 + $projInObj = new projectionObj($prjTema);
  1423 + $projOutObj = new projectionObj($prjMapa);
  1424 + }
  1425 + else{
  1426 + $projInObj = "";
  1427 + $projOutObj = "";
  1428 + }
1415 1429  
1416 1430 $layer->set("template","none.htm");
1417 1431 $diretorio = dirname($dir_tmp);
... ... @@ -1468,7 +1482,7 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE)
1468 1482 $resultadoFinal = true;
1469 1483 }
1470 1484 else{
1471   - $shapesSel = retornaShapesSelecionados($layer,$map_file,$map);
  1485 + $shapesSel = retornaShapesSelecionados($layer,$map_file,$map,false);
1472 1486 $items = pegaItens($layer);
1473 1487 // cria o dbf
1474 1488 $def = array();
... ... @@ -1482,10 +1496,12 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE)
1482 1496 $def[] = array($temp,"C","254");
1483 1497 $cni = $cni + 1;
1484 1498 }
1485   - if(!function_exists("dbase_create"))
1486   - {$db = xbase_create($nomeshp.".dbf", $def);}
1487   - else
1488   - {$db = dbase_create($nomeshp.".dbf", $def);}
  1499 + if(!function_exists("dbase_create")){
  1500 + $db = xbase_create($nomeshp.".dbf", $def);
  1501 + }
  1502 + else{
  1503 + $db = dbase_create($nomeshp.".dbf", $def);
  1504 + }
1489 1505 $dbname = $nomeshp.".dbf";
1490 1506 $reg = array();
1491 1507 $novoshpf = ms_newShapefileObj($nomeshp.".shp", -2);
... ... @@ -1494,8 +1510,8 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE)
1494 1510 if ($res_count > 0){
1495 1511 for ($i = 0; $i < $res_count; ++$i){
1496 1512 $shape = $shapesSel[$i];
1497   - foreach ($items as $ni)
1498   - {
  1513 + $shape->project($projInObj, $projOutObj);
  1514 + foreach ($items as $ni){
1499 1515 $vreg = $shape->values[$ni];
1500 1516 if(strlen($vreg) > 255){
1501 1517 $vreg = substr($vreg,0,255);
... ... @@ -1513,7 +1529,6 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE)
1513 1529 xbase_close($db);
1514 1530 else
1515 1531 dbase_close($db);
1516   - $layer->close();
1517 1532 //
1518 1533 //verifica a quantidade de registros no final
1519 1534 //
... ... @@ -1538,6 +1553,8 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE)
1538 1553 {unlink($nomeshp.".shp");}
1539 1554 if(file_exists($nomeshp.".shx"))
1540 1555 {unlink($nomeshp.".shx");}
  1556 + if(file_exists($nomeshp.".prj"))
  1557 + {unlink($nomeshp.".prj");}
1541 1558 $resultadoFinal = false;
1542 1559 }
1543 1560 }
... ... @@ -1550,20 +1567,9 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE)
1550 1567 }
1551 1568 else{
1552 1569 //gera o arquivo prj
1553   - /*
1554   - if(!file_exists($nomeshp.".prj")){
1555   - $projecao = $layer->getProjection();
1556   - if($projecao == ""){
1557   - $projecao = $map->getProjection();
1558   - }
1559   - include($locaplic."/pacotes/proj4php-proj4php5.2/src/proj4php/proj4php.php");
1560   -
1561   - $proj4 = new Proj4php();
1562   - $projWGS84 = new Proj4phpProj('EPSG:4326',$proj4);
1563   - echo $projWGS84->projection;exit;
1564   -
  1570 + if($prj != ""){
  1571 + gravaDados(array($prj),$nomeshp.".prj");
1565 1572 }
1566   - */
1567 1573 return $nomeshp;
1568 1574 }
1569 1575 }
... ... @@ -1618,7 +1624,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa)
1618 1624 //cria o arquivo mapfile, caso ele n&atilde;o exista, que servir&aacute; de base para obten&ccedil;&atilde;o dos dados
1619 1625 //
1620 1626 $nomeRand = true;
1621   - //echo $versao;exit;
  1627 + $projecao = pegaProjecaoDefault();
1622 1628 if (($map_file == "") || (!@ms_newMapObj($map_file))){ //a funcao foi chamada do aplicativo datadownload
1623 1629 if($base == "" or !isset($base)){
1624 1630 $base = "";
... ... @@ -1647,6 +1653,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa)
1647 1653 }
1648 1654 $map_tmp = ms_newMapObj($base);
1649 1655 $map_file = $dir_tmp."/".nomerandomico(20).".map";
  1656 + $map_tmp->setProjection($projecao["proj4"]);
1650 1657 $map_tmp->save($map_file);
1651 1658 $nomeRand = false;
1652 1659 }
... ... @@ -1830,12 +1837,19 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa)
1830 1837 }
1831 1838 //
1832 1839 //se nao existir selecao seleciona por box
  1840 + //o box vem do mapfile original
1833 1841 //
1834 1842 if(!file_exists($sel->qyfile) || $numSel < 1){
1835 1843 $box = $rectextent->minx." ".$rectextent->miny." ".$rectextent->maxx." ".$rectextent->maxy;
1836 1844 $sel->selecaoBOX("novo",$box);
  1845 + //reaproveita arquivo anterior
  1846 + $nomeRand = false;
  1847 + }
  1848 + $nomeshp = criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand,$projecao["prj"]);
  1849 + //remove o arquivo de selecao se ele foi criado apenas para pegar todos os elementos
  1850 + if($nomeRand == false){
  1851 + $sel->selecaoLimpa();
1837 1852 }
1838   - $nomeshp = criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand);
1839 1853 if($nomeshp == false){
1840 1854 return array("arquivos"=>"<span style=color:red >Ocorreu um erro, tente novamente","nreg"=>0);
1841 1855 }
... ... @@ -1847,6 +1861,9 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa)
1847 1861  
1848 1862 $resultado[] = str_replace($radtmp."/","",$nomeshp).".dbf";
1849 1863 $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".dbf"));
  1864 +
  1865 + $resultado[] = str_replace($radtmp."/","",$nomeshp).".prj";
  1866 + $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".prj"));
1850 1867 }
1851 1868 }
1852 1869 }
... ... @@ -2500,17 +2517,17 @@ function retornaShapesMapext($objLayer,$objMapa){
2500 2517 function retornaShapesSelecionados($objLayer,$map_file,$objMapa,$indexado=false){
2501 2518 $shapes = array();
2502 2519 $qyfile = dirname($map_file)."/".$objLayer->name.".php";
2503   -
2504   - if(!file_exists($qyfile))
2505   - {return $shapes;}
  2520 + if(!file_exists($qyfile)){
  2521 + return $shapes;
  2522 + }
2506 2523  
2507 2524 $handle = fopen ($qyfile, "r");
2508 2525 $conteudo = fread ($handle, filesize ($qyfile));
2509 2526 fclose ($handle);
2510 2527 $listaDeIndices = unserialize($conteudo);
2511   - //echo count($listaDeIndices);exit;
2512   - if(count($listaDeIndices) == 0)
2513   - {return $shapes;}
  2528 + if(count($listaDeIndices) == 0){
  2529 + return $shapes;
  2530 + }
2514 2531  
2515 2532 $versao = versao();
2516 2533 $versao = $versao["principal"];
... ... @@ -2521,14 +2538,11 @@ function retornaShapesSelecionados($objLayer,$map_file,$objMapa,$indexado=false)
2521 2538  
2522 2539 $sopen = $objLayer->open();
2523 2540 if($sopen == MS_FAILURE){return "erro";}
2524   - $objLayer->open();
2525 2541 $res_count = $objLayer->getNumresults();
2526 2542 $centroides = array();
2527 2543 $shapes = array();
2528 2544 //pega um shape especifico
2529   -
2530   - for ($i = 0; $i < $res_count; ++$i)
2531   - {
  2545 + for ($i = 0; $i < $res_count; ++$i){
2532 2546 if($versao >= 6){
2533 2547 $shape = $objLayer->getShape($objLayer->getResult($i));
2534 2548 $shp_index = $shape->index;
... ...