[GRASS-SVN] r30457 - grass/trunk/scripts/r.in.wms

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 4 03:36:19 EST 2008


Author: hamish
Date: 2008-03-04 03:36:17 -0500 (Tue, 04 Mar 2008)
New Revision: 30457

Modified:
   grass/trunk/scripts/r.in.wms/r.in.wms
Log:
work-around for broken WMS which wants post-data in the URL not as post-data (yeah, that means you ESRI: NOAA's ENC server)

Modified: grass/trunk/scripts/r.in.wms/r.in.wms
===================================================================
--- grass/trunk/scripts/r.in.wms/r.in.wms	2008-03-04 05:47:57 UTC (rev 30456)
+++ grass/trunk/scripts/r.in.wms/r.in.wms	2008-03-04 08:36:17 UTC (rev 30457)
@@ -219,6 +219,19 @@
     fi
 fi
 
+# turn verbose mode on if requested either way
+if [ "$GIS_OPT_V" -lt 2 ] ; then
+   if [ -n "$GRASS_VERBOSE" ] && [ "$GRASS_VERBOSE" -ge 2 ] ; then
+      GIS_OPT_V=2
+   fi
+else
+   g.message -w "The verbosity option is superseded. Use --verbose instead"
+   if [ -n "$GRASS_VERBOSE" ] && [ "$GRASS_VERBOSE" -lt 2 ] ; then
+      GRASS_VERBOSE=2
+   fi
+fi
+
+
 # Remember the intial field seperator
 defaultIFS="$IFS"
 
@@ -235,7 +248,7 @@
 message () {
 	if [ $1 -lt $GIS_OPT_V ] ; then
 		shift
-		echo "$@"  
+		echo "$@" 1>&2
 	fi
 }
 
@@ -300,18 +313,53 @@
 	CAPABILITIES_FILE="${TMP}capabilities.xml"
     
 	STRING="service=WMS&request=GetCapabilities&${GIS_OPT_WMSQUERY}";
+	g.message -d message="POST: [$STRING]"
 
 	### wget or curl the XML and grep the lines with layer names
-	g.message message="List of layers for server ${GIS_OPT_MAPSERVER}:"
+	g.message message="List of layers for server <$GIS_OPT_MAPSERVER>:"
+	g.message -v message=""
 	if [ "$USE_WGET" ] ; then
 	    wget $GIS_OPT_WGETOPTIONS --post-data="${STRING}" "$GIS_OPT_MAPSERVER" -O "$CAPABILITIES_FILE";
-	    message 1 wget $GIS_OPT_WGETOPTIONS --post-data="${STRING}" "$GIS_OPT_MAPSERVER" -O "$CAPABILITIES_FILE";
+	    message 1 "wget $GIS_OPT_WGETOPTIONS --post-data=\"${STRING}\" \"$GIS_OPT_MAPSERVER\" -O \"$CAPABILITIES_FILE\";"
 	else
 	    curl $GIS_OPT_CURLOPTIONS -o "$CAPABILITIES_FILE" -d "${STRING}" "$GIS_OPT_MAPSERVER"
-	    message 1 curl $GIS_OPT_CURLOPTIONS -o "$CAPABILITIES_FILE" -d "${STRING}" "$GIS_OPT_MAPSERVER"
+	    message 1 "curl $GIS_OPT_CURLOPTIONS -o \"$CAPABILITIES_FILE\" -d \"${STRING}\" \"$GIS_OPT_MAPSERVER\""
 	fi
+	g.message -v message=""
 
-	# use xml2
+	if [ ! -e "$CAPABILITIES_FILE" ] ; then
+	    g.message -e "Downloading XML file"
+	    \rm "$TMP"
+	    exit 1
+	fi
+
+	# work-around for broken WMS which wants post-data in the URL line
+	if [ `wc -c < "$CAPABILITIES_FILE"` -eq 0 ] ; then
+	    g.message -w "Downloaded XML file was empty -- trying another method"
+	    g.message -v message=""
+	    if [ "$USE_WGET" ] ; then
+		wget $GIS_OPT_WGETOPTIONS "${GIS_OPT_MAPSERVER}${STRING}" -O "$CAPABILITIES_FILE";
+		message 1 "wget $GIS_OPT_WGETOPTIONS \"${GIS_OPT_MAPSERVER}${STRING}\" -O \"$CAPABILITIES_FILE\";"
+	    else
+		curl $GIS_OPT_CURLOPTIONS -o "$CAPABILITIES_FILE" "${GIS_OPT_MAPSERVER}${STRING}"
+		message 1 "curl $GIS_OPT_CURLOPTIONS -o \"$CAPABILITIES_FILE\" \"${GIS_OPT_MAPSERVER}${STRING}\""
+	    fi
+	    g.message -v message=""
+	fi
+
+	if [ ! -e "$CAPABILITIES_FILE" ] ; then
+	    g.message -e "Downloading XML file"
+	    \rm "$TMP"
+	    exit 1
+	fi
+
+	if [ `wc -c < "$CAPABILITIES_FILE"` -eq 0 ] ; then
+	     g.message -e "Downloaded XML file was empty"
+	     \rm -f "$CAPABILITIES_FILE" "$TMP"
+	     exit 1
+	fi
+
+	# use xml2 if we have it
 	if [ -x "`which xml2`" ] ; then
 		cat "$CAPABILITIES_FILE" | xml2 | \
 		  grep "Layer/SRS=\|Layer/Name=\|Layer/Title=\|Style/Name=\|Style/Title=\|Layer/Abstract=" | \



More information about the grass-commit mailing list