[GRASS-SVN] r30637 -
grass/branches/releasebranch_6_3/scripts/r.in.wms
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Mar 19 07:02:14 EDT 2008
Author: hamish
Date: 2008-03-19 07:02:14 -0400 (Wed, 19 Mar 2008)
New Revision: 30637
Modified:
grass/branches/releasebranch_6_3/scripts/r.in.wms/r.in.wms
grass/branches/releasebranch_6_3/scripts/r.in.wms/wms.download
Log:
really merge from HEAD, not from local experiment
Modified: grass/branches/releasebranch_6_3/scripts/r.in.wms/r.in.wms
===================================================================
--- grass/branches/releasebranch_6_3/scripts/r.in.wms/r.in.wms 2008-03-19 10:58:26 UTC (rev 30636)
+++ grass/branches/releasebranch_6_3/scripts/r.in.wms/r.in.wms 2008-03-19 11:02:14 UTC (rev 30637)
@@ -29,29 +29,24 @@
#%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
-#% description: Use alternative GET method (try if you have download problems)
-#% guisection: Request
-#%end
#%option
#% key: output
#% type: string
@@ -316,151 +311,106 @@
######################
-# name: parse_capabilities
-# purpose: attempt parse XML capabilities file
-parse_capabilities() {
- # 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=" | \
- sed -e "s/.*Layer\\/Name=/LAYER: /" \
- -e "s/.*Layer\\/SRS=/ SRS: /" \
- -e "s/.*Layer\\/Title=/ Title: /" \
- -e "s/.*Layer\\/Abstract=/ |/" \
- -e "s/.*Layer\\/Style\\/Name=/ STYLE: /" \
- -e "s/.*Layer\\/Style\\/Title=/ Style title: /" \
- > "${TMP}capabilities.txt"
-
- else : # xml2 is not available
- g.message -w "The 'xml2' program was not found. Proceeding with internal XML parsing which may not be as reliable."
- sed -e "s/<Layer/\n<Layer/g" \
- -e "s/<Name>/\n<Name>/g" \
- -e "s/<Style>/\n<Style>/g" \
- -e "s/<Title>/\n<Title>/g" \
- "$CAPABILITIES_FILE" | \
- grep "Name\|Title\|Style\|Layer" | \
- sed -e "s/<Layer .*>/LAYER:/" \
- -e "s/<\/Layer.*>//" \
- -e "s/<Name>\s*\([^<]*\)/~\1~/g" \
- -e "s/<\/Name>\n\?//g" \
- -e "s/<Style>\n*\s*\(\w*\)/Style: \1/" \
- -e "s/<\/Style>//" \
- -e "s/<Title>\(.*\)<\/Title>/\t --\1 /" \
- -e "s/<\/Title>//" \
- -e "s/<\/*.*\/*\/*>//" \
- > "${TMP}capabilities.txt"
- fi
-
- if [ `wc -l < "${TMP}capabilities.txt"` -eq 0 ] ; then
- if [ $GIS_FLAG_G -eq 0 ] ; then
- g.message -w "Problem parsing XML file using POST-data method"
- GIS_FLAG_G=1
- fi
- fi
-}
-
-
-######################
-# name: dl_cap_post
-# purpose: attempt capabilities download using POST-data
-dl_cap_post() {
- ### 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
- fi
- if [ `wc -c < "$CAPABILITIES_FILE"` -eq 0 ] ; then
- g.message -e "Downloaded XML file was empty"
- \rm -f "$CAPABILITIES_FILE" "$TMP"
- GIS_FLAG_G=1
- fi
-}
-
-
-######################
-# name: dl_cap_get
-# purpose: attempt capabilities download using a single GET
-dl_cap_get() {
- 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=""
-
- 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
-}
-
-
-######################
# name: listLayers
# purpose: list layers available from this server
listLayers() {
CAPABILITIES_FILE="${TMP}capabilities.xml"
-
+
STRING="service=WMS&request=GetCapabilities&${GIS_OPT_WMSQUERY}";
g.message -d message="POST-data: [$STRING]"
- if [ $GIS_FLAG_G -eq 0 ] ; then
- dl_cap_post
- parse_capabilities
+ ### 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 [ $GIS_FLAG_G -eq 1 ] ; then
- g.message -w "Problem downloading XML -- trying all-in-one GET method"
+ 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"
+ 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
- # work-around for brain-dead WMSs which want POST-data as part of the GET URL
- # (that is allowed by OGC WMS def Sec 6.3.4)
- if [ $GIS_FLAG_G -eq 1 ] ; then
- dl_cap_get
- parse_capabilities
+ 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=" | \
+ sed -e "s/.*Layer\\/Name=/LAYER: /" \
+ -e "s/.*Layer\\/SRS=/ SRS: /" \
+ -e "s/.*Layer\\/Title=/ Title: /" \
+ -e "s/.*Layer\\/Abstract=/ |/" \
+ -e "s/.*Layer\\/Style\\/Name=/ STYLE: /" \
+ -e "s/.*Layer\\/Style\\/Title=/ Style title: /" \
+ > "${TMP}capabilities.txt"
+
+ else : # xml2 is not available
+ g.message -w "The 'xml2' program was not found. Proceeding with internal XML parsing which may not be as reliable."
+ sed -e "s/<Layer/\n<Layer/g" \
+ -e "s/<Name>/\n<Name>/g" \
+ -e "s/<Style>/\n<Style>/g" \
+ -e "s/<Title>/\n<Title>/g" \
+ "$CAPABILITIES_FILE" | \
+ grep "Name\|Title\|Style\|Layer" | \
+ sed -e "s/<Layer .*>/LAYER:/" \
+ -e "s/<\/Layer.*>//" \
+ -e "s/<Name>\s*\([^<]*\)/~\1~/g" \
+ -e "s/<\/Name>\n\?//g" \
+ -e "s/<Style>\n*\s*\(\w*\)/Style: \1/" \
+ -e "s/<\/Style>//" \
+ -e "s/<Title>\(.*\)<\/Title>/\t --\1 /" \
+ -e "s/<\/Title>//" \
+ -e "s/<\/*.*\/*\/*>//" \
+ > "${TMP}capabilities.txt"
+ fi
+
if [ `wc -l < "${TMP}capabilities.txt"` -eq 0 ] ; then
g.message message=""
g.message -e "Parsing XML file"
g.message message="------------------------"
cat "$CAPABILITIES_FILE"
- EXITVAL=1
else
- # we think it worked, output capabilities
cat "${TMP}capabilities.txt"
- EXITVAL=0
fi
g.message message=""
if [ -e "$CAPABILITIES_FILE" ] ; then
\rm -f "$CAPABILITIES_FILE" "${TMP}capabilities.txt" "$TMP"
fi
-
- exit $EXITVAL
+ exit 1;
}
@@ -534,7 +484,6 @@
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/releasebranch_6_3/scripts/r.in.wms/wms.download
===================================================================
--- grass/branches/releasebranch_6_3/scripts/r.in.wms/wms.download 2008-03-19 10:58:26 UTC (rev 30636)
+++ grass/branches/releasebranch_6_3/scripts/r.in.wms/wms.download 2008-03-19 11:02:14 UTC (rev 30637)
@@ -46,10 +46,6 @@
#% description: Verbosity level
#% answer: 1
#%end
-#%Flag
-#% key: g
-#% description: Use alternative GET method (try if you have download problems)
-#%end
if [ -z "$GISBASE" ] ; then
echo "You must be in GRASS GIS to run this program." 1>&2
@@ -114,11 +110,7 @@
g.message "Downloading tiles"
# init POST-data vs. GET URL method variable
- if [ $GIS_FLAG_G -eq 0 ] ; then
- POST_DATA_OK=1
- else
- POST_DATA_OK=0
- fi
+ POST_DATA_OK=1
CONTENTS=`cat "${REQUESTFILE}"`
More information about the grass-commit
mailing list