From 43f2d76f66cc67f48783ee291a9a6fde4ef04db8 Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Fri, 15 May 2015 14:24:13 +0000 Subject: [PATCH] Correção no uso de JSON na requisição WMS getfeatureinfo --- aplicmap/ogcws.map | 2 ++ aplicmap/ogcwsv5.map | 1 + aplicmap/ogcwsv6.map | 1 + classesphp/funcoes_gerais.php | 3 ++- guia_de_migracao.txt | 6 +++++- ogc.php | 84 +++++++++++++++++++++++++++++++++++++++++++++--------------------------------------- temas/_lbiomashp.map | 2 +- 7 files changed, 57 insertions(+), 42 deletions(-) diff --git a/aplicmap/ogcws.map b/aplicmap/ogcws.map index aa0d741..df72b1c 100644 --- a/aplicmap/ogcws.map +++ b/aplicmap/ogcws.map @@ -105,6 +105,8 @@ MAP "ows_namespace_uri" "http://www.omsug.ca/osgis2004" "ows_address" "http://www.mma.gov.br" "ows_postcode" "" + "wms_info" "1.1.1" + "wms_feature_info_mime_type" "application/json" "ows_enable_request" "*" END QUERYFORMAT text/html diff --git a/aplicmap/ogcwsv5.map b/aplicmap/ogcwsv5.map index 3c7b517..ea14d9b 100644 --- a/aplicmap/ogcwsv5.map +++ b/aplicmap/ogcwsv5.map @@ -107,6 +107,7 @@ MAP "ows_address" "http://www.mma.gov.br" "ows_postcode" "" "ows_enable_request" "*" + "wms_feature_info_mime_type" "application/json" END QUERYFORMAT text/html LEGENDFORMAT text/html diff --git a/aplicmap/ogcwsv6.map b/aplicmap/ogcwsv6.map index 405fcf7..3dc9838 100644 --- a/aplicmap/ogcwsv6.map +++ b/aplicmap/ogcwsv6.map @@ -138,6 +138,7 @@ MAP "ows_postcode" "" "ows_enable_request" "*" "ows_sld_enabled" "true" + "wms_feature_info_mime_type" "application/json" END QUERYFORMAT text/html LEGENDFORMAT text/html diff --git a/classesphp/funcoes_gerais.php b/classesphp/funcoes_gerais.php index b748380..8c249a9 100644 --- a/classesphp/funcoes_gerais.php +++ b/classesphp/funcoes_gerais.php @@ -2201,6 +2201,7 @@ function getRGBpallete($rule, $value){ $b=$rule["b0"] + round(($rule["b1"]-$rule["b0"])*$escala, 0); return array($r,$g,$b); } +//TODO verificar ao fechar versao /* Function: removeAcentos @@ -2216,7 +2217,7 @@ Retorno: */ function removeAcentos($var) { - $a = array('�', 'Á', 'Â', 'Ã', '�', '�', '�', 'Ç', '�', 'É', 'Ê', '�', '�', 'Í', '�', '�', '�', '�', '�', '�', 'Ô', 'Õ', '�', '�', '�', 'Ú', '�', '�', '�', '�', '�', 'á', 'â', 'ã', '�', '�', '�', 'ç', '�', 'é', 'ê', '�', '�', 'í', '�', '�', '�', '�', '�', 'ô', 'õ', '�', '�', '�', 'ú', '�', '�', '�', '�', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', '�', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', '�', '�', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', '�', '�', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', '�', 'Z', 'z', 'Z', 'z', '�', '�', '?', '�', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?'); + $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?'); $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); return str_replace($a, $b, $var); } diff --git a/guia_de_migracao.txt b/guia_de_migracao.txt index 99a05ed..d6e7acf 100644 --- a/guia_de_migracao.txt +++ b/guia_de_migracao.txt @@ -7,6 +7,10 @@ Para a versão 7.0 ------------------------------------------------------------------------------------------------- Para a versão 6.0 +- para permitir o retorno da requisição WMS getfeatureinfo em JSON, foi incluído no mapfile base utilizado para +gerar os serviços OGC a linha "wms_feature_info_mime_type" "application/json" em WEB->METADATA +Caso você utilize um mapfile específico da sua instalação, veja o arquivo original existente em i3geo/aplicmap +para fazer as adaptações. - style.overflow passou a ser definido automaticamente como "hidden" para previnir problemas com as janelas de informação. Essa definição ocorre apenas quando o elemento body do HTML contiver o id definido como "i3geo" e quando seu estilo @@ -18,7 +22,7 @@ de informação - Inclusão da variável $i3geo_proxy_server no ms_configura.php para uso em algumas operações baseadas no acesso a outros servidores via Curl e OGC -- Inclusão da variável $statusFerramentas no ms_configura para controlar o status de ferramentas que +- Inclusão da variável $statusFerramentas no ms_configura para controlar o status de ferramentas que dependem de configuração específica do servidor - Foram incluídos subitens no menu suspenso para acomodar o grande número de opções. Os códigos locais que diff --git a/ogc.php b/ogc.php index 6340848..dc5df36 100644 --- a/ogc.php +++ b/ogc.php @@ -106,17 +106,6 @@ if(strtolower($OUTPUTFORMAT) == "kml" || strtolower($OUTPUTFORMAT) == "kmz"){ $urln = "pacotes/kmlmapserver/kmlservice.php?request=kmz&map=".$tema."&typename=".$tema; header("Location:".$urln); exit; - /* - $l = $oMap->getlayer(0); - $n = $l->name."-kml"; - $oMap->selectOutputFormat("kml"); - $oMap->outputformat->setOption("STORAGE", "memory"); - $oMap->outputformat->setOption("FILENAME", $n.".kml"); - $l->setmetadata("wfs_getfeature_formatlist","kml"); - $oMap->save($nomeMapfileTmp); - header('Content-Disposition: attachment; filename='.$n.'.kml'); - header("Content-type: application/vnd.google-earth.kml+xml"); - */ } //define um nome para o mapfile caso a origem seja o sistema de metadados estatisticos @@ -876,42 +865,53 @@ ms_ioinstallstdouttobuffer(); if(strtolower($req->getValueByName("REQUEST")) == "getmap" && $req->getValueByName("format") == ""){ $req->setParameter("format","image/png"); } - +if(strtolower($req->getValueByName("REQUEST")) == "getfeatureinfo" && $_GET["info_format"] == "text/xml"){ + $req->setParameter("info_format","application/vnd.ogc.gml"); +} +//json conforme cesium if(strtolower($req->getValueByName("REQUEST")) == "getfeatureinfo" && $_GET["info_format"] == "application/json"){ - //TODO verificar itens e itensdesc - //FIXME essa nao e a melhor forma de fazer o Json - $req->setParameter("info_format","text/plain"); + $req->setParameter("info_format","application/vnd.ogc.gml"); $oMap->owsdispatch($req); ms_iostripstdoutbuffercontentheaders(); ob_clean(); $r = ms_iogetstdoutbufferstring(); - $t = explode("=",$r); + //$r = converteenc($r); + $nome = $oMap->getlayer(0)->name; + $xml = simplexml_load_string($r); + + $json = json_encode($xml); + $r = json_decode($json,TRUE); + $propriedades = $r[$nome."_layer"]; + $propriedades = $propriedades[$nome."_feature"]; + $propriedades = converteenc(json_encode($propriedades)); + $propriedades = json_decode($propriedades); $n = array(); - if(count($t) > 1){ - $v = str_replace("\\n","",$t[1]); - $v = str_replace("\\r","",$v); - if(trim($v) != ""){ - $va = trim($v); - $coluna = trim(explode(":",$t[0])[2]); - $valor = str_replace("'","",$va); - $n[] = array ( - "type" => "FeatureCollection", - "features" => array( - array( - "type"=>"Feature", - "id" => "", - "geometry" => array(), - "properties" => array( - $coluna => $valor - ), - "geometry_name" => "" - ) + $n[] = array ( + "type" => "FeatureCollection", + "features" => array( + array( + "type"=>"Feature", + "id" => "", + "geometry" => array(), + "properties" => array( + $propriedades + ), + "geometry_name" => "" ) - ); - } - } + ) + ); header("Content-type: application/json"); - echo json_encode($n[0]); + $json = json_encode($n[0]); + //verifica a substituicao de alias + $itens = $oMap->getlayer(0)->getmetadata("ITENS"); // itens + $itensdesc = $oMap->getlayer(0)->getmetadata("ITENSDESC"); // descrição dos itens + $itens = explode(",",$itens); + $itensdesc = explode(",",converteenc($itensdesc)); + $n = count($itens); + for($i = 0; $i < $n; $i++){ + $json = str_ireplace($itens[$i],$itensdesc[$i],$json); + } + echo $json; exit; } @@ -1145,4 +1145,10 @@ function renderNocacheTms(){ header("Content-type: image/png"); } } +function converteenc($texto){ + if (!mb_detect_encoding($texto,"UTF-8",true)){ + $texto = mb_convert_encoding($texto,"UTF-8","ISO-8859-1"); + } + return $texto; +} ?> diff --git a/temas/_lbiomashp.map b/temas/_lbiomashp.map index e112160..fda0b63 100644 --- a/temas/_lbiomashp.map +++ b/temas/_lbiomashp.map @@ -9,7 +9,7 @@ MAP "TIP" "CD_LEGENDA" "CLASSE" "SIM" "permitekmz" "SIM" - "ITENSDESC" "Teste de acentuação" + "ITENSDESC" "Bioma Teste de acentuação" "ESCALA" "1000000" "TILES" "SIM" "METAESTAT_CODIGO_TIPO_REGIAO" "" -- libgit2 0.21.2