Commit ec78cdac40616aeb931c11a645550da0fb830af2
1 parent
fc51a5cb
Exists in
master
and in
7 other branches
inclusao de opcao para calculos nas juncoes de tabelas do sistema metaestat
Showing
4 changed files
with
114 additions
and
45 deletions
Show diff stats
admin/admin.db
No preview for this file type
ferramentas/metaestat/analise.php
@@ -125,7 +125,7 @@ switch (strtoupper($funcao)){ | @@ -125,7 +125,7 @@ switch (strtoupper($funcao)){ | ||
125 | $retorno = listaLayersAgrupados($map_file); | 125 | $retorno = listaLayersAgrupados($map_file); |
126 | break; | 126 | break; |
127 | case "JUNTAMEDIDASVARIAVEIS": | 127 | case "JUNTAMEDIDASVARIAVEIS": |
128 | - $retorno = juntaMedidasVariaveis($map_file,$layerNames,$nome); | 128 | + $retorno = juntaMedidasVariaveis($map_file,$layerNames,$nome,$colunascalc,$formulas); |
129 | break; | 129 | break; |
130 | case "ADICIONALIMITEREGIAO": | 130 | case "ADICIONALIMITEREGIAO": |
131 | if(empty($outlinecolor)){ | 131 | if(empty($outlinecolor)){ |
@@ -650,7 +650,7 @@ function analise_aplicafiltroregiao($map_file,$codigo_tipo_regiao,$codigo_regiao | @@ -650,7 +650,7 @@ function analise_aplicafiltroregiao($map_file,$codigo_tipo_regiao,$codigo_regiao | ||
650 | * @return Nome do layer criado | 650 | * @return Nome do layer criado |
651 | * | 651 | * |
652 | */ | 652 | */ |
653 | -function juntaMedidasVariaveis($map_file,$layerNames,$nome){ | 653 | +function juntaMedidasVariaveis($map_file,$layerNames,$nome,$colunascalc,$formulas){ |
654 | //o sql que faz acesso aos dados e marcado com /*SE*//*SE*/ | 654 | //o sql que faz acesso aos dados e marcado com /*SE*//*SE*/ |
655 | $mapa = ms_newMapObj($map_file); | 655 | $mapa = ms_newMapObj($map_file); |
656 | $layernames = explode(",",$layerNames); | 656 | $layernames = explode(",",$layerNames); |
@@ -692,12 +692,36 @@ function juntaMedidasVariaveis($map_file,$layerNames,$nome){ | @@ -692,12 +692,36 @@ function juntaMedidasVariaveis($map_file,$layerNames,$nome){ | ||
692 | $colunasDados = array(); | 692 | $colunasDados = array(); |
693 | $itens = array($gid,"regiao"); | 693 | $itens = array($gid,"regiao"); |
694 | $itensdesc = array("gid","Regiao"); | 694 | $itensdesc = array("gid","Regiao"); |
695 | + $tabelaColuna = []; | ||
695 | for($i=0;$i<$n;$i++){ | 696 | for($i=0;$i<$n;$i++){ |
696 | $colunasDados[] = "tabela".$i.".".$colunasValor[$i]." as valortema".$i; | 697 | $colunasDados[] = "tabela".$i.".".$colunasValor[$i]." as valortema".$i; |
698 | + $tabelaColuna[valortema.$i] = "tabela".$i.".".$colunasValor[$i]; | ||
697 | $itens[] = "valortema".$i; | 699 | $itens[] = "valortema".$i; |
698 | $itensdesc[] = $nomesLayers[$i]; | 700 | $itensdesc[] = $nomesLayers[$i]; |
699 | } | 701 | } |
700 | - $sqlfinal = "SELECT tabela0.".$gid.",tabela0.".$regiao["colunanomeregiao"]." as regiao,tabela0.".$regiao["colunageo"]." as the_geom,".implode(",",$colunasDados)." from ".implode(",",$sqls)." WHERE "; | 702 | + //pega as colunas e as formulas adicionais |
703 | + $colunascalc = explode(",",$colunascalc); | ||
704 | + $formulas = explode(",",$formulas); | ||
705 | + $nformulas = count($formulas); | ||
706 | + $complemento = array(); | ||
707 | + for($i=0;$i<$nformulas;$i++){ | ||
708 | + $complemento[] = "(".$formulas[$i].") as ".$colunascalc[$i]; | ||
709 | + } | ||
710 | + $complemento = implode(",",$complemento); | ||
711 | + //substitui pelo nome correto das colunas | ||
712 | + foreach(array_keys($tabelaColuna) as $k){ | ||
713 | + $complemento = str_replace($k,$tabelaColuna[$k],$complemento); | ||
714 | + } | ||
715 | + if($complemento != ""){ | ||
716 | + $complemento .= ","; | ||
717 | + $itens = array_merge($itens,$colunascalc); | ||
718 | + $itensdesc = array_merge($itensdesc,$colunascalc); | ||
719 | + $complemento = str_ireplace("select","",$complemento); | ||
720 | + $complemento = str_ireplace("update","",$complemento); | ||
721 | + $complemento = str_ireplace("delete","",$complemento); | ||
722 | + } | ||
723 | + //echo $complemento;exit; | ||
724 | + $sqlfinal = "SELECT $complemento tabela0.".$gid.",tabela0.".$regiao["colunanomeregiao"]." as regiao,tabela0.".$regiao["colunageo"]." as the_geom,".implode(",",$colunasDados)." from ".implode(",",$sqls)." WHERE "; | ||
701 | $sqlfinal .= implode($cwhere," AND "); | 725 | $sqlfinal .= implode($cwhere," AND "); |
702 | $sqlfinal = str_replace("/*FA*/","",$sqlfinal); | 726 | $sqlfinal = str_replace("/*FA*/","",$sqlfinal); |
703 | $sqlfinal = str_replace("/*FAT*/","",$sqlfinal); | 727 | $sqlfinal = str_replace("/*FAT*/","",$sqlfinal); |
@@ -708,11 +732,11 @@ function juntaMedidasVariaveis($map_file,$layerNames,$nome){ | @@ -708,11 +732,11 @@ function juntaMedidasVariaveis($map_file,$layerNames,$nome){ | ||
708 | $nlayer->setmetadata("tema",$nome); | 732 | $nlayer->setmetadata("tema",$nome); |
709 | $nlayer->setmetadata("METAESTAT_DERIVADO","sim"); | 733 | $nlayer->setmetadata("METAESTAT_DERIVADO","sim"); |
710 | $nlayer->setmetadata("METAESTAT_ID_MEDIDA_VARIAVEL",""); | 734 | $nlayer->setmetadata("METAESTAT_ID_MEDIDA_VARIAVEL",""); |
711 | - $nlayer->setmetadata("TIP",""); | ||
712 | - $nlayer->setmetadata("arquivotemaoriginal",""); | ||
713 | - $nlayer->setmetadata("nomeoriginal",""); | ||
714 | - $nlayer->setmetadata("ITENS",implode(",",$itens)); | ||
715 | - $nlayer->setmetadata("ITENSDESC",implode(",",$itensdesc)); | 735 | + $nlayer->setmetadata("TIP",""); |
736 | + $nlayer->setmetadata("arquivotemaoriginal",""); | ||
737 | + $nlayer->setmetadata("nomeoriginal",""); | ||
738 | + $nlayer->setmetadata("ITENS",implode(",",$itens)); | ||
739 | + $nlayer->setmetadata("ITENSDESC",implode(",",$itensdesc)); | ||
716 | $nclass = $nlayer->numclasses; | 740 | $nclass = $nlayer->numclasses; |
717 | for($i=1;$i<$nclass;$i++){ | 741 | for($i=1;$i<$nclass;$i++){ |
718 | $nlayer->getclass($i)->set("status",MS_DELETE); | 742 | $nlayer->getclass($i)->set("status",MS_DELETE); |
ferramentas/metaestat/editorlimites.js
@@ -274,7 +274,7 @@ i3GEOF.editorlimites = { | @@ -274,7 +274,7 @@ i3GEOF.editorlimites = { | ||
274 | lista = [], | 274 | lista = [], |
275 | n = i3GEOF.editorlimites.shapes.length, | 275 | n = i3GEOF.editorlimites.shapes.length, |
276 | tipo = "", | 276 | tipo = "", |
277 | - ps,nps,j,p = {},i; | 277 | + ps,nps,j,p,i,r = {}; |
278 | 278 | ||
279 | for(i=0;i<n;i++){ | 279 | for(i=0;i<n;i++){ |
280 | coordenadas = []; | 280 | coordenadas = []; |
@@ -291,8 +291,8 @@ i3GEOF.editorlimites = { | @@ -291,8 +291,8 @@ i3GEOF.editorlimites = { | ||
291 | lista.push(coordenadas); | 291 | lista.push(coordenadas); |
292 | } | 292 | } |
293 | } | 293 | } |
294 | - p = {"tipo":tipo,"coordenadas":lista}; | ||
295 | - return p; | 294 | + r = {"tipo":tipo,"coordenadas":lista}; |
295 | + return r; | ||
296 | }, | 296 | }, |
297 | /** | 297 | /** |
298 | * Converte um objeto shape em uma string WKT | 298 | * Converte um objeto shape em uma string WKT |
ferramentas/metaestat/index.js
@@ -339,41 +339,12 @@ i3GEOF.metaestat = { | @@ -339,41 +339,12 @@ i3GEOF.metaestat = { | ||
339 | i3GEO.janela.abreAguarde("aguardeAnalise","Aguarde..."); | 339 | i3GEO.janela.abreAguarde("aguardeAnalise","Aguarde..."); |
340 | i3GEO.util.ajaxGet(p,i3GEOF.metaestat.analise.juntaMedidasVariaveis.janelaFlutuante); | 340 | i3GEO.util.ajaxGet(p,i3GEOF.metaestat.analise.juntaMedidasVariaveis.janelaFlutuante); |
341 | }, | 341 | }, |
342 | - janelaFlutuante: function(retorno){ | 342 | + janelaFlutuante: function(retorno){ |
343 | i3GEO.janela.fechaAguarde("aguardeAnalise"); | 343 | i3GEO.janela.fechaAguarde("aguardeAnalise"); |
344 | if($i("i3GEOF.junta_corpo")){ | 344 | if($i("i3GEOF.junta_corpo")){ |
345 | return; | 345 | return; |
346 | } | 346 | } |
347 | - var aplica,minimiza,cabecalho,titulo,ins,n,i,lista = "<table class=lista4 >"; | ||
348 | - aplica = function(){ | ||
349 | - if($i("aguardeAnalise_c") && $i("aguardeAnalise_c").style.visibility == "visible"){ | ||
350 | - return; | ||
351 | - }; | ||
352 | - i3GEO.janela.abreAguarde("aguardeAnalise","Aguarde..."); | ||
353 | - | ||
354 | - var atualiza,p,i, | ||
355 | - lista = [], | ||
356 | - ics = $i("i3GEOF.junta_corpo").getElementsByTagName("input"), | ||
357 | - n = ics.length; | ||
358 | - for(i=0;i<n;i++){ | ||
359 | - if(ics[i].type == "checkbox" && ics[i].checked === true){ | ||
360 | - lista.push(ics[i].value); | ||
361 | - } | ||
362 | - } | ||
363 | - if(lista.length == 0){ | ||
364 | - alert("Escolha uma camada"); | ||
365 | - return; | ||
366 | - } | ||
367 | - i3GEO.janela.abreAguarde("aguardeAnalise","Aguarde..."); | ||
368 | - p = i3GEO.configura.locaplic+"/ferramentas/metaestat/analise.php?g_sid="+i3GEO.configura.sid + | ||
369 | - "&funcao=juntaMedidasVariaveis&layerNames="+lista.join(",")+"&nome="+$i("i3GEOFjuntaNovoNome").value; | ||
370 | - atualiza = function(){ | ||
371 | - i3GEO.janela.fechaAguarde("aguardeAnalise"); | ||
372 | - i3GEO.atualiza(); | ||
373 | - i3GEOF.metaestat.analise.comboCamadas(); | ||
374 | - }; | ||
375 | - i3GEO.util.ajaxGet(p,atualiza); | ||
376 | - }; | 347 | + var minimiza,cabecalho,titulo,ins,n,i,lista = "<table class=lista4 >"; |
377 | cabecalho = function(){ | 348 | cabecalho = function(){ |
378 | }; | 349 | }; |
379 | minimiza = function(){ | 350 | minimiza = function(){ |
@@ -405,12 +376,86 @@ i3GEOF.metaestat = { | @@ -405,12 +376,86 @@ i3GEOF.metaestat = { | ||
405 | lista + | 376 | lista + |
406 | '<br><p class=paragrafo >Nome da nova camada</p>' + | 377 | '<br><p class=paragrafo >Nome da nova camada</p>' + |
407 | $inputText("","","i3GEOFjuntaNovoNome","",30,'') + | 378 | $inputText("","","i3GEOFjuntaNovoNome","",30,'') + |
408 | - '<br><br><input id=i3geojuntaAplica type="button" value="Aplicar" />'; | 379 | + '<br><br><input id=i3geojuntaAplica type="button" value="Aplicar" />' + |
380 | + '<div id=i3GEOFjuntaColunasCalculadas >' + | ||
381 | + '<br><p class=paragrafo ><b>Colunas calculadas (opcional)</b></p></div>' + | ||
382 | + '<div id=i3GEOFjuntaColunasCalculadasMensagemAjuda ></div>' ; | ||
409 | $i("i3GEOF.junta_corpo").innerHTML = ins; | 383 | $i("i3GEOF.junta_corpo").innerHTML = ins; |
410 | new YAHOO.widget.Button( | 384 | new YAHOO.widget.Button( |
411 | "i3geojuntaAplica", | 385 | "i3geojuntaAplica", |
412 | - {onclick:{fn: aplica}} | 386 | + {onclick:{fn: i3GEOF.metaestat.analise.juntaMedidasVariaveis.aplica}} |
387 | + ); | ||
388 | + i3GEOF.metaestat.analise.juntaMedidasVariaveis.noNovoCalculo(); | ||
389 | + //ajuda para o calculo | ||
390 | + i3GEO.util.mensagemAjuda("i3GEOFjuntaColunasCalculadasMensagemAjuda", | ||
391 | + "As colunas calculadas são fórmulas que utilizam as colunas que forem juntadas e que serão acrescentadas"+ | ||
392 | + "à nova camada. Cada uma dessas colunas receberá um nome sequencial, por exemplo <i>valortema0,valortema1,"+ | ||
393 | + "valortema2...</i><br>As colunas calculadas podem utilizar essas colunas como entrada em fórmulas."+ | ||
394 | + "Cada fórmula irá gerar uma nova coluna na tabela e deve utilizar a sintaxe SQL (<a href='http://www.postgresql.org/docs/9.3/static/functions-math.html' target=_blank >SQL no Postgres</a>)"+ | ||
395 | + "<br>Exemplos de uso:<br>" + | ||
396 | + "coluna de nome <b>soma</b><br>" + | ||
397 | + "valortema0 + valortema1 <br>" + | ||
398 | + "coluna de nome <b>taxa</b><br>" + | ||
399 | + "(valortema0 * 100) / valortema1" | ||
413 | ); | 400 | ); |
401 | + }, | ||
402 | + noNovoCalculo: function(){ | ||
403 | + var no = document.createElement("div"); | ||
404 | + no.style.margin = "10px"; | ||
405 | + no.style.padding = "5px"; | ||
406 | + no.style.backgroundColor = "beige"; | ||
407 | + no.style.width = "210px"; | ||
408 | + no.innerHTML = '<p class=paragrafo >Nome (apenas letras e números)<br>' + | ||
409 | + '<input type=text value="" style=width:205px />' + | ||
410 | + '<br>Fórmula (padrão sql)<br>' + | ||
411 | + '<textarea style=width:205px ></textarea></p>'; | ||
412 | + $i("i3GEOFjuntaColunasCalculadas").appendChild(no); | ||
413 | + }, | ||
414 | + pegaCalculos: function(){ | ||
415 | + var div = $i("i3GEOFjuntaColunasCalculadas"), | ||
416 | + nomes = div.getElementsByTagName("input"), | ||
417 | + formulas = div.getElementsByTagName("textarea"), | ||
418 | + n = nomes.length, | ||
419 | + parnomes = [], | ||
420 | + parformulas = [], | ||
421 | + i; | ||
422 | + for(i=0;i<n;i++){ | ||
423 | + if(nomes[i].value != "" && formulas[i].value != ""){ | ||
424 | + parnomes.push(nomes[i].value); | ||
425 | + parformulas.push(formulas[i].value); | ||
426 | + } | ||
427 | + } | ||
428 | + return "&colunascalc="+parnomes.join(",")+"&formulas="+parformulas.join(","); | ||
429 | + }, | ||
430 | + aplica: function(){ | ||
431 | + if($i("aguardeAnalise_c") && $i("aguardeAnalise_c").style.visibility == "visible"){ | ||
432 | + return; | ||
433 | + }; | ||
434 | + i3GEO.janela.abreAguarde("aguardeAnalise","Aguarde..."); | ||
435 | + var ps,atualiza,p,i, | ||
436 | + lista = [], | ||
437 | + ics = $i("i3GEOF.junta_corpo").getElementsByTagName("input"), | ||
438 | + n = ics.length; | ||
439 | + for(i=0;i<n;i++){ | ||
440 | + if(ics[i].type == "checkbox" && ics[i].checked === true){ | ||
441 | + lista.push(ics[i].value); | ||
442 | + } | ||
443 | + } | ||
444 | + if(lista.length == 0){ | ||
445 | + alert("Escolha uma camada"); | ||
446 | + return; | ||
447 | + } | ||
448 | + i3GEO.janela.abreAguarde("aguardeAnalise","Aguarde..."); | ||
449 | + p = i3GEO.configura.locaplic+"/ferramentas/metaestat/analise.php?g_sid="+i3GEO.configura.sid + | ||
450 | + "&funcao=juntaMedidasVariaveis&layerNames="+lista.join(",")+"&nome="+$i("i3GEOFjuntaNovoNome").value; | ||
451 | + ps = i3GEOF.metaestat.analise.juntaMedidasVariaveis.pegaCalculos(); | ||
452 | + atualiza = function(){ | ||
453 | + i3GEO.janela.fechaAguarde("aguardeAnalise"); | ||
454 | + i3GEO.atualiza(); | ||
455 | + i3GEOF.metaestat.analise.comboCamadas(); | ||
456 | + }; | ||
457 | + //i3GEO.util.ajaxGet(p,atualiza); | ||
458 | + cpJSON.call(p,"foo",atualiza,ps); | ||
414 | } | 459 | } |
415 | }, | 460 | }, |
416 | /** | 461 | /** |
@@ -1565,7 +1610,7 @@ i3GEOF.metaestat = { | @@ -1565,7 +1610,7 @@ i3GEOF.metaestat = { | ||
1565 | $i("EcolunaDia").value = ""; | 1610 | $i("EcolunaDia").value = ""; |
1566 | $i("EcolunaHora").value = ""; | 1611 | $i("EcolunaHora").value = ""; |
1567 | } | 1612 | } |
1568 | - } | 1613 | + }; |
1569 | //impede a alteracao do filtro | 1614 | //impede a alteracao do filtro |
1570 | $i("Efiltro").disabled = "disabled"; | 1615 | $i("Efiltro").disabled = "disabled"; |
1571 | //altera a tabela quando escolher | 1616 | //altera a tabela quando escolher |