Commit d3035b9bd5418c030b69ae766ce57be498848186
1 parent
ffa25349
Exists in
master
Otimização da geração de arquivos shapefile para download
Showing
2 changed files
with
30 additions
and
10 deletions
Show diff stats
classesphp/classe_selecao.php
... | ... | @@ -870,8 +870,10 @@ parameters: |
870 | 870 | $tipo - Tipo de operação adiciona|retira|inverte|limpa|novo |
871 | 871 | |
872 | 872 | $ext - coordenadas separadas por espaços no estilo xmin ymin xmax ymax |
873 | + | |
874 | +$retornaShapes - retorna os shapes selecionados. Nesse caso, nao e gerado o arquivo em disco contendo a selecao | |
873 | 875 | */ |
874 | - function selecaoBOX($tipo,$ext) { | |
876 | + function selecaoBOX($tipo,$ext,$retornaShapes=false) { | |
875 | 877 | if ($tipo == "novo"){ |
876 | 878 | $this->selecaoLimpa(); |
877 | 879 | $tipo = "adiciona"; |
... | ... | @@ -906,12 +908,28 @@ $ext - coordenadas separadas por espaços no estilo xmin ymin xmax ymax |
906 | 908 | $ident = $this->layer->queryByRect($rect); |
907 | 909 | if ($ident != 1){ |
908 | 910 | $res_count = $this->layer->getNumresults(); |
911 | + //echo $res_count;exit;325449 | |
909 | 912 | $shpi = array(); |
910 | 913 | for ($i = 0; $i < $res_count; ++$i) { |
911 | 914 | $result = $this->layer->getResult($i); |
912 | - $shpi[] = $result->shapeindex; | |
915 | + if($result != MS_FALSE){ | |
916 | + if($retornaShapes == false){ | |
917 | + $shpi[] = $result->shapeindex; | |
918 | + } | |
919 | + else { | |
920 | + if($this->v >= 6){ | |
921 | + $shpi[] = $this->layer->getshape($result); | |
922 | + } | |
923 | + else{ | |
924 | + $shpi[] = $this->layer->getfeature($result->shapeindex,-1); | |
925 | + } | |
926 | + } | |
927 | + } | |
913 | 928 | } |
914 | 929 | } |
930 | + if($retornaShapes == true){ | |
931 | + return $shpi; | |
932 | + } | |
915 | 933 | if ($tipo == "adiciona"){ |
916 | 934 | return($this->selecaoAdiciona($shpi,$shp_atual)); |
917 | 935 | } | ... | ... |
classesphp/funcoes_gerais.php
... | ... | @@ -1455,12 +1455,13 @@ $prj {string} - String que sera gravada no arquivo prj |
1455 | 1455 | |
1456 | 1456 | $projetaToMap {boolean} - Projeta os shapes para a projecao do mapa |
1457 | 1457 | |
1458 | +$shapesSel - (opcional) array com os shapes | |
1459 | + | |
1458 | 1460 | Retorno: |
1459 | 1461 | |
1460 | 1462 | {string} - nome do arquivo criado ou false se ocorrer erro |
1461 | 1463 | */ |
1462 | -function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE,$prj="",$projetaToMap=true) | |
1463 | -{ | |
1464 | +function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE,$prj="",$projetaToMap=true,$shapesSel=false){ | |
1464 | 1465 | include(dirname(__FILE__)."/../ms_configura.php"); |
1465 | 1466 | $versao = versao(); |
1466 | 1467 | $versao = $versao["principal"]; |
... | ... | @@ -1490,7 +1491,6 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE,$prj="",$proj |
1490 | 1491 | $projOutObj = ""; |
1491 | 1492 | $projetaToMap = false; |
1492 | 1493 | } |
1493 | - | |
1494 | 1494 | $layer->set("template","none.htm"); |
1495 | 1495 | $diretorio = dirname($dir_tmp); |
1496 | 1496 | $tipol = MS_SHP_POINT; |
... | ... | @@ -1543,10 +1543,11 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE,$prj="",$proj |
1543 | 1543 | $novoshpf = ms_newShapefileObj($nomeshp.".shp", -2); |
1544 | 1544 | $novoshpf->addShape($shape); |
1545 | 1545 | $resultadoFinal = true; |
1546 | - | |
1547 | 1546 | } |
1548 | 1547 | else{ |
1549 | - $shapesSel = retornaShapesSelecionados($layer,$map_file,$map,false); | |
1548 | + if($shapesSel == false){ | |
1549 | + $shapesSel = retornaShapesSelecionados($layer,$map_file,$map,false); | |
1550 | + } | |
1550 | 1551 | $items = pegaItens($layer); |
1551 | 1552 | // cria o dbf |
1552 | 1553 | $def = array(); |
... | ... | @@ -1685,6 +1686,7 @@ Include: |
1685 | 1686 | function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) |
1686 | 1687 | { |
1687 | 1688 | ini_set("max_execution_time","1800"); |
1689 | + ini_set('memory_limit', '5000M'); | |
1688 | 1690 | $temas = array(); |
1689 | 1691 | if(file_exists($locaplic."/ms_configura.php")){ |
1690 | 1692 | include($locaplic."/ms_configura.php"); |
... | ... | @@ -1927,6 +1929,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) |
1927 | 1929 | if(file_exists($sel->qyfile)){ |
1928 | 1930 | $map->loadquery($sel->qyfile); |
1929 | 1931 | $numSel = $l->getNumresults(); |
1932 | + $nomeshp = criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand,$projecao["prj"]); | |
1930 | 1933 | } |
1931 | 1934 | // |
1932 | 1935 | //se nao existir selecao seleciona por box |
... | ... | @@ -1934,12 +1937,11 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) |
1934 | 1937 | // |
1935 | 1938 | if(!file_exists($sel->qyfile)){ |
1936 | 1939 | $box = $rectextent->minx." ".$rectextent->miny." ".$rectextent->maxx." ".$rectextent->maxy; |
1937 | - $sel->selecaoBOX("novo",$box); | |
1940 | + $shapesSel = $sel->selecaoBOX("novo",$box, true); | |
1938 | 1941 | //reaproveita arquivo anterior |
1939 | 1942 | $nomeRand = false; |
1943 | + $nomeshp = criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand,$projecao["prj"],true,$shapesSel); | |
1940 | 1944 | } |
1941 | - | |
1942 | - $nomeshp = criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand,$projecao["prj"]); | |
1943 | 1945 | //remove o arquivo de selecao se ele foi criado apenas para pegar todos os elementos |
1944 | 1946 | if($nomeRand == false){ |
1945 | 1947 | $sel->selecaoLimpa(); | ... | ... |