[GRASS-SVN] r45167 - in grass-addons/ossim_grass: . d.png.legend r.planet

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 23 09:33:57 EST 2011


Author: epifanio
Date: 2011-01-23 06:33:57 -0800 (Sun, 23 Jan 2011)
New Revision: 45167

Added:
   grass-addons/ossim_grass/d.png.legend/
   grass-addons/ossim_grass/d.png.legend/d.png.legend
   grass-addons/ossim_grass/d.png.legend/description.html
   grass-addons/ossim_grass/r.planet/make3d.py
Modified:
   grass-addons/ossim_grass/r.planet/r.planet.py
Log:
added script to generate a png legend for raster layers (used as screen overlay in ossimplanet), inizial set of function to convert raster data to 3dtiles and general-raster formats

Added: grass-addons/ossim_grass/d.png.legend/d.png.legend
===================================================================
--- grass-addons/ossim_grass/d.png.legend/d.png.legend	                        (rev 0)
+++ grass-addons/ossim_grass/d.png.legend/d.png.legend	2011-01-23 14:33:57 UTC (rev 45167)
@@ -0,0 +1,281 @@
+#!/bin/sh
+
+############################################################################
+#
+# MODULE:       d.legend.png
+#
+# AUTHOR(S):    Di Stefano Massimo
+#               
+#
+# PURPOSE:      generate legend in png
+#               
+#
+# COPYRIGHT:    (c) 2006 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: generate legend in png 
+#%End
+#%option
+#% guisection: Options
+#% key: input
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Input raster data
+#% multiple : yes
+#% required: yes
+#%end
+#%option
+#% guisection: Options
+#% key: color
+#% type: string
+#% answer:red
+#% options :red,orange,yellow,green,blue,indigo,violet,white,black,gray,brown,magenta,aqua,grey,cyan,purple
+#% description: Legend text color
+#% required : yes
+#%end
+#%option
+#% guisection: Options
+#% key: output_directory
+#% type: string
+#% gisprompt: new_file,directory,output
+#% description: Directory where save output 
+#% required : yes
+#%end
+#%option
+#% guisection: Options
+#% key_desc: string
+#% key: TRUECOLOR
+#% answer:TRUE
+#% options :TRUE,FALSE
+#% type: string
+#% description: Sets true-color support
+#% required : no
+#%end
+#%option
+#% guisection: Options
+#% key_desc: string
+#% key: TRANSPARENT
+#% answer:TRUE
+#% options :TRUE,FALSE
+#% type: string
+#% description: Sets transparent background ON or OFF
+#% required : no
+#%end
+#%option
+#% guisection: Options
+#% key_desc: string
+#% key: PNG_READ
+#% answer:FALSE
+#% options :TRUE,FALSE
+#% type: string
+#% description: If TRUE, the PNG driver will initialize the image from the contents of GRASS_PNGFILE.
+#% required : no
+#%end
+#%option
+#% guisection: Options
+#% key: BACKGROUNDCOLOR
+#% answer: 000000
+#% type: string
+#% description: Specifies the background color to use in RGB notation (hex values)
+#% required : no
+#%end
+#%option
+#% guisection: Options
+#% key: PNG_COMPRESSION
+#% answer: 9
+#% options :1,2,3,4,5,6,7,8,9
+#% type: integer
+#% description: Compression level of PNG files 
+#% required : no
+#%end
+#%option
+#% guisection: Options
+#% key: width
+#% type: double
+#% answer: 640
+#% description: width
+#% required : no
+#%end
+#%option
+#% guisection: Options
+#% key: height
+#% type: double
+#% answer: 480
+#% description: height
+#% required : no
+#%end
+#%option
+#% guisection: Options
+#% key: at
+#% type: double
+#% description: Placement as percentage of screen coordinates
+#% required : no
+#%end
+
+#%flag
+#% guisection: Advanced
+#% key: v
+#% description: Do not show category labels
+#%END
+#%flag
+#% guisection: Advanced
+#% key: c
+#% description: Do not show category numbers
+#%END
+#%flag
+#% guisection: Advanced
+#% key: n
+#% description: Skip category with no labels
+#%END
+#%flag
+#% guisection: Advanced
+#% key: s
+#% description: Draw smooth gradient
+#%END
+#%flag
+#% guisection: Advanced
+#% key: f
+#% description: Flip legend
+#%END
+#%flag
+#% guisection: Advanced
+#% key: z
+#% description: Export Image
+#%END
+
+
+#%option
+#% guisection: Advanced
+#% key: lines
+#% type: integer
+#% answer: 0
+#% description: Number of text lines
+#% required : no
+#%end
+#%option
+#% guisection: Advanced
+#% key: thin
+#% type: integer
+#% answer: 1
+#% description: Number of text labels for smooth gradient legend
+#% required : no
+#%end
+#%option
+#% guisection: Advanced
+#% key: labelnum
+#% type: integer
+#% answer: 5
+#% description: Number of text labels for smooth gradient legend
+#% required : no
+#%end
+#%option
+#% guisection: Advanced
+#% key: use
+#% type: string
+#% description: List of discrete category for numbers/values for legend
+#% required : no
+#%end
+#%option
+#% guisection: Advanced
+#% key: range
+#% type: string
+#% description: Use a subset of the map range for the legend
+#% required : no
+#%end
+
+
+
+    input=$GIS_OPT_input
+    color=$GIS_OPT_color
+    TRUECOLOR=$GIS_OPT_TRUECOLOR
+    TRANSPARENT=$GIS_OPT_TRANSPARENT
+    PNG_READ=$GIS_OPT_PNG_READ
+    BACKGROUNDCOLOR=$GIS_OPT_BACKGROUNDCOLOR
+    PNG_COMPRESSION=$GIS_OPT_PNG_COMPRESSION
+    width=$GIS_OPT_width
+    height=$GIS_OPT_height
+    output_directory=$GIS_OPT_output_directory
+
+    lines=$GIS_OPT_lines
+    thin=$GIS_OPT_thin
+    labelnum=$GIS_OPT_labelnum
+    at=$GIS_OPT_at
+    use=$GIS_OPT_use
+    range=$GIS_OPT_range
+
+    if  [ -z $GISBASE ] ; then
+    	     echo "You must be in GRASS GIS to run this program."
+	     exit 1
+    fi   
+
+    if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+    fi
+
+
+eval `g.gisenv`
+: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
+LOCATION=$GISDBASE/$LOCATION_NAME/$MAPSET
+
+
+
+if [ $GIS_FLAG_v -eq 1 ] ; then
+	flag_v="-v "
+fi
+
+if [ $GIS_FLAG_c -eq 1 ] ; then
+	flag_c="-c "
+fi
+
+if [ $GIS_FLAG_n -eq 1 ] ; then
+	flag_n="-n "
+fi
+
+if [ $GIS_FLAG_f -eq 1 ] ; then
+	flag_f="-f "
+fi
+
+if [ $GIS_FLAG_s -eq 1 ] ; then
+	flag_s="-s"
+fi
+
+flags=$flag_v$flag_c$flag_n$flag_f$flag_s
+
+
+export GRASS_RENDER_IMMEDIATE=TRUE
+export GRASS_TRUECOLOR=$GIS_OPT_TRUECOLOR
+export GRASS_TRANSPARENT=$GIS_OPT_TRANSPARENT
+export GRASS_PNG_READ=$GIS_OPT_PNG_READ
+export GRASS_BACKGROUNDCOLOR=$GIS_OPT_BACKGROUNDCOLOR
+export GRASS_PNG_COMPRESSION=$GIS_OPT_PNG_COMPRESSION
+export GRASS_WIDTH=$GIS_OPT_width
+export GRASS_HEIGHT=$GIS_OPT_height
+
+# at=$at use=$use range=$range
+
+
+
+STRING=`echo $GIS_OPT_input | sed s/,/\ /g`
+for i in $STRING
+    do
+	export GRASS_PNGFILE=$output_directory/$i.png
+	d.legend map=$i color=$color $flags lines=$lines thin=$thin labelnum=$labelnum
+done
+
+if [ $GIS_FLAG_z -eq 1 ] ; then
+	for i in $STRING
+	do
+		#export GRASS_TRANSPARENT=FALSE
+		export GRASS_PNGFILE=$output_directory/image_$i.png
+		d.rast $i
+		d.legend map=$i color=$color $flags lines=$lines thin=$thin labelnum=$labelnum
+	done
+fi


