Commit 5e8b35bd9e0c0a1da9c7759dbcd962329e362dcf
1 parent
6bebae49
Exists in
master
and in
7 other branches
Exportação de shapefile zipado em datadownload. Exportação de shapefile em OGC mesmo sem uso de OGR
Showing
2 changed files
with
34 additions
and
5 deletions
Show diff stats
classesphp/funcoes_gerais.php
... | ... | @@ -1632,6 +1632,8 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) |
1632 | 1632 | else{ |
1633 | 1633 | include(dirname(__FILE__)."/../ms_configura.php"); |
1634 | 1634 | } |
1635 | + //para zipar o shapefile | |
1636 | + include(dirname(__FILE__)."/../pacotes/kmlmapserver/classes/zip.class.php"); | |
1635 | 1637 | $versao = versao(); |
1636 | 1638 | $versao = $versao["principal"]; |
1637 | 1639 | $dataArquivos = array(); |
... | ... | @@ -1781,6 +1783,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) |
1781 | 1783 | } |
1782 | 1784 | //$temas agora é um array com os NAMEs dos LAYERS que serão baixados |
1783 | 1785 | $radtmp = dirname($dir_tmp); |
1786 | + $ziper = new zipfile(); | |
1784 | 1787 | foreach ($temas as $tema){ |
1785 | 1788 | $l = $map->getlayerbyname($tema); |
1786 | 1789 | $novonomelayer = $tema; |
... | ... | @@ -1796,6 +1799,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) |
1796 | 1799 | unlink($nomeshp.".shp"); |
1797 | 1800 | unlink($nomeshp.".shx"); |
1798 | 1801 | unlink($nomeshp.".prj"); |
1802 | + unlink($nomeshp.".zip"); | |
1799 | 1803 | } |
1800 | 1804 | } |
1801 | 1805 | // |
... | ... | @@ -1868,17 +1872,31 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) |
1868 | 1872 | if($nomeshp == false){ |
1869 | 1873 | return array("arquivos"=>"<span style=color:red >Ocorreu um erro, tente novamente","nreg"=>0); |
1870 | 1874 | } |
1871 | - $resultado[] = str_replace($radtmp."/","",$nomeshp).".shp"; | |
1875 | + $pre = str_replace($radtmp."/","",$nomeshp); | |
1876 | + $resultado[] = $pre.".shp"; | |
1872 | 1877 | $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".shp")); |
1873 | 1878 | |
1874 | - $resultado[] = str_replace($radtmp."/","",$nomeshp).".shx"; | |
1879 | + $resultado[] = $pre.".shx"; | |
1875 | 1880 | $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".shx")); |
1876 | 1881 | |
1877 | - $resultado[] = str_replace($radtmp."/","",$nomeshp).".dbf"; | |
1882 | + $resultado[] = $pre.".dbf"; | |
1878 | 1883 | $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".dbf")); |
1879 | 1884 | |
1880 | - $resultado[] = str_replace($radtmp."/","",$nomeshp).".prj"; | |
1885 | + $resultado[] = $pre.".prj"; | |
1881 | 1886 | $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".prj")); |
1887 | + //zipa o arquivo | |
1888 | + $zip = basename($pre); | |
1889 | + if(!file_exists($pre.".zip")){ | |
1890 | + $ziper->addFile(file_get_contents($nomeshp.".shp"), $zip.".shp"); | |
1891 | + $ziper->addFile(file_get_contents($nomeshp.".shx"), $zip.".shx"); | |
1892 | + $ziper->addFile(file_get_contents($nomeshp.".dbf"), $zip.".dbf"); | |
1893 | + $ziper->addFile(file_get_contents($nomeshp.".prj"), $zip.".prj"); | |
1894 | + $fp = fopen($nomeshp.".zip","wb"); | |
1895 | + fwrite($fp, $ziper->file()); | |
1896 | + fclose($fp); | |
1897 | + } | |
1898 | + $resultado[] = $pre.".zip"; | |
1899 | + $dataArquivos[] = date ("F d Y H:i:s.",filemtime($nomeshp.".zip")); | |
1882 | 1900 | } |
1883 | 1901 | } |
1884 | 1902 | } |
... | ... | @@ -1914,7 +1932,7 @@ function downloadTema2($map_file,$tema,$locaplic,$dir_tmp,$postgis_mapa) |
1914 | 1932 | $maptemp->save($nomemapfile); |
1915 | 1933 | $nomemapfileurl = str_replace($radtmp."/","",$nomemapfile); |
1916 | 1934 | } |
1917 | - return array("tema"=>$tema,"mapfile"=>$nomemapfile,"mapfileurl"=>$nomemapfileurl,"arquivos"=>implode(",",$resultado),"nreg"=>$nreg,"datas"=>$dataArquivos); | |
1935 | + return array("tema"=>$tema,"mapfile"=>$nomemapfile,"mapfileurl"=>$nomemapfileurl,"arquivos"=>implode(",",$resultado),"nreg"=>$nreg,"datas"=>$dataArquivos, "shape-zip"=>$nomeshp.".zip"); | |
1918 | 1936 | } |
1919 | 1937 | |
1920 | 1938 | /* | ... | ... |
ogc.php
... | ... | @@ -201,6 +201,17 @@ if(strtolower($OUTPUTFORMAT) == "kml" && $ogrOutput == false){ |
201 | 201 | header("Location:".$urln); |
202 | 202 | exit; |
203 | 203 | } |
204 | +if(strtolower($OUTPUTFORMAT) == "shape-zip" && $ogrOutput == false){ | |
205 | + $retorno = downloadTema2("",$tema,$locaplic,$dir_tmp,$postgis_mapa); | |
206 | + $zip = $retorno["shape-zip"]; | |
207 | + if(file_exists($zip)){ | |
208 | + ob_end_clean(); | |
209 | + header('Content-type: application/zip'); | |
210 | + header('Content-Disposition: attachment; filename='.basename($zip)); | |
211 | + echo file_get_contents($zip); | |
212 | + } | |
213 | + exit; | |
214 | +} | |
204 | 215 | // |
205 | 216 | //caso seja uma requisição WMS com format |
206 | 217 | // | ... | ... |