[GRASS-SVN] r40907 - in grass-addons: . ossim_grass ossim_grass/r.planet

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 10 08:20:05 EST 2010


Author: epifanio
Date: 2010-02-10 08:20:04 -0500 (Wed, 10 Feb 2010)
New Revision: 40907

Added:
   grass-addons/ossim_grass/
   grass-addons/ossim_grass/r.planet/
   grass-addons/ossim_grass/r.planet/Makefile
   grass-addons/ossim_grass/r.planet/description.html
   grass-addons/ossim_grass/r.planet/r.planet.py
Log:
Add scripts to start ossim_grass data+position communication

Added: grass-addons/ossim_grass/r.planet/Makefile
===================================================================
--- grass-addons/ossim_grass/r.planet/Makefile	                        (rev 0)
+++ grass-addons/ossim_grass/r.planet/Makefile	2010-02-10 13:20:04 UTC (rev 40907)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.planet.py
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/ossim_grass/r.planet/description.html
===================================================================
--- grass-addons/ossim_grass/r.planet/description.html	                        (rev 0)
+++ grass-addons/ossim_grass/r.planet/description.html	2010-02-10 13:20:04 UTC (rev 40907)
@@ -0,0 +1,52 @@
+<H2>DESCRIPTION</H2>
+
+
+<EM><B>r.planet.py : </B></EM> Scripts to generate vrt layer from a selected grass raster layer and add/zoomTo/remove the data to ossimplanet using the ossimplanet tcp listner.
+
+<H2>OPTIONS</H2>
+
+<p>
+<B>[-a] :</B> add map and zoom to it
+<p>
+<B>[-r] :</B> remove map
+<p>
+<B>[map] :</B> input layer
+<p>
+<p>
+<B>[host] :</B> ossimplanet listner settings "host" (default to "loacalhost")
+<p>
+<p>
+<B>[pport] :</B> ossimplanet listner settings "position message port number" (default to "7000")
+<p>
+<p>
+<B>[dport] :</B> ossimplanet listner settings "data port number" (default to "8000")
+<p>
+
+<H2>EXAMPLE</H2>
+
+Add selected map to ossimplanet screen and zoom to it :
+<div class="code"><pre>
+r.planet.py map=elevation.10m -a
+</pre></div>
+<p>
+Remove selected map from ossimplanet screen :
+<div class="code"><pre>
+r.planet.py map=elevation.10m -r
+</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>
+
+<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/r.planet.py
===================================================================
--- grass-addons/ossim_grass/r.planet/r.planet.py	                        (rev 0)
+++ grass-addons/ossim_grass/r.planet/r.planet.py	2010-02-10 13:20:04 UTC (rev 40907)
@@ -0,0 +1,238 @@
+#!/usr/bin/env python
+################################################################################
+#
+# MODULE:       r.planet.py
+#
+# AUTHOR(S):    Massimo Di Stefano 2010-02-7
+#               
+#
+# PURPOSE:      
+#
+# COPYRIGHT:    (c) 2010 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.
+#
+# REQUIRES:     Ossimplanet
+#                 
+#               
+#
+################################################################################
+
+#%module
+#% description: 
+#% keywords: raster
+#%end
+#%option
+#% key: map
+#% type: string
+#% gisprompt: old,raster,raster
+#% key_desc: name
+#% description: Name of raster map 
+#% required: yes
+#%end
+#%option
+#% key: host
+#% type: string
+#% key_desc: host
+#% answer: 127.0.0.1
+#% description: Host
+#% required : no
+#%end
+#%option
+#% key: dport
+#% type: double
+#% key_desc: dport
+#% answer: 8000
+#% description: Data Port 
+#% required : no
+#%end
+#%option
+#% key: pport
+#% type: double
+#% key_desc: port
+#% answer: 7000
+#% description: Position Port 
+#% required : no
+#%end
+#%flag
+#% key: a
+#% description: Add raster
+#%END
+#%flag
+#% key: r
+#% description: Remove raster
+#%END
+
+
+
+import sys
+import os
+import socket
+import grass.script as grass
+import osgeo.gdal as gdal
+
+def main():
+	add = flags['a']
+	remove = flags['r']
+	host = options['host']
+	dport = options['dport']
+	pport = options['pport']
+	grassenv = grass.gisenv()
+	mappa = options['map'].replace("@"," ")
+	mappa = mappa.split()
+	
+	nflags = len(filter(None, [add, remove]))
+	if nflags > 1:
+		grass.run_command('g.message' , message = 'Cannot add & remove a map at same time.')
+	if nflags < 1:
+		grass.run_command('g.message' , message = 'No action requested , please choose one from "-a : add" or "-r : remove" flags.')
+	try :
+		rasterpath = os.path.join(grassenv['GISDBASE'], grassenv['LOCATION_NAME'], mappa[1], 'cellhd') 
+		mapfile = os.path.join(rasterpath, mappa[0])
+		vrtdir = os.path.join(grassenv['GISDBASE'], grassenv['LOCATION_NAME'], mappa[1], 'vrt')
+	except :
+		rasterpath = os.path.join(grassenv['GISDBASE'], grassenv['LOCATION_NAME'], grassenv['MAPSET'], 'cellhd')
+		mapfile = os.path.join(rasterpath, mappa[0])   
+		vrtdir = os.path.join(grassenv['GISDBASE'], grassenv['LOCATION_NAME'], grassenv['MAPSET'], 'vrt')
+	d = os.path.dirname(vrtdir)
+	if not os.path.exists(d):
+		os.makedirs(d)
+	vrtfilename =  mappa[0] + '.vrt'
+	output = os.path.join(vrtdir, vrtfilename) 
+	if not os.path.exists(output):
+		gdal.GetDriverByName('VRT').CreateCopy(output,gdal.Open(mapfile))
+		#grass.run_command('r.out.gdal', format = 'VRT', type = 'Float64', input = mappa[0] , output = '%s' % (output))
+	proj_info = projinfo()
+	unit = proj_info['units']
+	if unit.lower() == 'meters':
+		zoom_position = setCPRJ(options['map'])
+	if unit == 'Degrees':
+		zoom_position = setCLL(options['map'])
+	lat = zoom_position[0]
+	lon = zoom_position[1]
+	distance = zoom_position[2]
+	if add :
+		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
+	if remove :
+		removefile(output,host,dport)
+		print 'Removed raster file :', mappa[0]
+
+
+def addfile(output,host,dport):
+	ossim_data_xml = "<Add target=':idolbridge'><Image groupType='groundTexture'><filename>%s</filename> <id>%s</id><name>%s</name></Image></Add>" % (output,output,output)
+	ossimdata = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+	ossimdata.connect((host, int(dport)))
+	ossimdata.send(ossim_data_xml)
+	ossimdata.close()
+
+def zoomto(lon,lat,distance,host,pport):
+	ossim_zoom_xml = '<Set target=":navigator" vref="wgs84"><Camera><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>0</heading><pitch>0</pitch><roll>0</roll><altitudeMode>absolute</altitudeMode><range>%s</range></Camera></Set>' % (lon, lat, distance, distance)
+	ossimposition = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+	ossimposition.connect((host, int(pport)))  
+	ossimposition.send(ossim_zoom_xml)
+	ossimposition.close()
+
+def removefile(output,host,dport):
+	ossimdata = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+	ossimdata.connect((host, int(dport)))
+	ossim_data_xml = "<Remove target=':idolbridge' id='%s' />" % (output)
+	ossimdata.send(ossim_data_xml)
+	ossimdata.close()
+
+
+def addzoom(output,lon,lat,distance,host,dport,pport):
+	addfile(output,host,dport)
+	zoomto(lon,lat,distance,host,pport)
+
+
+def projinfo():
+	units = grass.read_command("g.proj", flags='p')
+	units = units.replace('-','')
+	units = grass.parse_key_val(units, ':')
+	units_key = units.keys()
+	for i in units_key :
+		key_value = str(units[i]).strip()
+		units[i] = key_value
+	return units
+
+
+
+def setCLL(map):
+	center = []
+	info_region = grass.read_command('g.region', flags = 'cael', rast = '%s' % (map)) 
+	dict_region = grass.parse_key_val(info_region, ':')
+	lon = dict_region['east-west center']	
+	lat = dict_region['north-south center']
+	lon = str(lon)
+	lat = str(lat)
+	lon = lon.replace(':', " ")
+	lat = lat.replace(':', " ")
+	if lat[-1] == 'N':
+		signlat = 1
+	if lat[-1] == 'S':
+		signlat = -1
+	if lon[-1] == 'E':
+		signlon = 1
+	if lon[-1] == 'W':
+		signlon = -1
+	lat = lat[:-1] 
+	lon = lon[:-1]
+	lat = [float(i) for i in lat.split()]
+	lon = [float(i) for i in lon.split()]
+	lat = (lat[0] + (lat[1] / 60) + lat[2] / 3600) * float(signlat)
+	lon = (lon[0] + (lon[1] / 60) + lon[2] / 3600) * float(signlon)
+	ns = float(dict_region['north-south extent'])
+	we = float(dict_region['east-west extent'])
+	distance = (ns + we) / 2
+	center.append(lat)
+	center.append(lon)
+	center.append(distance)
+	return center
+
+
+
+def setCPRJ(map):
+	center = []
+	info_region = grass.read_command('g.region', flags = 'ael', rast = '%s' % (map)) 
+	dict_region = grass.parse_key_val(info_region, ':')
+	lon = dict_region['center longitude']	
+	lat = dict_region['center latitude']
+	lon = str(lon)
+	lat = str(lat)
+	lon = lon.replace(':', " ")
+	lat = lat.replace(':', " ")
+	if lat[-1] == 'N':
+		signlat = 1
+	if lat[-1] == 'S':
+		signlat = -1
+	if lon[-1] == 'E':
+		signlon = 1
+	if lon[-1] == 'W':
+		signlon = -1
+	lat = lat[:-1] 
+	lon = lon[:-1]
+	lat = [float(i) for i in lat.split()]
+	lon = [float(i) for i in lon.split()]
+	lat = (lat[0] + (lat[1] / 60) + lat[2] / 3600) * float(signlat)
+	lon = (lon[0] + (lon[1] / 60) + lon[2] / 3600) * float(signlon)
+	ns = float(dict_region['north-south extent'])
+	we = float(dict_region['east-west extent'])
+	distance = (ns + we) / 2
+	center.append(lat)
+	center.append(lon)
+	center.append(distance)
+	return center
+
+
+if __name__ == "__main__":
+	options, flags = grass.parser()
+	sys.exit(main())
+
+


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



More information about the grass-commit mailing list