Property changes on: grass-addons/ossim_grass/d.png.legend/d.png.legend
___________________________________________________________________
Added: svn:executable
   + *

Added: grass-addons/ossim_grass/d.png.legend/description.html
===================================================================
--- grass-addons/ossim_grass/d.png.legend/description.html	                        (rev 0)
+++ grass-addons/ossim_grass/d.png.legend/description.html	2011-01-23 14:33:57 UTC (rev 45167)
@@ -0,0 +1,77 @@
+<h2>DESCRIPTION</h2>
+
+
+<em><b>d.png.legend </b></em> 
+<p>
+- Generate legend in PNG.
+<p>
+- Used in kml screen overlay.
+<p>
+
+<h2>Flags:</h2>
+
+<em><b>-v </b></em> : Do not show category labels
+<p>
+<em><b>-c </b></em> : Do not show category numbers
+<p>
+<em><b>-n </b></em> : Skip category with no labels
+<p>
+<em><b>-s </b></em> : Draw smooth gradient
+<p>
+<em><b>-f </b></em> : Flip legend
+<p>
+<em><b>-z </b></em> : Export Image
+
+
+<h2>Parameters</h2> :
+<p>
+<em><b>input </b></em> : Input raster data
+<p>
+<em><b>color </b></em> : Legend text color
+<p>
+<em><b>output_directory </b></em> : Directory where save output 
+<p>
+<em><b>TRUECOLOR </b></em> : Sets true-color support
+<p>
+<em><b>TRANSPARENT </b></em> : Sets transparent background ON or OFF
+<p>
+<p>
+<em><b>PNG_READ </b></em> : If TRUE, the PNG driver will initialize the image from the contents of GRASS_PNGFILE.
+<p>
+<p>
+<em><b>BACKGROUNDCOLOR </b></em> : Specifies the background color to use in RGB notation (hex values) 
+<p>
+<em><b>PNG_COMPRESSION </b></em> : Compression level of PNG files 
+<p>
+<em><b>width </b></em> : Image width
+<p>
+<em><b>height </b></em> : Image height
+<p>
+<em><b>at </b></em> : Placement as percentage of screen coordinates
+<p>
+
+<h2>EXAMPLE</h2>
+
+title :
+<div class="code"><pre>
+d.png.legend
+</pre></div>
+<p>
+
+
+
+<h2>REFERENCES</h2>
+ 
+<em><A HREF="http://web.me.com/epiesasha/PlanetSasha/">PlanetSasha</A></em> Google Summer of Code - OSGEO - Massimo Di Stefano.
+
+<h2>SEE ALSO</h2>
+
+<em><A HREF="v.planet.html">v.planet.py</A></em>
+<em><A HREF="r.planet.html">r.planet.py</A></em>
+
+<H2>AUTHOR</H2>
+
+Massimo Di Stefano - <EM><A HREF="mailto:massimodisasha at gmail.com">@-mail</A></EM> <br>
+
+
+<p><i>Last changed: $Date: 2010-02-07 00:45:10 +0200 (Mon, 9 Feb 2010) $</i>

