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
|
#!/usr/bin/perl
use warnings;
#
# Copyright (C) 2000-2023 The Xastir Group
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# Run this as "./wms.pl URL", where URL = a "GetCapabilities" link, but
# with a backslash added before each '&' character. The script will
# download the XML file at that URL and parse it. It will then attempt
# to find the map layer names and list them at the end of the run.
#my $xml_text = `wget -O - "http://geogratis.gc.ca/maps/CBMT?service=wms\&version=1.1.1\&request\=GetCapabilities"`;
#my $xml_text = `wget -O - "http://nowcoast.noaa.gov/arcgis/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer/WMSServer?request=GetCapabilities\&service=WMS\&version=1.3.0"`;
#
# Once you have the map layer names it is relatively easy to construct a
# .geo file for Xastir that uses one of those map layers. Here's an example
# from README.MAPS. Both lines are required in the .geo file:
# -----------------------
# WMSSERVER
# URL http://geogratis.gc.ca/maps/CBMT?VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&SRS=EPSG:4326&LAYERS=Sub_regional&STYLES=&FORMAT=image/png&BGCOLOR=0xFFFFFF&TRANSPARENT=FALSE
# -----------------------
#
#Here's the info from Dumper that we're interested in (Name):
#$VAR1 = {
# 'Capability' => [
# {
# 'Layer' => [
# {
# 'Layer' => [
# {
# 'Name' => [
# 'National'
#
# -or-
#
#$VAR1 = {
# 'Capability' => {
# 'Layer' => {
# 'Layer' => {
# 'Layer' => [
# {
# 'Name' => '1',
use strict;
use XML::Simple;
use Getopt::Std;
use Data::Dumper;
use Scalar::Util 'reftype';
my $url;
$url = shift;
if (!defined $url || $url eq "") {
print "Please enter GetCapabilities URL with '\' before each '&' character.\n";
$url = <>;
}
my $xml_text= `wget -O - $url`;
my $xml = XMLin( $xml_text );
print Dumper($xml);
print "\n----------------------------------------------------------\n\n";
my $version = $url;
$version =~ s/.*version=(\d+\.\d+\.\d+).*/$1/;
if ($version =~ /\d+\.\d+\.\d+/) {
}
else {
$version = "1.0.0";
}
my $url_filtered = $url;
$url_filtered =~ s/\\//g; # Get rid of backslashes
$url_filtered =~ s/(.*\?).*/$1/; # Remove everything after '?'
$url_filtered = "URL " . $url_filtered . "SERVICE=wms&VERSION=$version&REQUEST=GetMap&SRS=EPSG:4326&FORMAT=image/png&BGCOLOR=0xFFFFFF&TRANSPARENT=false&STYLES=&LAYERS=";
print "POSSIBLE .GEO FILE CONTENTS:\n\n";
my $ii;
my $reftype = reftype $xml->{Capability}->{Layer}->{Layer};
if ( (defined $reftype) && ($reftype eq 'ARRAY') ) {
for ($ii = 0; $ii < 15; $ii++) {
if ( defined($xml->{Capability}->{Layer}->{Layer}->[$ii]->{Name}) ) {
print "-----\n";
print "WMSSERVER\n";
print $url_filtered;
print "$xml->{Capability}->{Layer}->{Layer}->[$ii]->{Name}\n";
}
}
}
if ( (defined $reftype) && ($reftype eq 'HASH') ) {
for ($ii = 0; $ii < 15; $ii++) {
if ( defined($xml->{Capability}->{Layer}->{Layer}->{Layer}->[$ii]->{Name}) ) {
print "-----\n";
print "\nWMSSERVER\n";
print $url_filtered;
print "$xml->{Capability}->{Layer}->{Layer}->{Layer}->[$ii]->{Name}\n";
}
}
}
|