Commit 965f17fc989413f6e68f0d463257b6196747299b
1 parent
50159d0b
Exists in
master
and in
7 other branches
Correção na projecao de dados em projecao AUTO e download
Showing
3 changed files
with
60 additions
and
51 deletions
Show diff stats
admin/admin.db
No preview for this file type
classesphp/classe_analise.php
@@ -1274,8 +1274,7 @@ class Analise | @@ -1274,8 +1274,7 @@ class Analise | ||
1274 | $layerdestino->close(); | 1274 | $layerdestino->close(); |
1275 | $rect = $this->mapa->extent; | 1275 | $rect = $this->mapa->extent; |
1276 | $projInObj = $layerorigem->getProjection(); | 1276 | $projInObj = $layerorigem->getProjection(); |
1277 | - if ($projInObj == "") | ||
1278 | - { | 1277 | + if ($projInObj == ""){ |
1279 | $projInObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs"); | 1278 | $projInObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs"); |
1280 | } | 1279 | } |
1281 | $projOutObj = ms_newprojectionobj("proj=poly,ellps=GRS67,lat_0=".$rect->miny.",lon_0=".$rect->minx.",x_0=5000000,y_0=10000000"); | 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,12 +1290,11 @@ class Analise | ||
1291 | $def[] = array("dist_m","N","10","2"); | 1290 | $def[] = array("dist_m","N","10","2"); |
1292 | $def[] = array("origem","C","255"); | 1291 | $def[] = array("origem","C","255"); |
1293 | $def[] = array("destino","C","255"); | 1292 | $def[] = array("destino","C","255"); |
1294 | - if($this->dbaseExiste == false) | ||
1295 | - { | 1293 | + if($this->dbaseExiste == false){ |
1296 | $db = xbase_create($nomeshp.".dbf", $def);xbase_close($db); | 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 | //acrescenta os pontos no novo shapefile | 1299 | //acrescenta os pontos no novo shapefile |
1302 | $dbname = $nomeshp.".dbf"; | 1300 | $dbname = $nomeshp.".dbf"; |
@@ -1304,26 +1302,23 @@ class Analise | @@ -1304,26 +1302,23 @@ class Analise | ||
1304 | $db=xbase_open($dbname,2); | 1302 | $db=xbase_open($dbname,2); |
1305 | else | 1303 | else |
1306 | $db=dbase_open($dbname,2); | 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 | $valororigem = $sorigem->values[$itemorigem]; | 1307 | $valororigem = $sorigem->values[$itemorigem]; |
1312 | } | 1308 | } |
1313 | - else | ||
1314 | - {$valororigem = ""; | 1309 | + else{ |
1310 | + $valororigem = ""; | ||
1315 | } | 1311 | } |
1316 | foreach ($shapesdestino as $sdestino) | 1312 | foreach ($shapesdestino as $sdestino) |
1317 | { | 1313 | { |
1318 | $linha = ms_newLineObj(); | 1314 | $linha = ms_newLineObj(); |
1319 | $linha->add($sorigem->getCentroid()); | 1315 | $linha->add($sorigem->getCentroid()); |
1320 | $linha->add($sdestino->getCentroid()); | 1316 | $linha->add($sdestino->getCentroid()); |
1321 | - if($itemdestino != "") | ||
1322 | - { | 1317 | + if($itemdestino != ""){ |
1323 | $valordestino = $sdestino->values[$itemdestino]; | 1318 | $valordestino = $sdestino->values[$itemdestino]; |
1324 | } | 1319 | } |
1325 | - else | ||
1326 | - {$valordestino = ""; | 1320 | + else{ |
1321 | + $valordestino = ""; | ||
1327 | } | 1322 | } |
1328 | $ShapeObj = ms_newShapeObj(MS_SHAPE_LINE); | 1323 | $ShapeObj = ms_newShapeObj(MS_SHAPE_LINE); |
1329 | $ShapeObj->add($linha); | 1324 | $ShapeObj->add($linha); |
@@ -1619,7 +1614,7 @@ class Analise | @@ -1619,7 +1614,7 @@ class Analise | ||
1619 | $nomeCentroides = nomeRandomico(); | 1614 | $nomeCentroides = nomeRandomico(); |
1620 | $nomeshp = $this->diretorio."/".$nomeCentroides; | 1615 | $nomeshp = $this->diretorio."/".$nomeCentroides; |
1621 | $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa); | 1616 | $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa); |
1622 | - | 1617 | + |
1623 | //$shapes = $shape[0]; | 1618 | //$shapes = $shape[0]; |
1624 | foreach($shapes as $shape){ | 1619 | foreach($shapes as $shape){ |
1625 | $LineObj = ms_newLineObj(); | 1620 | $LineObj = ms_newLineObj(); |
classesphp/funcoes_gerais.php
@@ -1395,11 +1395,13 @@ $dir_tmp {string} - Diretório temporário | @@ -1395,11 +1395,13 @@ $dir_tmp {string} - Diretório temporário | ||
1395 | 1395 | ||
1396 | $nomeRand {boleano} - Gera um nome randomico para o shapefile (TRUE) ou utiliza o nome do tema (FALSE) | 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 | Retorno: | 1400 | Retorno: |
1399 | 1401 | ||
1400 | {string} - nome do arquivo criado ou false se ocorrer erro | 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 | $versao = versao(); | 1406 | $versao = versao(); |
1405 | $versao = $versao["principal"]; | 1407 | $versao = $versao["principal"]; |
@@ -1412,6 +1414,18 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | @@ -1412,6 +1414,18 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | ||
1412 | } | 1414 | } |
1413 | $map = @ms_newMapObj($map_file); | 1415 | $map = @ms_newMapObj($map_file); |
1414 | $layer = $map->getlayerbyname($tema); | 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 | $layer->set("template","none.htm"); | 1430 | $layer->set("template","none.htm"); |
1417 | $diretorio = dirname($dir_tmp); | 1431 | $diretorio = dirname($dir_tmp); |
@@ -1468,7 +1482,7 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | @@ -1468,7 +1482,7 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | ||
1468 | $resultadoFinal = true; | 1482 | $resultadoFinal = true; |
1469 | } | 1483 | } |
1470 | else{ | 1484 | else{ |
1471 | - $shapesSel = retornaShapesSelecionados($layer,$map_file,$map); | 1485 | + $shapesSel = retornaShapesSelecionados($layer,$map_file,$map,false); |
1472 | $items = pegaItens($layer); | 1486 | $items = pegaItens($layer); |
1473 | // cria o dbf | 1487 | // cria o dbf |
1474 | $def = array(); | 1488 | $def = array(); |
@@ -1482,10 +1496,12 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | @@ -1482,10 +1496,12 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | ||
1482 | $def[] = array($temp,"C","254"); | 1496 | $def[] = array($temp,"C","254"); |
1483 | $cni = $cni + 1; | 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 | $dbname = $nomeshp.".dbf"; | 1505 | $dbname = $nomeshp.".dbf"; |
1490 | $reg = array(); | 1506 | $reg = array(); |
1491 | $novoshpf = ms_newShapefileObj($nomeshp.".shp", -2); | 1507 | $novoshpf = ms_newShapefileObj($nomeshp.".shp", -2); |
@@ -1494,8 +1510,8 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | @@ -1494,8 +1510,8 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | ||
1494 | if ($res_count > 0){ | 1510 | if ($res_count > 0){ |
1495 | for ($i = 0; $i < $res_count; ++$i){ | 1511 | for ($i = 0; $i < $res_count; ++$i){ |
1496 | $shape = $shapesSel[$i]; | 1512 | $shape = $shapesSel[$i]; |
1497 | - foreach ($items as $ni) | ||
1498 | - { | 1513 | + $shape->project($projInObj, $projOutObj); |
1514 | + foreach ($items as $ni){ | ||
1499 | $vreg = $shape->values[$ni]; | 1515 | $vreg = $shape->values[$ni]; |
1500 | if(strlen($vreg) > 255){ | 1516 | if(strlen($vreg) > 255){ |
1501 | $vreg = substr($vreg,0,255); | 1517 | $vreg = substr($vreg,0,255); |
@@ -1513,7 +1529,6 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | @@ -1513,7 +1529,6 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | ||
1513 | xbase_close($db); | 1529 | xbase_close($db); |
1514 | else | 1530 | else |
1515 | dbase_close($db); | 1531 | dbase_close($db); |
1516 | - $layer->close(); | ||
1517 | // | 1532 | // |
1518 | //verifica a quantidade de registros no final | 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,6 +1553,8 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | ||
1538 | {unlink($nomeshp.".shp");} | 1553 | {unlink($nomeshp.".shp");} |
1539 | if(file_exists($nomeshp.".shx")) | 1554 | if(file_exists($nomeshp.".shx")) |
1540 | {unlink($nomeshp.".shx");} | 1555 | {unlink($nomeshp.".shx");} |
1556 | + if(file_exists($nomeshp.".prj")) | ||
1557 | + {unlink($nomeshp.".prj");} | ||
1541 | $resultadoFinal = false; | 1558 | $resultadoFinal = false; |
1542 | } | 1559 | } |
1543 | } | 1560 | } |
@@ -1550,20 +1567,9 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | @@ -1550,20 +1567,9 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) | ||
1550 | } | 1567 | } |
1551 | else{ | 1568 | else{ |
1552 | //gera o arquivo prj | 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 | return $nomeshp; | 1573 | return $nomeshp; |
1568 | } | 1574 | } |
1569 | } | 1575 | } |
@@ -1618,7 +1624,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) | @@ -1618,7 +1624,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) | ||
1618 | //cria o arquivo mapfile, caso ele não exista, que servirá de base para obtenção dos dados | 1624 | //cria o arquivo mapfile, caso ele não exista, que servirá de base para obtenção dos dados |
1619 | // | 1625 | // |
1620 | $nomeRand = true; | 1626 | $nomeRand = true; |
1621 | - //echo $versao;exit; | 1627 | + $projecao = pegaProjecaoDefault(); |
1622 | if (($map_file == "") || (!@ms_newMapObj($map_file))){ //a funcao foi chamada do aplicativo datadownload | 1628 | if (($map_file == "") || (!@ms_newMapObj($map_file))){ //a funcao foi chamada do aplicativo datadownload |
1623 | if($base == "" or !isset($base)){ | 1629 | if($base == "" or !isset($base)){ |
1624 | $base = ""; | 1630 | $base = ""; |
@@ -1647,6 +1653,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) | @@ -1647,6 +1653,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) | ||
1647 | } | 1653 | } |
1648 | $map_tmp = ms_newMapObj($base); | 1654 | $map_tmp = ms_newMapObj($base); |
1649 | $map_file = $dir_tmp."/".nomerandomico(20).".map"; | 1655 | $map_file = $dir_tmp."/".nomerandomico(20).".map"; |
1656 | + $map_tmp->setProjection($projecao["proj4"]); | ||
1650 | $map_tmp->save($map_file); | 1657 | $map_tmp->save($map_file); |
1651 | $nomeRand = false; | 1658 | $nomeRand = false; |
1652 | } | 1659 | } |
@@ -1830,12 +1837,19 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) | @@ -1830,12 +1837,19 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) | ||
1830 | } | 1837 | } |
1831 | // | 1838 | // |
1832 | //se nao existir selecao seleciona por box | 1839 | //se nao existir selecao seleciona por box |
1840 | + //o box vem do mapfile original | ||
1833 | // | 1841 | // |
1834 | if(!file_exists($sel->qyfile) || $numSel < 1){ | 1842 | if(!file_exists($sel->qyfile) || $numSel < 1){ |
1835 | $box = $rectextent->minx." ".$rectextent->miny." ".$rectextent->maxx." ".$rectextent->maxy; | 1843 | $box = $rectextent->minx." ".$rectextent->miny." ".$rectextent->maxx." ".$rectextent->maxy; |
1836 | $sel->selecaoBOX("novo",$box); | 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 | if($nomeshp == false){ | 1853 | if($nomeshp == false){ |
1840 | return array("arquivos"=>"<span style=color:red >Ocorreu um erro, tente novamente","nreg"=>0); | 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,6 +1861,9 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) | ||
1847 | 1861 | ||
1848 | $resultado[] = str_replace($radtmp."/","",$nomeshp).".dbf"; | 1862 | $resultado[] = str_replace($radtmp."/","",$nomeshp).".dbf"; |
1849 | $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".dbf")); | 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,17 +2517,17 @@ function retornaShapesMapext($objLayer,$objMapa){ | ||
2500 | function retornaShapesSelecionados($objLayer,$map_file,$objMapa,$indexado=false){ | 2517 | function retornaShapesSelecionados($objLayer,$map_file,$objMapa,$indexado=false){ |
2501 | $shapes = array(); | 2518 | $shapes = array(); |
2502 | $qyfile = dirname($map_file)."/".$objLayer->name.".php"; | 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 | $handle = fopen ($qyfile, "r"); | 2524 | $handle = fopen ($qyfile, "r"); |
2508 | $conteudo = fread ($handle, filesize ($qyfile)); | 2525 | $conteudo = fread ($handle, filesize ($qyfile)); |
2509 | fclose ($handle); | 2526 | fclose ($handle); |
2510 | $listaDeIndices = unserialize($conteudo); | 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 | $versao = versao(); | 2532 | $versao = versao(); |
2516 | $versao = $versao["principal"]; | 2533 | $versao = $versao["principal"]; |
@@ -2521,14 +2538,11 @@ function retornaShapesSelecionados($objLayer,$map_file,$objMapa,$indexado=false) | @@ -2521,14 +2538,11 @@ function retornaShapesSelecionados($objLayer,$map_file,$objMapa,$indexado=false) | ||
2521 | 2538 | ||
2522 | $sopen = $objLayer->open(); | 2539 | $sopen = $objLayer->open(); |
2523 | if($sopen == MS_FAILURE){return "erro";} | 2540 | if($sopen == MS_FAILURE){return "erro";} |
2524 | - $objLayer->open(); | ||
2525 | $res_count = $objLayer->getNumresults(); | 2541 | $res_count = $objLayer->getNumresults(); |
2526 | $centroides = array(); | 2542 | $centroides = array(); |
2527 | $shapes = array(); | 2543 | $shapes = array(); |
2528 | //pega um shape especifico | 2544 | //pega um shape especifico |
2529 | - | ||
2530 | - for ($i = 0; $i < $res_count; ++$i) | ||
2531 | - { | 2545 | + for ($i = 0; $i < $res_count; ++$i){ |
2532 | if($versao >= 6){ | 2546 | if($versao >= 6){ |
2533 | $shape = $objLayer->getShape($objLayer->getResult($i)); | 2547 | $shape = $objLayer->getShape($objLayer->getResult($i)); |
2534 | $shp_index = $shape->index; | 2548 | $shp_index = $shape->index; |