Added: grass-addons/ossim_grass/r.planet/make3d.py
===================================================================
--- grass-addons/ossim_grass/r.planet/make3d.py	                        (rev 0)
+++ grass-addons/ossim_grass/r.planet/make3d.py	2011-01-23 14:33:57 UTC (rev 45167)
@@ -0,0 +1,45 @@
+def make3d(tile, elev, outdir):
+    makedir(outdir)
+    kwl = 'elev.kwl'
+    template = 'igen.slave_tile_buffers: 5 \n'
+    template += 'igen.tiling.type: ossimTiling \n'
+    template += 'igen.tiling.tiling_distance: 1 1 \n'
+    template += 'igen.tiling.tiling_distance_type: degrees \n'
+    template += 'igen.tiling.delta: %s %s \n' % (tile,tile)
+    template += 'igen.tiling.delta_type: total_pixels \n'
+    template += 'igen.tiling.padding_size_in_pixels: 0 0 \n'
+    template += 'object1.description: \n'
+    template += 'object1.enabled:  1 \n'
+    template += 'object1.id:  1 \n'
+    template += 'object1.object1.description: \n'  
+    template += 'object1.object1.enabled:  1 \n'
+    template += 'object1.object1.id:  2 \n'
+    template += 'object1.object1.resampler.magnify_type:  bilinear \n'
+    template += 'object1.object1.resampler.minify_type:  bilinear \n'
+    template += 'object1.object1.type:  ossimImageRenderer \n'
+    template += 'object1.object2.type:  ossimCastTileSourceFilter \n'
+    template += 'object1.object2.scalar_type: ossim_sint16 \n'
+    template += 'object1.type:  ossimImageChain \n'
+    template += 'object2.type: ossimGeneralRasterWriter \n'
+    template += 'object2.byte_order: big_endian \n'
+    template += 'object2.create_overview: false \n'
+    template += 'object2.create_histogram: false \n'
+    template += 'object2.create_external_geometry: false \n'
+    template += 'product.projection.type: ossimEquDistCylProjection \n'
+    open(kwl,'w').write(template)
+    instr = 'ossim-orthoigen'
+    instr += ' --tiling-template '
+    instr += kwl
+    instr +=' --view-template '
+    instr += kwl
+    instr +=' --writer-template '
+    instr += kwl
+    instr +=' --chain-template '
+    instr += kwl
+    instr += ' %s ' % elev 
+    instr += '%s' % outdir
+    instr +='/%SRTM%'
+    return instr
+
+# os.system(instr)
+


