wmswfs.php 21 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
<?php
/*
Title: OGC

Faz a leitura e o processamento de web services nos padrões OGC.
Atualmente, processa apenas serviços no padrão WMS.

About: Licença

I3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet

Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil
Desenvolvedor: Edmar Moretti edmar.moretti@mma.gov.br

Este programa é software livre; você pode redistribuí-lo
e/ou modificá-lo sob os termos da Licença Pública Geral
GNU conforme publicada pela Free Software Foundation;
tanto a versão 2 da Licença.
Este programa é distribuído na expectativa de que seja útil,
porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita
de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA.
Consulte a Licença Pública Geral do GNU para mais detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral do
GNU junto com este programa; se não, escreva para a
Free Software Foundation, Inc., no endereço
59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.

File: wmswfs.php

19/6/2007
*/
/*
function: existeTemaWFS

Verifica se existe um tema em um servico WFS processando o getcapabilities.

parameters:
$wfs - endereço do serviço

$tema - tema que será verificado
*/
function existeTemaWFS()
{
	global $wfs,$tema;
	$capabilities = implode("",$wfs);
	$dom = new DomDocument();
	$dom->loadXML($capabilities);
	$xpath = new DOMXPath($dom);
	$query = '//WFS_Capabilities/FeatureTypeList/FeatureType';
	$entries = $xpath->query($query);
	foreach($entries as $e)
	{
		$e->getElementsByTagName("Name");
		$n = $e->nodeValue;
		if ($n == $tema)
		{return "sim";}
	}
	return "nao";
}
/*
function: existeWFS

Verifica se existe um servico WFS invocando o getcapabilities.

parameters:
$servico - endereço do serviço
*/
function existeWFS()
{
	global $servico;
	$teste = explode("=",$servico);
	if ( count($teste) > 1 ){$servico = $servico."&";}
	$wms_service_request = $servico . "REQUEST=GetCapabilities&SERVICE=WFS";
	# -------------------------------------------------------------
	# Test that the capabilites file has successfully downloaded.
	#
	if( !($wfs_capabilities = file($wms_service_request)) ) {
		# Cannot download the capabilities file.
		return "nao";
	}
	else
	{return $wfs_capabilities;}
}
/*
function: getcapabilities

Chama a função getcapabilities e retorna o resultado.

parameters:
$servico - Endereço do web service.

$cp - Objeto CPAINT.
*/
function getcapabilities()
{
	global $servico,$cp;
	$teste = explode("=",$servico);
	if ( count($teste) > 1 ){$servico = $servico."&";}
	$wms_service_request = $servico . "REQUEST=GetCapabilities&SERVICE=WMS&version=1.1.0";
	# -------------------------------------------------------------
	# Test that the capabilites file has successfully downloaded.
	#
	if( !($wms_capabilities = file($wms_service_request)) ) {
		# Cannot download the capabilities file.
		$cp->set_data("Erro de acesso");
		return;
	}
	$wms_capabilities = implode("",$wms_capabilities);
	$cp->set_data(xml2html($wms_capabilities));
}
/*
function: getcapabilities2

Chama a função getcapabilities e retorna o resultado formatado (WMS).

parameters:
$servico - Endereço do web service.

$cp - Objeto CPAINT.
*/
function getcapabilities2()
{
	global $servico,$cp;
	$teste = explode("=",$servico);
	if ( count($teste) > 1 ){$servico = $servico."&";}
	$wms_service_request = $servico . "REQUEST=GetCapabilities&SERVICE=WMS&version=1.1.0";
	# -------------------------------------------------------------
	# Test that the capabilites file has successfully downloaded.
	#
	if( !($wms_capabilities = file($wms_service_request)) ) {
		# Cannot download the capabilities file.
		$cp->set_data("Erro de acesso");
		return;
	}
	$wms_capabilities = implode("",$wms_capabilities);
	$dom = new DomDocument();
	$dom->loadXML($wms_capabilities);
	$xpath = new DOMXPath($dom);
	$retorno = "";
	$query = '//WMT_MS_Capabilities/Service/Name';
	$entries = $xpath->query($query);
	$temp = "";
	foreach ($entries as $entry){$temp .= $entry->nodeValue;}
	$retorno .= "<b>Nome: </b>".$temp;

	$query = '//WMT_MS_Capabilities/Service/Title';
	$entries = $xpath->query($query);
	$temp = "";
	foreach ($entries as $entry){$temp .= $entry->nodeValue;}
	$retorno .= "<br><br><b>T&iacute;tulo: </b>".$temp;

	$query = '//WMT_MS_Capabilities/Service/Abstract';
	$entries = $xpath->query($query);
	$temp = "";
	foreach ($entries as $entry){$temp .= $entry->nodeValue;}
	$retorno .= "<br><br><b>Resumo: </b>".$temp;

	$query = '//WMT_MS_Capabilities/Service/KeywordList';
	$entries = $xpath->query($query);
	$temp = "";
	foreach ($entries as $entry){$temp .= $entry->nodeValue.".";}
	$retorno .= "<br><br><b>Palavras-chave: </b>".$temp;

	$query = '//WMT_MS_Capabilities/Service/ContactInformation';
	$entries = $xpath->query($query);
	$temp = "";
	foreach ($entries as $entry){$temp .= $entry->nodeValue.".";}
	$retorno .= "<br><br><b>Contato: </b>".$temp;

	$cp->set_data($retorno);
}
/*
function: getcapabilities3

Chama a função getcapabilities e retorna o resultado formatado (WFS).

parameters:

$servico - Endereço do web service.

$cp - Objeto CPAINT.
*/
function getcapabilities3()
{
	global $servico,$cp;
	$teste = explode("=",$servico);
	if ( count($teste) > 1 ){$servico = $servico."&";}
	$wms_service_request = $servico . "request=getcapabilities&service=wfs&version=1.0.0";
	# -------------------------------------------------------------
	# Test that the capabilites file has successfully downloaded.
	#
	if( !($wms_capabilities = file($wms_service_request)) ) {
		# Cannot download the capabilities file.
		$cp->set_data("Erro de acesso");
		return;
	}
	$wms_capabilities = implode("",$wms_capabilities);
	$dom = new DomDocument();
	$dom->loadXML($wms_capabilities);
	$retorno = "";
	$services = $dom->getElementsByTagName("Service");
	foreach ($services as $service)
	{
		$vs = $service->getElementsByTagName("Name");
		$temp = "";
		foreach ($vs as $v)
		{$temp .= $v->nodeValue;}
		$retorno .= "<b>Nome: </b>".$temp;
		$vs = $service->getElementsByTagName("Title");
		$temp = "";
		foreach ($vs as $v)
		{$temp .= $v->nodeValue;}
		$retorno .= "<br><br><b>T&iacute;tulo: </b>".$temp;
	}
	$cp->set_data($retorno);
}
/*
function: temaswms

Lista os temas de um web service WMS.

parameters:

$servico - Endereço do web service.

$cp - Objeto CPAINT.
*/
function temaswms()
{
	global $servico,$cp;
	$teste = explode("=",$servico);
	if ( count($teste) > 1 ){$servico = $servico."&";}
	$wms_service_request = $servico . "REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1";
	# -------------------------------------------------------------
	# Test that the capabilites file has successfully downloaded.
	#
	if( !($wms_capabilities = file($wms_service_request)) ) {
		# Cannot download the capabilities file.
		$cp->set_data("Erro de acesso");
		return;
	}
	$wms_capabilities = implode("",$wms_capabilities);
	$dom = new DomDocument();
	$dom->loadXML($wms_capabilities);
	$layers = wms_layers($dom);
	$xpath = new DOMXPath($dom);
	//verifica sld
	$query = '//WMT_MS_Capabilities/Capability/UserDefinedSymbolization';
	$entries = $xpath->query($query);
	foreach($entries as $e)
	{$n = $e->getAttribute("SupportSLD");}
	$suporta = "nao";
	if ($n == 1){$suporta = "sim";}
	
	$query = '//WMT_MS_Capabilities/Capability/Layer/Layer/Style';
	$entries = $xpath->query($query);
	$nums = $entries->length;
	if ($entries->length > 0)
	{
	 	 $query = '//WMT_MS_Capabilities/Capability/Layer';
		 $entries = $xpath->query($query);	 	 
	}
	$tval = "";
	foreach ($layers as $layer)
	{
		$noslayer = $layer->childNodes;
		for ($i = 0; $i < $noslayer->length; $i++)
		{
			$tnome = $noslayer->item($i)->tagName;
			$tvalor = $noslayer->item($i)->nodeValue;
			if ($tnome == "Title")
			{$retorna[] = "<b>Titulo da camada: ".$tvalor."</b><br><br>Sub-camadas:<br><br>";}
			if ($tnome == "Layer")
			{
				$retorna[] = "<hr>";
				$sublayers = $noslayer->item($i)->childNodes;
				for ($j = 0; $j < $sublayers->length; $j++)
				{
					$tnome = $sublayers->item($j)->tagName;
					$tvalor = $sublayers->item($j)->nodeValue;
					if ($tnome != "Style")
					{
						$ns = "";
						if ($tnome == "Name")
						{$retorna[] = "<br><b>Nome: </b>".$tvalor;$tval = $tvalor;}
						if ($tnome == "Title")
						{
							$retorna[] = "<br><span style=color:red ><b>Titulo: </b>".$tvalor."</span><br>";
							$nomecamada = $tvalor;
						}
						if ($tnome == "Abstract")
						{$retorna[] = "<b>Resumo: </b>".$tvalor."<br><br>Estilos:<br><br>";}
					}
					else
					{
						$estilos = $sublayers->item($j)->childNodes;
						for ($k = 0; $k < $estilos->length; $k++)
						{
							$nomeestilo = "";
							$tituloestilo = "";
							if ($estilos->item($k)->tagName == "Name")
							{$nomeestilo = $estilos->item($k)->nodeValue;}
							if ($estilos->item($k)->tagName == "Title")
							{
								$tituloestilo = $estilos->item($k)->nodeValue;
								$nomecamada = $tituloestilo;
							}
							$tituloestilo = $estilos->item($k + 2)->nodeValue;
							if ($nomeestilo != "")
							{
								$retorna[] = "<input style='cursor:pointer' type=radio NAME='checks' onClick='seltema(\"estilo\",\"" . $tval . "\",\"\",\"" . $nomeestilo . "\",\"".$nomecamada."\",\"".$suporta."\")' value='" . $nomeestilo . "'/>" . $nomeestilo." <i>".$tituloestilo."</i><br>";
							}
						}
					}
				}
				if ($nums == 0)
				{
					if ($tituloestilo == "")
					{$tituloestilo = "default";}
					$retorna[] = "<input style='cursor:pointer' type=radio NAME='checks' onClick='seltema(\"tema\",\"" . $tval . "\",\"\",\"" . $tituloestilo . "\",\"".$nomecamada."\",\"".$suporta."\")' value='" . $tval . "'/>" . $nomeestilo." ".$tituloestilo."<br>";
				}
			}
		}
	}
	$retorna[] = "<br>Proj.:<input size=30 id=proj type=text class=digitar value='".implode(",",wms_srs($dom))."'/><br>";
	$retorna[] = "<br>Formatos imagem:<input size=30 id=formatos type=text class=digitar value='".implode(",",wms_formats($dom))."'/><br><br>";
	$retorna[] = "<br>Formatos info:<input size=30 id=formatosinfo type=text class=digitar value='".implode(",",wms_formatsinfo($dom))."'/><br><br>";
	$retorna[] = "<br>Versao:<input size=30 id=versao type=text class=digitar value='".(wms_version($dom))."'/><br><br>";
	$retorna[] = "<br>Suporta SLD:<input size=30 id=suportasld type=text class=digitar value='".$suporta."'/><br><br><br>";
	$cp->set_data(implode($retorna));
}

