[GRASS-SVN] r31329 - grass/branches/develbranch_6/scripts/r.in.wms

svn_grass at osgeo.org svn_grass at osgeo.org
Tue May 13 08:03:33 EDT 2008


Author: hamish
Date: 2008-05-13 08:03:32 -0400 (Tue, 13 May 2008)
New Revision: 31329

Modified:
   grass/branches/develbranch_6/scripts/r.in.wms/r.in.gdalwarp
   grass/branches/develbranch_6/scripts/r.in.wms/r.in.wms
   grass/branches/develbranch_6/scripts/r.in.wms/wms.download
   grass/branches/develbranch_6/scripts/r.in.wms/wms.request
Log:
* add -g flag for braindead servers which can't handle POST data
* check to see if RGB image has an alpha layer before using it (jpeg)
* parse Channel list properly
* mention better method: gdal_merge.py
* add some more debug msgs


Modified: grass/branches/develbranch_6/scripts/r.in.wms/r.in.gdalwarp
===================================================================
--- grass/branches/develbranch_6/scripts/r.in.wms/r.in.gdalwarp	2008-05-13 07:06:24 UTC (rev 31328)
+++ grass/branches/develbranch_6/scripts/r.in.wms/r.in.gdalwarp	2008-05-13 12:03:32 UTC (rev 31329)
@@ -80,6 +80,8 @@
     exec g.parser "$0" "$@"
 fi
 
+g.message -d "[r.in.gdalwarp]"
+
 #### setup temporary file
 TMP="`g.tempfile pid=$$`"
 if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
@@ -171,6 +173,11 @@
 	else
 		ALPHALAYER=${TMPMAPNAME}.alpha
 	fi
+	# test to see if the alpha map exists
+	g.findfile element=cell file="$ALPHALAYER" > /dev/null
+	if [ $? -ne 0 ] ; then
+	    ALPHALAYER=""
+	fi
 
 	# Calculate the new maps:
 	for SUFFIX in $CHANNEL_SUFFIXES ; do
@@ -185,9 +192,16 @@
 		    continue
 		fi
 
-		# Use alpha channel for nulls:
-		GRASS_VERBOSE=1 \
-		  r.mapcalc "${MAP}${sfx} = if( $ALPHALAYER, ${TMPMAPNAME}${sfx}, null() )"
+		g.message -d message="alpha=[$ALPHALAYER]  MAPsfx=[${MAP}${sfx}]  tmpname=[${TMPMAPNAME}${sfx}]"
+		if [ -n "$ALPHALAYER" ] ; then
+		    # Use alpha channel for nulls:
+# problem: I've seen a map where alpha was 1-255; 1 being transparent. what to do?
+#    (Geosci Australia Gold layer, format=tiff)
+		    GRASS_VERBOSE=1 \
+		      r.mapcalc "${MAP}${sfx} = if( $ALPHALAYER, ${TMPMAPNAME}${sfx}, null() )"
+		else
+		    g.copy rast="${TMPMAPNAME}${sfx}","${MAP}${sfx}" --quiet
+		fi		  
 
 		# Copy the color tables:
 		r.colors map=${MAP}${sfx} rast=${TMPMAPNAME}${sfx} --quiet
@@ -210,8 +224,10 @@
 	fi
 
 	# Remove the old channels:
-	CHANNEL_LIST_COMMA=`echo "$CHANNEL_LIST" | sed "s/ /,/g"`
+	CHANNEL_LIST_COMMA=`echo "$CHANNEL_LIST" | tr '\n' ',' | sed -e 's/ /,/g' -e 's/,$//'`
+	g.message -d message="CHANNEL_LIST_COMMA=[$CHANNEL_LIST_COMMA]"
 	g.remove rast="$CHANNEL_LIST_COMMA" --quiet