Property changes on: grass-addons/ossim_grass/r.planet/make3d.py
___________________________________________________________________
Added: svn:executable
   + *

Modified: grass-addons/ossim_grass/r.planet/r.planet.py
===================================================================
--- grass-addons/ossim_grass/r.planet/r.planet.py	2011-01-23 14:16:39 UTC (rev 45166)
+++ grass-addons/ossim_grass/r.planet/r.planet.py	2011-01-23 14:33:57 UTC (rev 45167)
@@ -57,27 +57,12 @@
 #% required : no
 #%end
 #%option
-#% key: np
-#% type: integer
-#% key_desc: Processor-Number
-#% answer: 0
-#% description: Mpi Processor Number
-#% required : no
-#%end
-#%option
 #% key: tile
 #% type: double
 #% key_desc: tile
 #% description: tile
 #% required : no
 #%end
-#%option
-#% key: elev
-#% type: string
-#% key_desc: elevation name
-#% description: elevation name
-#% required : no
-#%end
 #%flag
 #% key: a
 #% description: Add raster
@@ -90,10 +75,6 @@
 #% key: d
 #% description: Orthoigen 
 #%END
-#%flag
-#% key: m
-#% description: MPI 
-#%END
 
 
 import sys
@@ -101,21 +82,15 @@
 import socket
 import grass.script as grass
 import osgeo.gdal as gdal
-import platform
 
 def main():
-    global mpi
-    global np
     add = flags['a']
     remove = flags['r']
     orthoigen = flags['d']
-    mpi = flags['m']
     host = options['host']
     dport = options['dport']
     pport = options['pport']
     tile = options['tile']
-    elev = options['elev']
-    np = options['np']
     grassenv = grass.gisenv()
     mappa = options['map'].replace("@"," ")
     mappa = mappa.split()
@@ -123,7 +98,6 @@
     nflags = len(filter(None, [add, remove, orthoigen]))
     if nflags > 1:
         grass.run_command('g.message' , message = 'Cannot add & remove a map or use orthoigen at the same time.')
-        sys.exit()
     if nflags < 1:
         grass.run_command('g.message' , message = 'No action requested , please choose one from "-a : add" or "-r : remove" flags.')
     try :
@@ -156,34 +130,34 @@
     lat = zoom_position[0]
     lon = zoom_position[1]
     distance = zoom_position[2]
