Commit 418b50503c952e1e02ffd0840f025d1afc367df0

Authored by Edmar Moretti
1 parent cdf1f287

v6 - inclusão de opção para gerar um arquivo de configuração mapfile automaticam…

…ente quando um shapefile é enviado para o banco de dados postgis
admin/admin.db
No preview for this file type
admin/js/estat_editor.js
... ... @@ -521,6 +521,7 @@ i3GEOadmin.editor = {
521 521 );
522 522 i3GEO.util.comboEpsg("comboInSrid","selInSrid","i3GEOadmin.editor.uploadshp.mudaComboInSrid",4326);
523 523 i3GEO.util.comboEpsg("comboOutSrid","selOutSrid","i3GEOadmin.editor.uploadshp.mudaComboOutSrid",4326);
  524 + window.location.hash="i3GEOuploadshp";
524 525 },
525 526 mudaComboInSrid: function(obj){
526 527 $i("insrid").value = obj.value;
... ... @@ -529,14 +530,16 @@ i3GEOadmin.editor = {
529 530 $i("outsrid").value = obj.value;
530 531 },
531 532 formulario: function(){
532   - var ins = '<fieldset class=subbloco >' +
  533 + var ins = '' +
533 534 '<form id=i3GEOuploadf target="i3GEOuploadiframe" action="../php/metaestat_uploadshp_submit.php" method="post" ENCTYPE="multipart/form-data">' +
  535 + '<fieldset class=subbloco >' +
534 536 '<p class="paragrafo" >shp: <br><input type="file" size=22 name="i3GEOuploadshp" style="top:0px;left:0px;cursor:pointer;"></p>' +
535 537 '<p class="paragrafo" >shx: <br><input type="file" size=22 name="i3GEOuploadshx" style="top:0px;left:0px;cursor:pointer;"></p>' +
536 538 '<p class="paragrafo" >dbf: <br><input type="file" size=22 name="i3GEOuploaddbf" style="top:0px;left:0px;cursor:pointer;"></p>' +
537 539 '</fieldset>' +
538 540 '<fieldset class=subbloco >' +
539   - '<p class="paragrafo" >Nome da tabela (n&atilde;o utilize caracteres incompat&iacute;veis com o banco de dados, como -, acentos ou espa&ccedil;os em branco):<br><input class=digitar type="text" size=20 id="tabelaDestino" name="tabelaDestino" style="top:0px;left:0px;cursor:pointer;"> ' +
  541 + '<p class="paragrafo" >Nome da tabela (n&atilde;o utilize caracteres incompat&iacute;veis com o banco de dados, como -, acentos ou espa&ccedil;os em branco):<br>' +
  542 + '<input class=digitar type="text" size=20 id="tabelaDestino" name="tabelaDestino" style="top:0px;left:0px;cursor:pointer;"> ' +
540 543 'Ou escolha da lista: ' +
541 544 '<select onchange="javascript:$i(\'tabelaDestino\').value = this.value;">' +
542 545 i3GEOadmin.editor.tabela.optionsTabela +
... ... @@ -558,17 +561,18 @@ i3GEOadmin.editor = {
558 561 '<p><div id=selOutSrid ></div><input class=digitar type="text" value="" size=20 id="outsrid" name="outsrid" style="top:0px;left:0px;cursor:pointer;"></p>' +
559 562 '</fieldset>' +
560 563 '<fieldset class=subbloco >' +
  564 + '<p class="paragrafo" ><input type=checkbox name=i3GEOuploadCriaMapfile id=i3GEOuploadCriaMapfile style="cursor:pointer;position:relative;top:2px;" />&nbsp;Marque para criar o arquivo de configura&ccedil;&atilde;o (mapfile) e visualizar os dados no mapa interativo (voc&ecirc; poder&aacute; editar esse arquivo posteriormente no editor de mapfiles)' +
561 565 '<p class="paragrafo" ><input type="checkbox" id="incluiserialshp" name="incluiserialshp" style="cursor:pointer;position:relative;top:2px;">&nbsp;Inclui uma coluna gid do tipo serial e chave prim&aacute;ria com c&oacute;digo &uacute;nico</p>' +
562 566 '<p class="paragrafo" ><input id=i3GEOuploadsubmit type="button" value="Enviar" size=12 />' +
563 567 '<input type="hidden" name="MAX_FILE_SIZE" value="1000000">' +
564 568 '<input type="hidden" id="i3GEOuploadcodigoconexao" name="i3GEOuploadcodigoconexao" value="">' +
565 569 '<input type="hidden" id="i3GEOuploadesquema" name="i3GEOuploadesquema" value="">' +
566   - '</form>' +
567 570 "<p class='paragrafo' style=color:red >N&atilde;o utilize '_' no nome do arquivo. Apenas letras e n&uacute;meros s&atilde;o aceitos!!!</p>" +
568 571 '<iframe name=i3GEOuploadiframe style="text-align:left;border:1px solid gray;" width="98%" height="400px"></iframe>' +
569 572 '<p class="paragrafo" >Ap&oacute;s terminar o processo, atualize essa p&aacute;gina para que a nova tabela criada apare&ccedil;a nas listas de sele&ccedil;&atilde;o.</p>' +
570 573 '<p class="paragrafo" >Utilize o <a href="./estat_tipo_regiao.html" >cadastro de regi&otilde;es</a> para registrar a tabela criada como uma nova unidade geogr&aacute;fica que poder&aacute; ser escolhida no processo de cria&ccedil;&atilde;o de vari&aacute;veis.</p>' +
571   - '</fieldset>';
  574 + '</fieldset>' +
  575 + '</form>';
572 576 return ins;
573 577 },
574 578 submit: function(){
... ...
admin/php/conexao.php
... ... @@ -33,7 +33,7 @@ Este programa &amp;eacute; distribu&amp;iacute;do na expectativa de que seja &amp;uacute;til
33 33 por&eacute;m, SEM NENHUMA GARANTIA; nem mesmo a garantia impl&iacute;cita
34 34 de COMERCIABILIDADE OU ADEQUA&Ccedil;&Atilde;O A UMA FINALIDADE ESPEC&Iacute;FICA.
35 35 Consulte a Licen&ccedil;a P&uacute;blica Geral do GNU para mais detalhes.
36   -Voc&ecirc; deve ter recebido uma cópia da Licen&ccedil;a P&uacute;blica Geral do
  36 +Voc&ecirc; deve ter recebido uma c�pia da Licen&ccedil;a P&uacute;blica Geral do
37 37 GNU junto com este programa; se n&atilde;o, escreva para a
38 38 Free Software Foundation, Inc., no endere&ccedil;o
39 39 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
... ...
admin/php/editormapfile.php
... ... @@ -231,7 +231,7 @@ switch (strtoupper($funcao))
231 231 /*
232 232 Valor: LIMPARCACHEMAPFILE
233 233  
234   - Apaga o diretrio contendo o cache de um tema (mapfile)
  234 + Apaga o diretorio contendo o cache de um tema (mapfile)
235 235  
236 236 Parametros:
237 237  
... ... @@ -268,7 +268,7 @@ switch (strtoupper($funcao))
268 268  
269 269 Exclui um mapfile.
270 270  
271   - S� &eacute; poss&iacute;vel excluir se o mapfile n&atilde;o estiver vinculado a nenhum tema ou n� da &aacute;rvore de temas
  271 + So &eacute; poss&iacute;vel excluir se o mapfile n&atilde;o estiver vinculado a nenhum tema ou no da &aacute;rvore de temas
272 272  
273 273 Parametros:
274 274  
... ... @@ -1183,9 +1183,8 @@ function sobeDesce()
1183 1183 return "ok";
1184 1184 }
1185 1185 //essa funcao e usada tambem por i3geo/ferramentas/upload/upload.php
1186   -function criarNovoMap()
1187   -{
1188   - global $nome,$codigo,$locaplic,$it,$en,$es,$esquemaadmin,$metaestat,$tipoLayer,$data;
  1186 +function criarNovoMap(){
  1187 + global $nome,$codigo,$locaplic,$it,$en,$es,$esquemaadmin,$metaestat,$tipoLayer,$data,$conexao;
1189 1188 $arq = $locaplic."/temas/".$codigo.".map";
1190 1189 if(!file_exists($arq)){
1191 1190 if(empty($tipoLayer)){
... ... @@ -1201,6 +1200,10 @@ function criarNovoMap()
1201 1200 $dados[] = ' CONNECTIONTYPE POSTGIS';
1202 1201 $tipoLayer = "polygon";
1203 1202 }
  1203 + elseif(!empty($conexao)){
  1204 + $dados[] = ' CONNECTIONTYPE POSTGIS';
  1205 + $dados[] = ' CONNECTION "'.$conexao.'"';
  1206 + }
1204 1207 $dados[] = " TYPE ".$tipoLayer;
1205 1208 if(empty($data)){
1206 1209 $dados[] = ' DATA ""';
... ... @@ -1237,7 +1240,8 @@ function criarNovoMap()
1237 1240 {
1238 1241 fwrite($fp,$dado."\n");
1239 1242 }
1240   - require_once("conexao.php");
  1243 +
  1244 + include("conexao.php");
1241 1245 if($convUTF){
1242 1246 $nome = utf8_encode($nome);
1243 1247 $desc = utf8_encode($desc);
... ...
admin/php/metaestat_uploadshp_submit.php
... ... @@ -76,7 +76,7 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
76 76 $colunasTemp = $layer->getItems();
77 77 $colunas = array();
78 78 foreach($colunasTemp as $c){
79   - //abaixo gid e forçado a entrar
  79 + //abaixo gid e forcado a entrar
80 80 if(!is_numeric($c) && strtolower($c) != "gid"){
81 81 $colunas[] = $c;
82 82 }
... ... @@ -182,6 +182,7 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
182 182 ob_flush();
183 183 flush();
184 184 sleep(1);
  185 + $srid = 4326;
185 186 for ($i=0; $i<$numshapes;$i++){
186 187 $s = $layer->getShape(new resultObj($i));
187 188 $vs = array();
... ... @@ -212,9 +213,11 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
212 213 }
213 214 if(($_POST["insrid"] == $_POST["outsrid"]) || $_POST["outsrid"] == ""){
214 215 $vs[] = "st_geomfromtext('".$s->toWkt()."','".$_POST["insrid"]."')";
  216 + $srid = $_POST["insrid"];
215 217 }
216 218 else{
217 219 $vs[] = "st_transform(st_geomfromtext('".$s->toWkt()."','".$_POST["insrid"]."'),'".$_POST["outsrid"]."')";
  220 + $srid = $_POST["outsrid"];
218 221 }
219 222 $str = implode(",",$vs);
220 223 $str = str_replace("nulo",'null',$str);
... ... @@ -228,7 +231,7 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
228 231 ob_flush();
229 232 flush();
230 233 sleep(1);
231   - if($_POST["incluiserialshp"] == "on"){
  234 + if($_POST["incluiserialshp"] == "on" || $_POST["i3GEOuploadCriaMapfile"] == "on"){
232 235 $linhas[] = "alter table ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." add gid serial CONSTRAINT ".$_POST["tabelaDestino"]."_gid_pkey PRIMARY KEY";
233 236 echo "<br>alter table ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." add gid serial CONSTRAINT ".$_POST["tabelaDestino"]."_gid_pkey PRIMARY KEY";
234 237 }
... ... @@ -257,6 +260,37 @@ if (isset($_FILES[&#39;i3GEOuploadshp&#39;][&#39;name&#39;])){
257 260 echo "<br>Registros na tabela final: ". count($r);
258 261 echo "<br>Diferen&ccedil;as podem ocorrer em fun&ccedil;&atilde;o de caracteres acentuados n&atilde;o suportados pelo banco de dados";
259 262 echo "<br><b>Feito!!!<br>Fa&ccedil;a o reload da p&aacute;gina";
  263 + if($_POST["i3GEOuploadCriaMapfile"] == "on"){
  264 + //verifica se o usuario marcou a opcao de cria mapfile
  265 + //nesse caso o aplicativo de upload esta sendo executado de dentro do sistema de administracao, e o mapfile devera
  266 + //ser criado e registrado no sistema
  267 + $nome = $_POST["tabelaDestino"];
  268 + $codigo = $_POST["tabelaDestino"];
  269 + $it = $_POST["tabelaDestino"];
  270 + $en = $_POST["tabelaDestino"];
  271 + $es = $_POST["tabelaDestino"];
  272 + //descobre o tipo de geometria
  273 + $tipo = "select ST_Dimension(the_geom) as d from ".$_POST["i3GEOuploadesquema"].".".$_POST["tabelaDestino"]." limit 1";
  274 + $q = $dbh->query($tipo,PDO::FETCH_ASSOC);
  275 + $tipo = $q->fetchAll();
  276 + $tipo = $tipo[0]["d"];
  277 + $tipoLayer = "polygon";
  278 + if ($tipo == 0){
  279 + $tipoLayer = "point";
  280 + }
  281 + if ($tipo == 1){
  282 + $tipoLayer = "line";
  283 + }
  284 + $funcao = "CRIARNOVOMAP";
  285 + $output = "retorno";
  286 + $data = "the_geom from ($sql) as foo using unique gid using srid=$srid ";
  287 + $conexao = 'dbname='.$conexao["bancodedados"].' user='.$conexao["usuario"].' password='.$conexao["senha"].' host='.$conexao["host"].' port='.$conexao["porta"];
  288 + include_once("editormapfile.php");
  289 + echo "<b><p class='paragrafo' >Criado o mapfile!!!<br>";
  290 + echo "Para editar clique: <a href='../../admin/html/editormapfile.html' target=_blank >".$nome."</a>";
  291 + echo "<script>window.scrollTo(0,10000);i3GEO.util.insereCookie('I3GEOletraAdmin','".$nome."');</script>";
  292 + }
  293 + echo "<br><br>Fim";
260 294 }
261 295 else{
262 296 echo "<p class='paragrafo' >Erro ao enviar o arquivo. Talvez o tamanho do arquivo seja maior do que o permitido.</p>";
... ...