+
 }
 
 nowarpimport () {
@@ -357,6 +373,8 @@
 	    #   different color tables so patches output end up all freaky.
 	    #	r.mapcalc r#,g#,b# manual patching + r.composite?
 	    #	or d.out.file + r.in.png + r.region?
+	    # *** there is a GDAL utility to do this: gdal_merge.py
+	    #       http://www.gdal.org/gdal_merge.html
 
 	    #r.patch input="$MAPLIST" output="${GIS_OPT_OUTPUT}"
 	    IFS=" "

Modified: grass/branches/develbranch_6/scripts/r.in.wms/r.in.wms
===================================================================
--- grass/branches/develbranch_6/scripts/r.in.wms/r.in.wms	2008-05-13 07:06:24 UTC (rev 31328)
+++ grass/branches/develbranch_6/scripts/r.in.wms/r.in.wms	2008-05-13 12:03:32 UTC (rev 31329)
@@ -29,24 +29,30 @@
 #%end
 #%flag
 #% key: o
-#% description: Don't request transparent data.
+#% description: Don't request transparent data
 #% guisection: Request
 #%end
 #%flag
 #% key: c
-#% description: Clean existing data out of download directory.
+#% description: Clean existing data out of download directory
 #% guisection: Download
 #%end
 #%flag
 #% key: k
-#% description: Keep band numbers instead of using band color names.
+#% description: Keep band numbers instead of using band color names
 #% guisection: Import
 #%end
 #%flag
 #% key: p
-#% description: Don't reproject the data, just patch it.
+#% description: Don't reproject the data, just patch it
 #% guisection: Import
 #%end
+#%flag
+#% key: g
+#% label: Use GET method instead of POST data method
+#% description: This may be needed to connect to servers which lack POST capability
+#% guisection: Request
+#%end
 #%option
 #% key: output
 #% type: string
@@ -317,37 +323,49 @@
 listLayers() {
 
 	CAPABILITIES_FILE="${TMP}capabilities.xml"
-    
+
 	STRING="service=WMS&request=GetCapabilities&${GIS_OPT_WMSQUERY}";
 	g.message -d message="POST-data: [$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 -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\";"
-	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\""
-	fi
-	g.message -v message=""
 
-	if [ ! -e "$CAPABILITIES_FILE" ] ; then
-	    g.message -e "Downloading XML file"
-	    \rm "$TMP"
-	    exit 1
+	if [ "$GIS_FLAG_G" -eq 0 ] ; then
+	    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\";"
+	    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\""
+	    fi
+	    g.message -v message=""
+
+	    if [ ! -e "$CAPABILITIES_FILE" ] ; then
+		g.message -e "Downloading XML file"
+		\rm "$TMP"
+		exit 1
+	    fi
+
+	    # work-around for brain-dead WMSs which want POST-data as part of the GET URL
+	    #   (allowed by OGC WMS def S6.3.4)
+	    if [ `wc -c < "$CAPABILITIES_FILE"` -eq 0 ] ; then
+		g.message -w "Downloaded XML file was empty -- trying another method"
+		GIS_FLAG_G=1
+	    fi
 	fi
 
-	# work-around for brain-dead WMSs which want POST-data as part of the GET URL (allowed by OGC WMS def S6.3.4)
-	if [ `wc -c < "$CAPABILITIES_FILE"` -eq 0 ] ; then
-	    g.message -w "Downloaded XML file was empty -- trying another method"
+	if  [ "$GIS_FLAG_G" -eq 1 ] ; then
 	    g.message -v message=""
 	    if [ "$USE_WGET" ] ; then
-		wget $GIS_OPT_WGETOPTIONS "${GIS_OPT_MAPSERVER}${STRING}" -O "$CAPABILITIES_FILE";
+		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}"
+		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=""
@@ -484,6 +502,7 @@
 	fi
 fi
 
+addflag DOWNLOAD g ${GIS_FLAG_G}
 addargument DOWNLOAD requestfile "${REQUESTFILE}"
 addargument DOWNLOAD wgetoptions "${GIS_OPT_WGETOPTIONS}"
 addargument DOWNLOAD curloptions "${GIS_OPT_CURLOPTIONS}"

Modified: grass/branches/develbranch_6/scripts/r.in.wms/wms.download
===================================================================
--- grass/branches/develbranch_6/scripts/r.in.wms/wms.download	2008-05-13 07:06:24 UTC (rev 31328)
+++ grass/branches/develbranch_6/scripts/r.in.wms/wms.download	2008-05-13 12:03:32 UTC (rev 31329)
@@ -19,6 +19,11 @@
 #%  description: Downloads data from servers.
 #%  keywords: wms
 #%End
+#%flag
+#% key: g
+#% label: Use GET method instead of POST data method
+#% description: This may be needed to connect to servers which lack POST capability
+#%end
 #%option
 #% key: requestfile
 #% type: string
@@ -56,6 +61,8 @@
   exec g.parser "$0" "$@"
 fi
 
+g.message -d "[wms.download]"
+
 #### setup temporary file
 TMP="`g.tempfile pid=$$`"
 if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
@@ -110,13 +117,17 @@
   g.message "Downloading tiles"
 
   # init POST-data vs. GET URL method variable
-  POST_DATA_OK=1
+  if [ "$GIS_FLAG_G" -eq 0 ] ; then
+     POST_DATA_OK=1
+  else
+     POST_DATA_OK=0
+  fi
 
   CONTENTS=`cat "${REQUESTFILE}"`
 
   NUMBER_OF_TILES=0
   for line in $CONTENTS ; do
-	g.message -d message="wget command: [$line]"
+	g.message -d message="wget command: [$line]" debug=2
 	eval "$line"
 
 	emptyness=`file "$OUTPUT_FILE" | grep empty$`
@@ -144,7 +155,7 @@
 #Get the data from the WMS server
 GetData() {
    g.message "Downloading data"
-   g.message -v message="Requesting Data from ${SERVER}:"
+   g.message -v message="Requesting Data from <${SERVER}:>"
    g.message -v message="$STRING"
 
    if [ "$POST_DATA_OK" -eq 1 ] ; then

Modified: grass/branches/develbranch_6/scripts/r.in.wms/wms.request
===================================================================
--- grass/branches/develbranch_6/scripts/r.in.wms/wms.request	2008-05-13 07:06:24 UTC (rev 31328)
+++ grass/branches/develbranch_6/scripts/r.in.wms/wms.request	2008-05-13 12:03:32 UTC (rev 31329)
@@ -130,6 +130,8 @@
   exec g.parser "$0" "$@"
 fi
 
+g.message -d "[wms.request]"
+
 SED="sed"
 GREP="grep"
 # check if we have sed



More information about the grass-commit mailing list