getlayerbyname($layername);
$nclasses = $layer->numclasses;
if($nclasses == 1)
{
$classe = $layer->getclass(0);
$expressao = $classe->getExpressionString();
if($expressao == "")
{return "simples";exit;}
$expressao = str_replace("'eq'","=");
$expressao = str_replace("'eq '","=");
$expressao = str_replace("' eq'","=");
$expressao = str_replace("' eq '","=");
if(count(explode("=",$expressao)) != 2)
{return "simples";exit;}
}
$verItem = array();
for($i=0;$i<$nclasses;++$i)
{
$classe = $layer->getclass($i);
$expressao = $classe->getExpressionString();
if(count(explode("[",$expressao)) > 2)
{
return "intervalo";
exit;
}
//
//verifica se os itens são únicos nas expressões
//
$item = preg_replace('/.*\[|\].*/i','\1', $expressao);
$verItem[$item] = 0;
}
if(count($verItem) == 1)
return "valorunico";
else
return "simples";
}
function legendaValorUnico($layername)
{
global $mapa;
$tipolegenda = "";
$layer = $mapa->getlayerbyname($layername);
$nclasses = $layer->numclasses;
$outlinecolor = array();
$color = array();
$nomes = array();
$valor = array();
//
$classe = $layer->getclass(0);
$expressao = $classe->getExpressionString();
$item = preg_replace('/.*\[|\].*/i','\1', $expressao);
for($i=0;$i<$nclasses;++$i)
{
$classe = $layer->getclass($i);
$estilo = $classe->getstyle(0);
$nomes[] = $classe->name;
$cor = $estilo->outlinecolor;
$outlinecolor[] = "'".$cor->red.",".$cor->green.",".$cor->blue.",255'";
$cor = $estilo->color;
$color[] = "'".$cor->red.",".$cor->green.",".$cor->blue.",255'";
$expressao = $classe->getExpressionString();
$expressao = str_replace("'eq","=",$expressao);
$expressao = str_replace("'eq ","=",$expressao);
$expressao = str_replace("' eq","=",$expressao);
$expressao = str_replace("' eq ","=",$expressao);
$temp = explode("=",$expressao);
$temp = trim($temp[1]);
$temp = trim(str_replace("'","",$temp));
$temp = trim(str_replace(")","",$temp));
$valor[] = trim(str_replace("'","",$temp));
}
//
//monta o xml
//
$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$temp = array();
$temp[] = "1111";
foreach($valor as $v)
{$temp[] = "-1";}
$temp = implode(" ,",$temp);
//$temp = "1111 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "";
$xml .= "\n";
$c = count($valor);
for($i=0;$i<$c;++$i)
{
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$temp = "true";
if($outlinecolor[$i] == "'-1,-1,-1,255'"){$temp = "false";}
$xml .= "\n";
if($color[$i] != "'-1,-1,-1,255'")
$xml .= "\n";
if($temp != "false")
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
}
$xml .= "\n";
echo header("Content-type: application/xml");
echo $xml;
exit;
}
function legendaSimples($layername)
{
global $mapa;
$tipolegenda = "";
$layer = $mapa->getlayerbyname($layername);
$classe = $layer->getclass(0);
$estilo = $classe->getstyle(0);
$cor = $estilo->color;
$outcor = $estilo->outlinecolor;
$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
if($cor->red != -1)
$xml .= "\n";
if($outcor->red != -1)
$xml .= "\n";
else
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
echo header("Content-type: application/xml");
echo $xml;
exit;
}
//
//gera xml com parâmetros do mapfile
//
function mapfile()
{
global $codigoLayer,$mapfile,$mapa,$objcontype,$objlayertypes,$forcawms,$postgis_mapa,$bloqueiaStringConexao;
$layers = $mapa->getalllayernames();
$dados = array();
$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
$xml .= "\n\n";
$xml .= "".implode(",",$objcontype)."\n";
$xml .= "".implode(",",$objlayertypes)."\n";
//verifica se tem grupos
$nlayers = array();
foreach ($layers as $layer)
{
$layer = $mapa->getlayerbyname($layer);
if($objcontype[$layer->connectiontype] != MS_WMS )
{
if($layer->group == "")
{$nlayers[] = $layer->name;}
else
{
if($layer->group == $layer->name)
{$nlayers[] = $layer->name;}
}
$layers = $nlayers;
}
}
foreach ($layers as $layer)
{
$xml .= "\n\n";
$layer = $mapa->getlayerbyname($layer);
$xml .= "".$layer->getmetadata('tema')."\n";
$d = $layer->data;
if (@$layer->open() == MS_SUCCESS)
{$colunas = implode(",",$layer->getItems());}
else
{$colunas = "*";}
$ct = $objcontype[$layer->connectiontype];
$tagLegenda = "parsemapfile.php?id=".$codigoLayer."&layername=".$layer->name."&tipoparse=legenda";
$nomeLayer = $layer->name;
if ($forcawms == "sim" || $ct == "MS_SHAPEFILE" || $ct == "" || $ct == "MS_RASTER" && $ct != "MS_WMS")
{
$ct = "MS_WMS";
$d = "http://".$_SERVER['HTTP_HOST'].str_replace("/admin/php/parsemapfile.php","",$_SERVER['PHP_SELF'])."/ogc.php?tema=".$codigoLayer;
$xml .= "1.1.1";
$xml .= "EPSG:4618";
$xml .= "image/png";
$xml .= "";
$tagLegenda = "";
}
else if($ct == "MS_WMS")
{
$d = $layer->connection;
$v = $layer->getmetadata("wms_server_version");
$e = $layer->getmetadata("wms_srs");
$i = $layer->getmetadata("wms_format");
$s = $layer->getmetadata("wms_style");
$nomeLayer = $layer->getmetadata("wms_name");
if($nomeLayer == "")
$nomeLayer = $layer->getmetadata("ows_name");
if($v == "")
$v = $layer->getmetadata("ows_server_version");
if($e == "")
$e = $layer->getmetadata("ows_srs");
if($i == "")
$i = $layer->getmetadata("ows_format");
if($s == "")
$s = $layer->getmetadata("ows_style");
if($s == "")
{$s = "default";}
$xml .= "$v";
$xml .= "$e";
$xml .= "image/png";
$xml .= "";
$tagLegenda = "";
}
$xml .= "$tagLegenda";
$xml .= "".$ct."\n";
$xml .= "$d\n";
$xml .= "$nomeLayer\n";
if($ct != "MS_WMS")
{
$xml .= "\n";
$con = $layer->connection;
if (($con == " ") || ($con == "") || (in_array($con,array_keys($postgis_mapa))))
{
if(($con == " ") || ($con == ""))
{$con = $postgis_mapa;}
else
{$con = $postgis_mapa[$con];}
}
if($bloqueiaStringConexao == true){
$xml .= "bloqueado (veja i3geo/admin/php/parsemapfile)\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "\n";
}
else{
$xml .= "".preg_replace('/.*user\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n";
$xml .= "".preg_replace('/.*password\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n";
$xml .= "".preg_replace('/.*dbname\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n";
$xml .= "".preg_replace('/.*host\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n";
$xml .= "".preg_replace('/.*port\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n";
}
$xml .= "\n";
$d = explode("(",$d);
$d = explode(")",$d[1]);
$dstring = $d[0];
$dstring = str_replace("the_geom","",$dstring);
$dstring = str_replace("*",$colunas,$dstring);
$xml .= "$colunas";
$xml .= "\n";
$string = preg_replace('/.*from\s*(.+).*/i', '\1', $d[0]);
$s = explode("WHERE",$string);
if(count($s) == 1)
$s = explode("where",$string);
$esquemaTabela = explode(".",$s[0]);
$xml .= "".$esquemaTabela[0]."";
$xml .= "".$esquemaTabela[1]."";
$xml .= "".$s[1]."";
$xml .= "".$objlayertypes[$layer->type]."\n";
$xml .= "".$layer->getfilterstring()."\n";
$xml .= "$layer->filteritem\n";
//$xml .= "".$layer->labelangleitem."\n";
$xml .= "$layer->labelitem\n";
$xml .= "$layer->labelmaxscaledenom\n";
$xml .= "$layer->labelminscaledenom\n";
$xml .= "\n";
}
$xml .= "$layer->group\n";
$xml .= "$layer->maxscaledenom\n";
$xml .= "$layer->minscaledenom\n";
$xml .= "".$layer->offsite->red.",".$layer->offsite->green.",".$layer->offsite->blue."\n";
$xml .= "$layer->opacity\n";
if($ct != "MS_WMS")
{
$xml .= "$layer->symbolscaledenom\n";
$xml .= "$layer->tileindex\n";
$xml .= "$layer->tileitem\n";
$xml .= "$layer->tolerance\n";
$xml .= "$layer->toleranceunits\n";
$xml .= "$layer->sizeunits\n";
$xml .= "".$layer->getProjection()."\n";
$xml .= "\n";
$xml = pegaClasses($xml);
$xml .= "\n";
}
$xml .= "";
}
$xml .= "\n";
echo header("Content-type: application/xml");
echo $xml;
}
function pegaClasses($xml)
{
global $layer;
$dados = array();
$nclasses = $layer->numclasses;
for($i=0;$i<$nclasses;++$i)
{
$xml .= "\n";
$classe = $layer->getclass($i);
$xml .= "".mb_convert_encoding(($classe->name),"UTF-8","ISO-8859-1")."\n";
$xml .= "".$classe->getExpressionString()."\n";
$xml .= "$classe->keyimage\n";
$xml .= "$classe->size\n";
$xml .= "$classe->symbolname\n";
$xml .= "$classe->type\n";
$xml .= "\n";
$xml = pegaEstilos($xml,$classe);
$xml .= "\n";
$xml .= "\n";
}
return $xml;
}
function pegaEstilos($xml,$classe)
{
$numestilos = $classe->numstyles;
$estilos = array();
for($j=0;$j<$numestilos;++$j)
{
$xml .= "\n";
$estilo = $classe->getstyle($j);
$xml .= "$estilo->symbolname\n";
$xml .= "".$estilo->color->red.",".$estilo->color->green.",".$estilo->color->blue."\n";
$xml .= "$estilo->size\n";
$xml .= "".$estilo->backgroundcolor->red.",".$estilo->backgroundcolor->green.",".$estilo->backgroundcolor->blue."\n";
$xml .= "".$estilo->outlinecolor->red.",".$estilo->outlinecolor->green.",".$estilo->outlinecolor->blue."\n";
$xml .= "\n";
}
return $xml;
}
?>