[GRASS-SVN] r52054 - in grass-addons/grass6/raster: . r.in.onearth
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 12 20:11:30 PDT 2012
Author: hamish
Date: 2012-06-12 20:11:30 -0700 (Tue, 12 Jun 2012)
New Revision: 52054
Added:
grass-addons/grass6/raster/r.in.onearth/
grass-addons/grass6/raster/r.in.onearth/Makefile
grass-addons/grass6/raster/r.in.onearth/README
grass-addons/grass6/raster/r.in.onearth/description.html
grass-addons/grass6/raster/r.in.onearth/r.in.onearth
Log:
move r.in.onearth by Soeren and Markus N into svn
Added: grass-addons/grass6/raster/r.in.onearth/Makefile
===================================================================
--- grass-addons/grass6/raster/r.in.onearth/Makefile (rev 0)
+++ grass-addons/grass6/raster/r.in.onearth/Makefile 2012-06-13 03:11:30 UTC (rev 52054)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.in.onearth
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Property changes on: grass-addons/grass6/raster/r.in.onearth/Makefile
___________________________________________________________________
Added: svn:mime-type
+ text/x-makefile
Added: svn:eol-style
+ native
Added: grass-addons/grass6/raster/r.in.onearth/README
===================================================================
--- grass-addons/grass6/raster/r.in.onearth/README (rev 0)
+++ grass-addons/grass6/raster/r.in.onearth/README 2012-06-13 03:11:30 UTC (rev 52054)
@@ -0,0 +1,4 @@
+r.in.onearth will need the newest grass6.1-cvs version of g.region. It is in
+CVS since 2005-12-21.
+
+Enjoy
Property changes on: grass-addons/grass6/raster/r.in.onearth/README
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Added: grass-addons/grass6/raster/r.in.onearth/description.html
===================================================================
--- grass-addons/grass6/raster/r.in.onearth/description.html (rev 0)
+++ grass-addons/grass6/raster/r.in.onearth/description.html 2012-06-13 03:11:30 UTC (rev 52054)
@@ -0,0 +1,66 @@
+<H2>DESCRIPTION</H2>
+
+<EM>r.in.onearth</EM> Download and import satellite images direct from
+the NASA onearth WMS server into GRASS. The images are downloaded with
+<i>wget</i> from <a href="http://wms.jpl.nasa.gov/">http://wms.jpl.nasa.gov/</a>
+<br>
+as geotiff image. After downloading the data, the images are imported
+with <a href="r.in.gdal.html">r.in.gdal</a>. Data will automatically
+be reprojected to the LOCATION's projection from
+latitude-longitude/WGS84 (EPSG:4326). The <i>wget</i> program needs to
+be installed to get the images. <b>The data will be downloaded with
+the size, resolution and location of the current GRASS location.</b>
+<em>g.region</em> can be used to adjust these settings beforehand.
+
+<H3>Downloadable Data sets</H3>
+
+<ul>
+ <li>WMS Global Mosaic, a high resolution global image mosaic of the
+ earth, produced from more than 8200 individual Landsat7
+ scenes.</li>
+ <li>30m SRTM Reflectance Image.</li>
+ <li>Composite of data produced by the MODIS Rapid Response System,
+ from data collected by the MODIS/Terra (default: previous day).</li>
+ <li>Composite of data produced by the MODIS Rapid Response System,
+ from data collected by the MODIS/Aqua (default: previous day).</li>
+ <li>Blue Marble Next Generation, A MODIS-derived 500m true color
+ earth data set including seasonal dynamics.</li>
+</ul>
+
+<H2>NOTES</H2>
+
+The images will be downloaded and stored into an temporary
+directory. After the download of one image is finished, it will be
+reprojected with gdalwarp (if the target location is not latitude-longitude/WGS84) and
+imported with <em>r.in.gdal</em>. At the end, the temporary directory
+will be deleted.
+<P>
+If the NASA WMS server do not provide the images,
+<em>r.in.onearth</em> will try to handle this and shows the content of
+the NASA error XML file at the stdout device.
+<P>
+
+More information about the NASA onearth WMS data available at
+<a href="http://wms.jpl.nasa.gov/">http://wms.jpl.nasa.gov/</a>. The WMS
+protocoll is hardcoded in <em>r.in.onearth</em>, also the NASA provided
+parameters. If these parameters change, the script has to be
+modified.
+
+<h2>EXAMPLE</h2>
+
+Download Landsat Global Mosaik for Spearfish (SD, USA) area:
+<div class="code"><pre>
+g.region res=15 -pa
+r.in.onearth -l output=spearfish tmband=visual
+d.rgb b=spearfish_LandsatTM_visual.blue g=spearfish_LandsatTM_visual.green r=spearfish_LandsatTM_visual.red
+</pre></div>
+
+
+<H2>SEE ALSO</H2>
+<a href="r.in.srtm.html">r.in.srtm</a>
+
+<H2>AUTHOR</H2>
+
+Soeren Gebbert, Markus Neteler
+
+<p><i>Last changed: $Date$</i>
Property changes on: grass-addons/grass6/raster/r.in.onearth/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Added: grass-addons/grass6/raster/r.in.onearth/r.in.onearth
===================================================================
--- grass-addons/grass6/raster/r.in.onearth/r.in.onearth (rev 0)
+++ grass-addons/grass6/raster/r.in.onearth/r.in.onearth 2012-06-13 03:11:30 UTC (rev 52054)
@@ -0,0 +1,399 @@
+#!/bin/sh
+#############################################################################
+# Download and import satellite images direct from the #
+# NASA onearth WMS server into GRASS. #
+# written by Soeren Gebbert 11/2005 soerengebbert AT gmx de #
+# and Markus Neteler #
+# #
+# COPYRIGHT: (C) 2005 by the GRASS Development Team #
+# #
+# This program is free software under the GNU General Public #
+# License (>=v2). Read the file COPYING that comes with GRASS #
+# for details. #
+# #
+#############################################################################
+
+#%Module
+#% description: Download and import satellite images direct from the NASA onearth WMS server into GRASS or to a geo-tiff image file.
+#%End
+#%option
+#% key: output
+#% gisprompt: new,cell,raster
+#% type: string
+#% description: Output raster map name prefix
+#% required : no
+#%end
+#%option
+#% key: file
+#% gisprompt: file,file,file
+#% type: string
+#% description: Output file name prefix
+#% answer: /tmp/test
+#% required : no
+#%end
+#%flag
+#% key: f
+#% description: Do not import to GRASS, create a tiff file instead.
+#%end
+#%flag
+#% key: l
+#% description: Download and Import WMS Global Mosaic, a High Resolution, Global Coverage, Landsat TM 7 mosaic.
+#%end
+#%flag
+#% key: s
+#% description: Download and Import the radar reflectance images produced by the SRTM mission.
+#%end
+#%flag
+#% key: b
+#% description: Download and Import the Blue Marble Next Generation layer, one for each month of the year.
+#%end
+#%flag
+#% key: t
+#% description: Download and Import the composite of data produced by the MODIS Rapid Response System, from data collected yesterday by the MODIS/Terra.
+#%end
+#%flag
+#% key: a
+#% description: Download and Import the composite of data produced by the MODIS Rapid Response System, from data collected yesterday by the MODIS/Aqua.
+#%end
+#%option
+#% key: tmband
+#% type: string
+#% description: NASA Landsat TM bands
+#% options: Red,Green,Blue,IR1,IR2,IR3,ThL,ThH,Pan,visual,pseudo
+#% required : no
+#%end
+#%option
+#% key: srtmband
+#% type: string
+#% description: Radar reflectance bands
+#% options: default,ss1,ss2,ss3,ss4,all
+#% required : no
+#%end
+#%option
+#% key: month
+#% type: string
+#% description: Blue Marble Next Generation layer
+#% options: Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
+#% required : no
+#%end
+#%option
+#% key: time
+#% type: string
+#% description: The datum of creation for Aqua or Terra satellite images
+#% answer: 2005-3-24
+#% required : no
+#%end
+#%option
+#% key: wgetopt
+#% type: string
+#% description: Options for wget
+#% answer: -c -t 5 --user-agent=MSIE5.5
+#% required : no
+#%end
+
+#Only run if started in GRASS
+if test "$GISBASE" = ""; then
+ echo "You must be in GRASS GIS to run this program." >&2
+ exit 1
+fi
+
+#Set up important vars first
+SRC="EPSG:4326" #This is the Projection LatLong wgs84
+FORMAT="image/geotiff" #GeoTiff import for r.in.gdal
+NASASERVER="http://wms.jpl.nasa.gov/wms.cgi" #this server may change
+TYPE=""
+TIME=""
+IMPORT=0 #0 is true
+GLOBAL_MOSAIC_LAYER="global_mosaic_base" #Thats the NASA WMS Global Mosaic database
+SRTM_MAG_LAYER="srtm_mag" #Thats the NASA srtm_mag database
+BMNG_LAYER="BMNG" #Thats the Blue Marble Next Generation database
+DAILY_TERRA_LAYER="daily_terra" #Thats the NASA daily terra database
+DAILY_AQUA_LAYER="daily_aqua" #Thats the NASA daily aqua database
+USEGDALWARP=0 #if we dont have gdalwarp, only LatLong projection is supported, 0 is true
+FILE_EXTENT=".tif"
+
+# check if we have wget
+if [ ! -x "`which wget`" ] ; then
+ echo "wget required, please install first" 2>&1
+ exit 1
+fi
+
+# check if we have gdalwarp
+if [ ! -x "`which gdalwarp`" ] ; then
+ echo "gdalwarp is recommended, please install first (script still works in LatLong locations)" 2>&1
+ USEGDALWARP=1 #use only LatLong
+fi
+
+#Some functions
+#Get the data from the NASA server
+GetData() {
+ IMPORT=0 #default
+ local STRING="request=GetMap&layers=${LAYER}&srs=${SRC}&width=${WIDTH}&height=${HEIGHT}&bbox=${w},${s},${e},${n}&format=${FORMAT}&version=1.1.0&styles=${STYLE}${TIME}"
+ #echo $STRING
+ #Create thefilename
+ IMAGEFILE="${TMPDIR}/Image_${LAYER}_${STYLE}_${HEIGHT}_${WIDTH}"
+ echo " "
+ echo " "
+ echo "************** DOWNLOAD DATA ****************"
+ echo "Requesting Data from ${NASASERVER}"
+ #download the File from the Server
+ wget ${WGET_OPTIONS} --post-data=${STRING} ${NASASERVER} -O ${IMAGEFILE}
+ if [ $? -ne 0 ]; then
+ echo " "
+ echo "!--------------ERROR-------------------!"
+ echo "wget was not able to download the data"
+ echo " "
+ IMPORT=1
+ return 1
+ fi
+ if [ -f "${IMAGEFILE}" ]; then
+ IMPORT=0
+ else
+ echo " "
+ echo "!--------------ERROR-------------------!"
+ echo "wget was not able to download the data"
+ echo " "
+ IMPORT=1
+ return 1
+ fi
+return 0
+}
+
+#warp the data to the current grass locationa via gdalwarp
+WarpData() {
+ if [ ${USEGDALWARP} -eq 0 ]; then
+ echo "************* CONVERT DATA ***************"
+ #create the new imagename
+ IMAGEFILE_GDALWARP="${TMPDIR}/Image_${LAYER}_${STYLE}_${HEIGHT}_${WIDTH}_gdalwarp"
+
+ #convert the data to the current location, create Erdas Imagine Images (HFA)
+ gdalwarp -s_srs $SRC -t_srs "`g.proj -wf`" -of HFA ${IMAGEFILE} ${IMAGEFILE_GDALWARP}
+ if [ $? -ne 0 ]; then
+ echo "!-------- CAN NOT CONVERT DATA --------!"
+ echo "!------------ WILL BREAK --------------!"
+ exitprocedure
+ fi
+ echo "************ DATA CONVERTED *************"
+ #remove the old image and convert the name
+ rm -f ${IMAGEFILE}
+ IMAGEFILE=${IMAGEFILE_GDALWARP}
+ return 0
+ fi
+return 1
+}
+
+#Import the Data with r.in.gdal
+ImportData() {
+ if [ ${IMPORT} -eq 0 ]; then
+ #Check if Tiff file
+ FILETYPE=`file ${IMAGEFILE} | cut --fields=2 --delimiter=:`
+ echo ${FILETYPE} | grep TIFF > /dev/null
+ if [ $? -ne 0 ]; then
+ echo "Downloaded file is not a GeoTiff file, but will try to import"
+ fi
+ echo "************** CHECK DATA *****************"
+ gdalinfo ${IMAGEFILE} | grep "GDALOpen failed" > /dev/null
+ local ReturnValueGdalBug=$?
+
+ gdalinfo ${IMAGEFILE}
+ local ReturnValueGdal=$?
+
+ if [ ${ReturnValueGdal} -eq 0 ] && [ ${ReturnValueGdalBug} -ne 0 ]; then
+ echo "************* DATA CHECK OK ***************"
+ #Copy or import
+ if [ ${GIS_FLAG_f} -eq 1 ] ; then
+ #Copy the data to the outputfile
+ echo "Creating output file ${GIS_OPT_file}${TYPE}${STYLE}${FILE_EXTENT}"
+ cp ${IMAGEFILE} ${GIS_OPT_file}${TYPE}${STYLE}${FILE_EXTENT}
+ else
+ #Warp the data!
+ WarpData
+ echo "************** IMPORT DATA ****************"
+ r.in.gdal -o input=${IMAGEFILE} output="${GIS_OPT_output}${TYPE}_${STYLE}"
+ fi
+ else
+ echo "!-------------------BREAK---------------------!"
+ echo "Downloaded file is not supported by gdal, or cannot be imported"
+ if [ ${ReturnValueGdalBug} -eq 0 ]; then
+ echo "There was a problem while downloading the file, maybe you should try it again."
+ fi
+ echo "File of Type: ${FILETYPE}"
+ #If the File is XML, then cat the contents to stdout
+ echo ${FILETYPE} | grep XML > /dev/null
+ if [ $? -eq 0 ]; then
+ echo " "
+ echo "Message from Server ${NASASERVER}"
+ echo " "
+ echo "!------------BEGIN-ERROR-MESSGAE--------------!"
+ cat ${IMAGEFILE}
+ echo "!-------------END-ERROR-MESSGAE---------------!"
+ echo " "
+ fi
+ fi
+ rm -rf ${IMAGEFILE}
+ fi
+
+ return 0
+}
+
+# what to do in case of user break:
+exitprocedure()
+{
+ echo "User break!"
+ rm -rf "$TMPDIR"
+ exit 1
+}
+trap "exitprocedure" 2 3 15
+
+#Parse the arguments
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+ exec g.parser "$0" "$@"
+fi
+
+#At least one flag should be set
+if [ $GIS_FLAG_l -eq 0 -a $GIS_FLAG_s -eq 0 -a $GIS_FLAG_b -eq 0 -a $GIS_FLAG_t -eq 0 -a $GIS_FLAG_a -eq 0 ] ; then
+ echo "ERROR: Select a flag to specify map type"
+ exit 1
+fi
+
+#Check if a file or a map should be created
+if [ ${GIS_FLAG_f} -eq 1 ] ; then
+ if [ ${GIS_OPT_file} == ""] ; then
+ echo "Please specify the output filename"
+ exit 1
+ fi
+fi
+
+#Some mapset informations
+eval `g.gisenv`
+: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
+LOCATION="$GISDBASE/$LOCATION_NAME/$MAPSET"
+PERM="$GISDBASE/$LOCATION_NAME/PERMANENT"
+
+#wget has many options
+WGET_OPTIONS=${GIS_OPT_wgetopt}
+
+#Get the region data
+eval `g.region -g`
+WIDTH=${cols}
+HEIGHT=${rows}
+eval `g.region -gb`
+#Now get the LatLong Boundingbox
+grep -i 'proj: ll' $PERM/PROJ_INFO > /dev/null
+if [ $? -ne 0 ] && [ ${USEGDALWARP} -eq 0 ]; then
+ n=$ll_n
+ s=$ll_s
+ e=$ll_e
+ w=$ll_w
+ echo "LatLong wgs84 bounding box = N $n S $s W $w E $e"
+else
+ #We have LatLong projection, no warp is needed!
+ USEGDALWARP=1
+ #There is a bug in nasa WMS service, it provides images which are lager then
+ #the world :(, we have to crop the images
+ if [ "$n" == "90" -a "$s" == "-90" -a "$w" == "-180" -a "$e" == "180" ] ; then
+
+ # check if we have bc
+ if [ ! -x "`which bc`" ] ; then
+ echo "bc required, please install first" 2>&1
+ exit 1
+ fi
+ #We request a smaller image from the wms server
+ n=`echo "$n - 0.001" | bc`
+ s=`echo "$s + 0.001" | bc`
+ e=`echo "$e - 0.001" | bc`
+ w=`echo "$w + 0.001" | bc`
+ fi
+fi
+
+#Break If we have no warp and no LatLong
+grep -i 'proj: ll' $PERM/PROJ_INFO > /dev/null
+if [ $? -ne 0 ] && [ ${USEGDALWARP} -eq 1 ] ; then
+ echo "NASA onearth data are in Latitude/Longitude. The current"
+ echo "location projection differs and you dont have gdalwarp! STOP."
+ exit 1
+fi
+
+
+#make a temporary directory
+TMPDIR="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMPDIR" ] ; then
+ echo "ERROR: unable to create temporary files" 1>&2
+ exit 1
+fi
+rm -f "$TMPDIR"
+mkdir "$TMPDIR"
+
+#Get the Data and import them
+#import every choice that can be made
+
+if [ $GIS_FLAG_l -eq 1 ] ; then
+LAYER=${GLOBAL_MOSAIC_LAYER}
+STYLE=${GIS_OPT_tmband}
+TYPE="LandsatTM"
+echo " "
+echo "======================================================="
+echo "Will download and import ${TYPE} Data with band ${STYLE}"
+echo "======================================================="
+GetData
+ImportData
+fi
+
+if [ $GIS_FLAG_s -eq 1 ] ; then
+LAYER=${SRTM_MAG_LAYER}
+STYLE=${GIS_OPT_srtmband}
+TYPE="SRTM"
+echo " "
+echo "======================================================="
+echo "Will download and import ${TYPE} Data with band ${STYLE}"
+echo "======================================================="
+GetData
+ImportData
+fi
+
+if [ $GIS_FLAG_b -eq 1 ] ; then
+LAYER=${BMNG_LAYER}
+STYLE=${GIS_OPT_month}
+TYPE="BMNG"
+echo " "
+echo "======================================================="
+echo "Will download and import ${TYPE} Data of month ${STYLE}"
+echo "======================================================="
+GetData
+ImportData
+fi
+
+if [ $GIS_FLAG_t -eq 1 ] ; then
+LAYER=${DAILY_TERRA_LAYER}
+TIME="&time=${GIS_OPT_time}"
+STYLE=""
+TYPE="Daily_Terra"
+echo " "
+echo "======================================================="
+echo "Will download and import ${TYPE} Data"
+echo "======================================================="
+GetData
+ImportData
+fi
+
+if [ $GIS_FLAG_a -eq 1 ] ; then
+LAYER=${DAILY_AQUA_LAYER}
+TIME="&time=${GIS_OPT_time}"
+STYLE=""
+TYPE="Daily_Aqua"
+echo " "
+echo "======================================================="
+echo "Will download and import ${TYPE} Data"
+echo "======================================================="
+GetData
+ImportData
+fi
+
+#remove the temp dir
+rm -rf "$TMPDIR"
+echo " "
+echo "========"
+echo "Finished"
+echo "========"
+exit 0
+
Property changes on: grass-addons/grass6/raster/r.in.onearth/r.in.onearth
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/x-sh
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list