-    if add :
-        try :
-            addzoom(output,lon,lat,distance,host,dport,pport)
-            print 'Added raster file :', mappa[0]
-            print 'Camera positioned to : '
-            print 'Longitude = ',lon
-            print 'Latitude = ', lat
-            print 'Altitude = ' , distance
-        except :
-            print "conecction error"
-    if remove :
-        removefile(output,host,dport)
-        print 'Removed raster file :', mappa[0]
-    if orthoigen :
-        if tile != '':
-            path = os.path.dirname(output)
-            if elev == '':
+    if nflags == 1:
+        if add :
+            try :
+                addzoom(output,lon,lat,distance,host,dport,pport)
+                print 'Added raster file :', mappa[0]
+                print 'Camera positioned to : '
+                print 'Longitude = ',lon
+                print 'Latitude = ', lat
+                print 'Altitude = ' , distance
+            except :
+                print "conecction error"
+        if remove :
+            removefile(output,host,dport)
+            print 'Removed raster file :', mappa[0]
+        if orthoigen :
+            if tile != '':
+                path = os.path.dirname(output)
                 elevdir = os.path.join(path,'elevation',mappa[0]+'/')
-            else :
-                elevdir = os.path.join(path,'elevation',elev+'/')
-            if not os.path.exists(elevdir):
-                os.makedirs(elevdir)
-                elev = mappa[0]+'.tiff'
-                exportiff(output,elev)
-                instr = make3d(tile, elev, elevdir)
-                os.system(instr)
-            if tile == '':
-                print 'please set the tile dimension'
+                print elevdir
+                if not os.path.exists(elevdir):
+                    os.makedirs(elevdir)
+                    elev = mappa[0]+'.tiff'
+                    exportiff(output,elev)
+                    instr = make3d(tile, elev, elevdir)
+                    print instr
+                    os.system(instr)
+                if tile == '':
+                    print 'please set the tile dimension'
 
 def exportiff(infile,outfile):
     gdal.GetDriverByName('GTiff').CreateCopy(outfile,gdal.Open(infile))
@@ -305,19 +279,7 @@
     if not os.path.exists(d):
         os.makedirs(d)
 
-
-def WhichPlatform():
-    #global platform
-    platforms = platform.system()
-    return platforms
-
-
 def make3d(tile, elev, outdir):
-    systemplatform = WhichPlatform()
-    if systemplatform == 'Darwin':
-        orthoigenexec = '/Users/sasha/OssimBuilds/Release/ossim-orthoigen'
-    else :
-        orthoigenexec = 'ossim-orthoigen'
     makedir(outdir)
     kwl = 'elev.kwl'
     template = 'igen.slave_tile_buffers: 5 \n'
@@ -346,12 +308,8 @@
     template += 'object2.create_external_geometry: false \n'
     template += 'product.projection.type: ossimEquDistCylProjection \n'
     open(kwl,'w').write(template)
-    instr = 'export DYLD_FRAMEWORK_PATH=/Users/sasha/OssimBuilds/Release/ ; '
-    if mpi :
-        instr += 'mpirun -np %s ' % np
-        instr += orthoigenexec
-    else :
-        instr += orthoigenexec
+    #instr = 'export DYLD_FRAMEWORK_PATH=/Users/sasha/OssimBuilds/Release/ ; '
+    instr = '/usr/local/bin/ossim-orthoigen'
     instr += ' --tiling-template '
     instr += kwl
     instr +=' --view-template '
@@ -367,16 +325,7 @@
 
 
 def makeoverview(input):
-    systemplatform = WhichPlatform()
-    if systemplatform == 'Darwin':
-        img2rrexec = 'export DYLD_FRAMEWORK_PATH=/Users/sasha/OssimBuilds/Release/ ; /Users/sasha/OssimBuilds/Release/ossim-img2rr'
-    else :
-        img2rrexec = 'ossim-img2rr'
-    if mpi :
-        os.system("mpirun -np %s %s %s" % (np, img2rrexec, input))
-    else :
-       os.system('%s %s' % (img2rrexec, input))
-        
+    os.system("ossim-img2rr %s" % input)
 
 
 if __name__ == "__main__":



More information about the grass-commit mailing list