/*
function: temaswfs

Lista os temas de um web service WFS.

parameters:
$servico - Endereço do web service.

$cp - Objeto CPAINT.
*/
function temaswfs()
{
	global $servico,$cp;
	$teste = explode("=",$servico);
	if ( count($teste) > 1 ){$servico = $servico."&";}
	$wms_service_request = $servico . "REQUEST=GetCapabilities&SERVICE=WFS";
	# -------------------------------------------------------------
	# Test that the capabilites file has successfully downloaded.
	#
	if( !($wms_capabilities = file($wms_service_request)) ) {
		# Cannot download the capabilities file.
		$cp->set_data("Erro de acesso");
		return;
	}
	$wms_capabilities = implode("",$wms_capabilities);
	$dom = new DomDocument();
	$dom->loadXML($wms_capabilities);
	$services = $dom->getElementsByTagName("Service");
	foreach ($services as $service)
	{
		$vs = $service->getElementsByTagName("Name");
		$serv = "";
		foreach ($vs as $v)
		{$serv .= $v->nodeValue;}
	}	
	$layers = $dom->getElementsByTagName("FeatureType");
	foreach ($layers as $layer)
	{
		$vs = $layer->getElementsByTagName("Title");
		$temp1 = "";
		foreach ($vs as $v)
		{$temp1 .= $v->nodeValue;}
		
		$vs = $layer->getElementsByTagName("Abstract");
		$temp2 = "";
		foreach ($vs as $v)
		{$temp2 .= $v->nodeValue;}
		
		$vs = $layer->getElementsByTagName("SRS");
		$temp3 = array();
		foreach ($vs as $v)
		{$temp3[] = $v->nodeValue;}
		$temp3 = implode("#",$temp3);

		$vs = $layer->getElementsByTagName("Name");
		$temp = "";
		foreach ($vs as $v)
		{$temp .= $v->nodeValue;}
		$temp = "<input style='cursor:pointer' type=radio NAME='checks' onClick='seltema(\"" . $temp . "\",\"" .$temp1. "\",\"" . $temp3 . "\",\"" . $serv ."\")' /><span style=color:red >" . $temp . "</span><br>";		
		$retorno .= "<br>".$temp.$temp1."<br>".$temp2."<hr>";
	}
	$cp->set_data($retorno);
}
/*
function: xml2html

Converte caracteres XML em HTML.

parameters:

$str - Xml.
*/
function xml2html ( $str )
{
	$str = ereg_replace("&","&amp;",$str);
	$str = ereg_replace("<","&lt;",$str);
	$str = ereg_replace(">","&gt;<BR>",$str);
	return $str;
}
/*
function: wms_descricao

Retorna a descrição de um serviço (nó).
*/
function wms_descricao ( $dom,$xp )
{
	$xpath = new DOMXPath($dom);
	$query = $xp;
	$entries = $xpath->query($query);
	$n = "";
	foreach ($entries as $entry)
	{
		$n = $entry->nodeValue;
	}
	return $n;
}
/*
function: wms_descricaov

Retorna a descrição de um serviço (atributo).
*/
function wms_descricaov ( $dom,$xp,$attrib )
{
	$xpath = new DOMXPath($dom);
	$query = $xp;
	$entries = $xpath->query($query);
	$n = "";
	foreach ($entries as $entry)
	{
		$n = $entry->getAttribute($attrib);
	}
	return $n;
}
/*
function: wms_descricaon

Retorna a descrição de um serviço (filho de um nó).
*/
function wms_descricaon ( $dom,$xp,$n ) {
	$ctx = xpath_new_context($dom);
	$xpnode = xpath_eval($ctx,$xp);
	$dtnode = $xpnode->nodeset[$n]->first_child();
	return $dtnode->content;
}
/*
function: wms_title

Retorna o título de um WMS.
*/
function wms_title ( $dom ) {
	#
	# Read the WMS service title and return it as text.
	#
	$xpath = new DOMXPath($dom);
	$query = '//WMT_MS_Capabilities/Service/Title';
	$entries = $xpath->query($query);
	foreach ($entries as $entry){$nomeserv = $entry->nodeValue;}
	return $nomeserv;
}
/*
function: wms_onlineresource

Retorna o recurso on-line de um WMS.
*/
function wms_onlineresource ( $dom ) {
	#
	# Read the WMS online resource URL and return it as text.
	#
	$xp = "/WMT_MS_Capabilities/Service/OnlineResource";
	$ctx = xpath_new_context($dom);
	$xpnode = xpath_eval($ctx,$xp);
	return $xpnode->nodeset[0]->get_attribute("href");
}
/*
function: wms_formats

Retorna os formatos de imagem de um WMS.
*/
function wms_formats ( $dom )
{
	$xpath = new DOMXPath($dom);
	$query = '//WMT_MS_Capabilities/Capability/Request/GetMap/Format';
	$entries = $xpath->query($query);
	$arr = array();
	foreach ($entries as $entry)
	{
		$arr[] = $entry->nodeValue;
	}
	return $arr;
}
/*
function: wms_formatsinfo

Retorna os formatos existentes de retorno da opção getfeatureinfo.
*/
function wms_formatsinfo ( $dom )
{
	$xpath = new DOMXPath($dom);
	$query = '//WMT_MS_Capabilities/Capability/Request/GetFeatureInfo/Format';
	$entries = $xpath->query($query);
	$arr = array();
	foreach ($entries as $entry)
	{
		$arr[] = $entry->nodeValue;
	}
	return $arr;
}
/*
function: wms_estilos

Retorna os estilos de um WMS.
*/
function wms_estilos ( $dom ) {
	#
	# Read the WMS image formats and return them as an array.
	#
	//$xp = "/Style";
	//$ctx = xpath_new_context($dom);
	//$xpnode = xpath_eval($ctx,$xp);
	//return $xpnode->nodeset;
	$return = $dom->getElementsByTagName("Style");

}
/*
function: wms_exceptions

Retorna as exceptions de um WMS.
*/
function wms_exceptions ( $dom ) {
	#
	# Read the WMS exception formats and return them as an array.
	#
	$xp = "/WMT_MS_Capabilities/Capability/Exception/Format";
	$ctx = xpath_new_context($dom);
	$xpnode = xpath_eval($ctx,$xp);
	$arr = array();
	for( $i = 0; $i < sizeof($xpnode->nodeset); $i++ ) {
		$dtnode = $xpnode->nodeset[0]->first_child();
		array_push($arr,$dtnode->content);
	}
	return $arr;
}
/*
function: wms_version

Retorna a versao.
*/
function wms_version ( $dom )
{
	$n = $dom->getElementsByTagName('WMT_MS_Capabilities');
	$params = $dom->getElementsByTagName('*');

	foreach ($params as $param) {
		$v = $param -> getAttribute('version');
		break;
	}
	return $v;
}
/*
function: wms_layers

Retorna os layers de um WMS.
*/
function wms_layers ( $dom ) {
	#
	# Read the WMS first level layers and return an
	# array of nodes.
	#
	$xpath = new DOMXPath($dom);
	$query = '//WMT_MS_Capabilities/Capability/Layer/Layer/Layer';
	$entries = $xpath->query($query);
	if ($entries->length == 0)
	{
		$query = '//WMT_MS_Capabilities/Capability/Layer';
		$entries = $xpath->query($query);		
	}
	else
	{
		$query = '//WMT_MS_Capabilities/Capability/Layer/Layer';
		$entries = $xpath->query($query);		
	}
	return $entries;
}
/*
function: wms_xpnode2content

Read the content child node of an element tag node WMS.
*/
function wms_xpnode2content( $xp_node ) {
	#
	# Read the content child node of an element tag
	# node.
	#
	$content = "";
	if( $xp_node->nodeset[0] ) {
		$node = $xp_node->nodeset[0]->first_child();
		$content = $node->content;
	}
	return $content;
}
/*
function: wms_srs

Retorna os SRSs WMS.
*/
function wms_srs( $dom )
{
	$xpath = new DOMXPath($dom);
	$query = '//WMT_MS_Capabilities/Capability/Layer/SRS';
	$entries = $xpath->query($query);
	$srs = "";
	//utiliza apenas os epsg do Brasil
	$single = array();
	foreach ($entries as $entry)
	{
		$arr[] = $entry->nodeValue;
		if ($entry->nodeValue == "EPSG:4326")
		{$single[] = "EPSG:4326";}
		if ($entry->nodeValue == "EPSG:4291")
		{$single[] = "EPSG:4291";}
	}
	if (count($single) > 0)
	{$arr = $single;}
	return $arr;
}
/*
function: wms_bbox

Retorna o BBOX de um WMS.
*/
function wms_bbox( $dom )
{
	$xpath = new DOMXPath($dom);
	$query = '//WMT_MS_Capabilities/Capability/Layer/LatLonBoundingBox';
	$entries = $xpath->query($query);
	foreach ($entries as $entry){$bbox = $entry->nodeValue;}
	if ($bbox == '-1,-1,-1,-1')
	{return '-180,-90,180,90';}
	else
	{return wms_bbox2txt($bbox);}
}
/*
function: wms_bbox2txt

Convert a BoundingBox node into a text string de um wms.
*/
function wms_bbox2txt( $node ) {
	#
	# Convert a BoundingBox node into a text string.
	#
	if( $node ) {
		$txt .= 1 * $node->get_attribute("minx");
		$txt .= ",";
		$txt .= 1 * $node->get_attribute("miny");
		$txt .= ",";
		$txt .= 1 * $node->get_attribute("maxx");
		$txt .= ",";
		$txt .= 1 * $node->get_attribute("maxy");
	}
	else {
		$txt = "-180,-90,180,90";
	}
	return $txt;
}
/*
function: wms_layer2html

Convert a Layer node into an HTML representation wms.
*/
function wms_layer2html( $node, $tipo , $layer ) {
	#
	# Convert a Layer node into an HTML representation.
	#
	$ctx = xpath_new_context($node);
	$xp_title  = xpath_eval($ctx,"/Title");
	$xp_name   = xpath_eval($ctx,"/Name");
	if (wms_xpnode2content($xp_name) == ""){$xp_name = xpath_eval($ctx,"/name");}
	$xp_srs    = xpath_eval($ctx,"/SRS");
	$xp_llbbox = xpath_eval($ctx,"/LatLonBoundingBox");
	$xp_bbox   = xpath_eval($ctx,"/BoundingBox");
	$txt_title = wms_xpnode2content($xp_title);
	$txt_name  = wms_xpnode2content($xp_name);
	$txt_srs   = strtoupper(wms_xpnode2content($xp_srs));
	$node_llbbox = $xp_llbbox->nodeset[0];
	$node_bbox   = $xp_bbox->nodeset[0];
	$queryable = 0;
	if ( $node->get_attribute("queryable") ) {
		$queryable = 1;
	}
	$opaque = 0;
	if ( $node->get_attribute("opaque") ) {
		$opaque = 1;
	}
	//legenda
	$xp_legenda   = xpath_eval($ctx,"/LegendURL/OnlineResource");
	$nodelegenda = $xp_legenda->nodeset[0];
	if($nodelegenda)
	{  $legenda = $nodelegenda->get_attribute("href");}

	$html  = "<INPUT TYPE='radio' NAME='checks' VALUE='$txt_name' onClick='toggle(event,\"$tipo\",\"$layer\",\"$legenda\",\"$txt_title\")'>";
	$html .= "&nbsp;&nbsp;";
	$html .= $txt_title . "\n";
	$html .= wms_hidden("bbox_$txt_name", wms_bbox2txt($node_bbox));
	$html .= wms_hidden("llbox_$txt_name", wms_bbox2txt($node_llbbox));
	$html .= wms_hidden("srs_$txt_name", $txt_srs);
	$html .= wms_hidden("query_$txt_name", $queryable );
	$html .= wms_hidden("opaque_$txt_name", $opaque );
	$html .= "<BR>";
	return $html;
}
/*
function: wms_layer3html

Convert a Layer node into an HTML representation sem radio.
*/
function wms_layer3html( $node ) {
	#
	# Convert a Layer node into an HTML representation sem radio.
	#
	$ctx = xpath_new_context($node);
	$xp_title  = xpath_eval($ctx,"/Title");
	$xp_abs  = xpath_eval($ctx,"/Abstract");
	$txt_title = wms_xpnode2content($xp_title);
	$txt_abs = wms_xpnode2content($xp_abs);
	$html .= "<b>".$txt_title . "</b><i style='color:gray'>" . "-" . $txt_abs . "</i>\n";
	$html .= "<BR>";
	return $html;
}
/*
function: wms_layer4html

Convert a Layer into an HTML WMS.
*/
function wms_layer4html( $layer ) {
	$estilos = wms_estilos($layer);
	if (count($estilos) > 0)
	{
		$ctxl = xpath_new_context($layer);
		$xp_namel   = xpath_eval($ctxl,"/Name");
		if (wms_xpnode2content($xp_namel) == ""){$xp_namel = xpath_eval($ctxl,"/name");}
		$txt_namel  = wms_xpnode2content($xp_namel);
		$html .= wms_layer3html($layer);
		foreach ($estilos as $estilo)
		{
			$html .= wms_layer2html($estilo,"estilo",$txt_namel);
		}
	}
	else
	{
		$html .= wms_layer2html($layer,"tema","");
	}
	return $html;
}
?>