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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 24 06:44:20 EDT 2010


Author: epifanio
Date: 2010-04-24 06:44:19 -0400 (Sat, 24 Apr 2010)
New Revision: 42013

Added:
   grass-addons/ossim_grass/ossim_grass/
   grass-addons/ossim_grass/ossim_grass/Makefile
   grass-addons/ossim_grass/ossim_grass/r.planet/
   grass-addons/ossim_grass/ossim_grass/r.planet/Makefile
   grass-addons/ossim_grass/ossim_grass/r.planet/description.html
   grass-addons/ossim_grass/ossim_grass/r.planet/r.planet.py
   grass-addons/ossim_grass/ossim_grass/v.planet/
   grass-addons/ossim_grass/ossim_grass/v.planet/Makefile
   grass-addons/ossim_grass/ossim_grass/v.planet/description.html
   grass-addons/ossim_grass/ossim_grass/v.planet/ogrTovrt.py
   grass-addons/ossim_grass/ossim_grass/v.planet/v.planet.py
Log:


Added: grass-addons/ossim_grass/ossim_grass/Makefile
===================================================================
--- grass-addons/ossim_grass/ossim_grass/Makefile	                        (rev 0)
+++ grass-addons/ossim_grass/ossim_grass/Makefile	2010-04-24 10:44:19 UTC (rev 42013)
@@ -0,0 +1,13 @@
+MODULE_TOPDIR = ..
+
+SUBDIRS = \
+	r.planet \
+	v.planet
+
+include $(MODULE_TOPDIR)/include/Make/Dir.make
+
+default: htmldir
+
+htmldir: subdirs
+
+clean: cleansubdirs

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

Added: grass-addons/ossim_grass/ossim_grass/r.planet/description.html
===================================================================
--- grass-addons/ossim_grass/ossim_grass/r.planet/description.html	                        (rev 0)
+++ grass-addons/ossim_grass/ossim_grass/r.planet/description.html	2010-04-24 10:44:19 UTC (rev 42013)
@@ -0,0 +1,42 @@
+<h2>DESCRIPTION</h2>
+
+
+<em><b>r.planet.py : </b></em> Scripts to : 
+<p>
+- generate vrt layer from a selected grass raster layer and add/zoomTo/remove the data from/to ossimplanet using the ossimplanet tcp listner.
+<p>
+- generate ossimplanet 3d tiles from elevation data.
+
+<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>
+Generate 3D tiles :
+<div class="code"><pre>
+r.planet.py map=elevation.10m -d tile=3601
+</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/ossim_grass/r.planet/r.planet.py
===================================================================
--- grass-addons/ossim_grass/ossim_grass/r.planet/r.planet.py	                        (rev 0)
+++ grass-addons/ossim_grass/ossim_grass/r.planet/r.planet.py	2010-04-24 10:44:19 UTC (rev 42013)
@@ -0,0 +1,370 @@
+#!/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: integer
+#% key_desc: dport
+#% answer: 8000
+#% description: Data Port 
+#% required : no
+#%end
+#%option
+#% key: pport
+#% type: integer
+#% key_desc: port
+#% answer: 7000
+#% description: Position Port 
+#% 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
+#%flag
+#% key: a
+#% description: Add raster
+#%END
+#%flag
+#% key: r
+#% description: Remove raster
+#%END
+#%flag
+#% key: d
+#% description: Orthoigen 
+#%END
+#%flag
+#% key: m
+#% description: MPI 
+#%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']
+    orthoigen = flags['d']
+    mpi = flags['m']
+    host = options['host']
+    dport = options['dport']
+    pport = options['pport']
+    tile = options['tile']
+    np = options['np']
+    grassenv = grass.gisenv()
+    mappa = options['map'].replace("@"," ")
+    mappa = mappa.split()
+    
+    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.')
+    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/raster/')
+        #print vrtdir
+    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/raster/')
+        #print vrtdir
+    d = os.path.dirname(vrtdir)
+    if not os.path.exists(d):
+        os.makedirs(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.lower() == 'metres':
+        zoom_position = setCPRJ(options['map'])
+    if unit.lower() == 'degrees':
+        zoom_position = setCLL(options['map'])
+    lat = zoom_position[0]
+    lon = zoom_position[1]
+    distance = zoom_position[2]
+    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]+'/')
+                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'
+
+def exportiff(infile,outfile):
+    gdal.GetDriverByName('GTiff').CreateCopy(outfile,gdal.Open(infile))
+
+
+
+def addfile(output,host,dport):
+    overview = output.replace('.vrt','.ovr')
+    if not os.path.isfile(overview):
+        makeoverview(output)
+    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
+
+
+def makedir(path):
+    d = os.path.dirname(path)
+    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'
+    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 = 'export DYLD_FRAMEWORK_PATH=/Users/sasha/OssimBuilds/Release/ ; '
+    if mpi :
+        instr += 'mpirun -np %s ' % np
+        instr += orthoigenexec
+    else :
+        instr += orthoigenexec
+    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
+
+
+def makeoverview(input):
+    if systemplatform == 'Darwin':
+        img2rrexec = '/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)
+
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())
+
+


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

Added: grass-addons/ossim_grass/ossim_grass/v.planet/Makefile
===================================================================
--- grass-addons/ossim_grass/ossim_grass/v.planet/Makefile	                        (rev 0)
+++ grass-addons/ossim_grass/ossim_grass/v.planet/Makefile	2010-04-24 10:44:19 UTC (rev 42013)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.planet.py
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/ossim_grass/ossim_grass/v.planet/description.html
===================================================================
--- grass-addons/ossim_grass/ossim_grass/v.planet/description.html	                        (rev 0)
+++ grass-addons/ossim_grass/ossim_grass/v.planet/description.html	2010-04-24 10:44:19 UTC (rev 42013)
@@ -0,0 +1,34 @@
+<h2>DESCRIPTION</h2>
+
+
+<em><b>v.planet.py : </b></em> Scripts to generate vrt layer from a selected grass vector layer and add/zoomTo/remove the data to ossimplanet using the ossimplanet tcp listner.
+
+
+<h2>EXAMPLE</h2>
+
+Add selected map to ossimplanet screen and zoom to it :
+<div class="code"><pre>
+v.planet.py map=elevation.10m -a
+</pre></div>
+<p>
+Remove selected map from ossimplanet screen :
+<div class="code"><pre>
+v.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="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/ossim_grass/v.planet/ogrTovrt.py
===================================================================
--- grass-addons/ossim_grass/ossim_grass/v.planet/ogrTovrt.py	                        (rev 0)
+++ grass-addons/ossim_grass/ossim_grass/v.planet/ogrTovrt.py	2010-04-24 10:44:19 UTC (rev 42013)
@@ -0,0 +1,139 @@
+#!/usr/bin/env python
+################################################################################
+#
+# MODULE:       ogrTovrt.py
+#
+# AUTHOR(S):    Massimo Di Stefano 2010-02-7 
+#               relicensed with permission by 
+#               Frank Warmerdam - warmerdam at pobox.com - original author
+#               original code : ogr2vrt.py
+#               
+#
+# PURPOSE:      Create OGR VRT from source datasource and 
+#               OMD associated style-file
+#
+# COPYRIGHT:    (c) 2010 by Massimo Di Stefano 
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+# REQUIRES:     Gdal - python
+#                 
+#               
+#
+################################################################################
+
+
+try:
+	from osgeo import osr, ogr, gdal
+except ImportError:
+	import osr, ogr, gdal
+
+import string
+import sys
+
+def GeomType2Name( type ):
+	if type == ogr.wkbUnknown:
+		return 'wkbUnknown'
+	elif type == ogr.wkbPoint:
+		return 'wkbPoint'
+	elif type == ogr.wkbLineString:
+		return 'wkbLineString'
+	elif type == ogr.wkbPolygon:
+		return 'wkbPolygon'
+	elif type == ogr.wkbMultiPoint:
+		return 'wkbMultiPoint'
+	elif type == ogr.wkbMultiLineString:
+		return 'wkbMultiLineString'
+	elif type == ogr.wkbMultiPolygon:
+		return 'wkbMultiPolygon'
+	elif type == ogr.wkbGeometryCollection:
+		return 'wkbGeometryCollection'
+	elif type == ogr.wkbNone:
+		return 'wkbNone'
+	elif type == ogr.wkbLinearRing:
+		return 'wkbLinearRing'
+	else:
+		return 'wkbUnknown'
+		
+def Esc(x):
+	return gdal.EscapeString( x, gdal.CPLES_XML )
+
+def makestile(outfile, brush, pen, size, fill, thickness):
+	brush = brush.split(',')
+	pen = pen.split(',')
+	size = size.split(',')
+	outfile = outfile.replace('.vrt','')
+	outfile = outfile+'.omd'
+	omd = '// vector file rendering options\n'
+	omd += 'brush_color: %s %s %s \n' % (brush[0], brush[1], brush[2])
+	omd += 'pen_color: %s %s %s \n' % (pen[0], pen[1], pen[2])
+	omd += 'point_width_height: %s %s \n' % (size[0], size[1])
+	omd += 'fill_flag: %s \n' % (fill)
+	omd += 'thickness: %s \n' % (thickness)
+	open(outfile,'w').write(omd)
+
+def ogrvrt(infile,outfile):
+	layer_list = []
+	relative = "0"
+	schema=0
+	src_ds = ogr.Open( infile, update = 0 )
+	if len(layer_list) == 0:
+		for layer in src_ds:
+			layer_list.append( layer.GetLayerDefn().GetName() )
+	vrt = '<OGRVRTDataSource>\n'
+	for name in layer_list:
+		layer = src_ds.GetLayerByName(name)
+		layerdef = layer.GetLayerDefn()
+		vrt += '  <OGRVRTLayer name="%s">\n' % Esc(name)
+		vrt += '    <SrcDataSource relativeToVRT="%s" shared="%d">%s</SrcDataSource>\n' \
+		% (relative,not schema,Esc(infile))
+		if schema:
+			vrt += '    <SrcLayer>@dummy@</SrcLayer>\n' 
+		else:
+			vrt += '    <SrcLayer>%s</SrcLayer>\n' % Esc(name)
+		vrt += '    <GeometryType>%s</GeometryType>\n' \
+		% GeomType2Name(layerdef.GetGeomType())
+		srs = layer.GetSpatialRef()
+		if srs is not None:
+			vrt += '    <LayerSRS>%s</LayerSRS>\n' \
+			% (Esc(srs.ExportToWkt()))
+		# Process all the fields.
+		for fld_index in range(layerdef.GetFieldCount()):
+			src_fd = layerdef.GetFieldDefn( fld_index )
+			if src_fd.GetType() == ogr.OFTInteger:
+				type = 'Integer'
+			elif src_fd.GetType() == ogr.OFTString:
+				type = 'String'
+			elif src_fd.GetType() == ogr.OFTReal:
+				type = 'Real'
+			elif src_fd.GetType() == ogr.OFTStringList:
+				type = 'StringList'
+			elif src_fd.GetType() == ogr.OFTIntegerList:
+				type = 'IntegerList'
+			elif src_fd.GetType() == ogr.OFTRealList:
+				type = 'RealList'
+			elif src_fd.GetType() == ogr.OFTBinary:
+				type = 'Binary'
+			elif src_fd.GetType() == ogr.OFTDate:
+				type = 'Date'
+			elif src_fd.GetType() == ogr.OFTTime:
+				type = 'Time'
+			elif src_fd.GetType() == ogr.OFTDateTime:
+				type = 'DateTime'
+			else:
+				type = 'String'
+				
+			vrt += '    <Field name="%s" type="%s"' \
+			% (Esc(src_fd.GetName()), type)
+			if not schema:
+				vrt += ' src="%s"' % Esc(src_fd.GetName())
+			if src_fd.GetWidth() > 0:
+				vrt += ' width="%d"' % src_fd.GetWidth()
+			if src_fd.GetPrecision() > 0:
+				vrt += ' precision="%d"' % src_fd.GetPrecision()
+			vrt += '/>\n'
+		vrt += '  </OGRVRTLayer>\n'
+	vrt += '</OGRVRTDataSource>\n' 
+	open(outfile,'w').write(vrt)

Added: grass-addons/ossim_grass/ossim_grass/v.planet/v.planet.py
===================================================================
--- grass-addons/ossim_grass/ossim_grass/v.planet/v.planet.py	                        (rev 0)
+++ grass-addons/ossim_grass/ossim_grass/v.planet/v.planet.py	2010-04-24 10:44:19 UTC (rev 42013)
@@ -0,0 +1,311 @@
+#!/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: vector
+#%end
+#%option
+#% key: map
+#% type: string
+#% gisprompt: old,vector,vector
+#% key_desc: name
+#% description: Name of vector 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: integer
+#% key_desc: dport
+#% answer: 8000
+#% description: Data Port 
+#% required : no
+#%end
+#%option
+#% key: pport
+#% type: integer
+#% key_desc: port
+#% answer: 7000
+#% description: Position Port 
+#% required : no
+#%end
+#%flag
+#% key: a
+#% description: Add vector
+#%END
+#%flag
+#% key: r
+#% description: Remove vector
+#%END
+#%option
+#% key: brush
+#% type: string
+#% key_desc: brush
+#% description: brush color  
+#% required : no
+#%end
+#%option
+#% key: pen
+#% type: string
+#% key_desc: pen
+#% description: pen color  
+#% required : no
+#%end
+#%option
+#% key: size
+#% type: string
+#% key_desc: size
+#% description: size 
+#% required : no
+#%end
+#%option
+#% key: fill
+#% type: string
+#% key_desc: fill
+#% description: fill 
+#% required : no
+#%end
+#%option
+#% key: thickness
+#% type: string
+#% key_desc: thickness
+#% description: thickness 
+#% required : no
+#% answer: 1
+#%end
+
+import sys
+import os
+import socket
+import grass.script as grass
+import string
+
+try:
+    from osgeo import osr, ogr, gdal
+except ImportError:
+    import osr, ogr, gdal
+
+from ogrTovrt import ogrvrt #, makestile
+
+
+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 :
+        vectorpath = os.path.join(grassenv['GISDBASE'], grassenv['LOCATION_NAME'], mappa[1], 'vector' , mappa[0] ) 
+        mapfile = os.path.join(vectorpath, 'head')
+        vrtdir = os.path.join(grassenv['GISDBASE'], grassenv['LOCATION_NAME'], mappa[1], 'vrt', 'vector/')
+    except :
+        vectorpath = os.path.join(grassenv['GISDBASE'], grassenv['LOCATION_NAME'], grassenv['MAPSET'], mappa[0] )
+        mapfile = os.path.join(vectorpath, 'head' )   
+        vrtdir = os.path.join(grassenv['GISDBASE'], grassenv['LOCATION_NAME'], grassenv['MAPSET'], 'vrt', 'vector/')
+    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):
+        ogrvrt(mapfile,output)
+        print 'try to make omd'
+        makestile(output, options['brush'], options['pen'], options['size'], options['fill'], options['thickness'])
+    proj_info = projinfo()
+    unit = proj_info['units']
+    if unit.lower() == 'meters':
+        zoom_position = setCPRJ(options['map'])
+    if unit.lower() == 'metres':
+        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 :
+        try:
+            addzoom(output,lon,lat,distance,host,dport,pport)
+            print 'Added vector 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 vector file :', mappa[0]
+
+
+def addfile(output,host,dport):
+    overview = output.replace('.vrt','.ovr')
+    if not os.path.isfile(overview):
+        makeoverview(output)
+    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', vect = '%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', vect = '%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
+
+def makeoverview(input):
+    print 'vector object should alredy have internal preview, make overview skipped'
+    #os.system("ossim-img2rr %s" % input)
+    
+
+def makestile(outfile, brush, pen, size, fill, thickness):
+    brush = brush.split(',')
+    pen = pen.split(',')
+    size = size.split(',')
+    print brush, pen, size
+    outfile = outfile.replace('.vrt','')
+    outfile = outfile+'.omd'
+    omd = '// vector file rendering options\n'
+    omd += 'brush_color: %s %s %s \n' % (brush[0], brush[1], brush[2])
+    omd += 'pen_color: %s %s %s \n' % (pen[0], pen[1], pen[2])
+    omd += 'point_width_height: %s %s \n' % (size[0], size[1])
+    omd += 'fill_flag: %s \n' % (fill)
+    omd += 'thickness: %s \n' % (thickness)
+    open(outfile,'w').write(omd)
+    print omd
+
+
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())
+
+


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



More information about the grass-commit mailing list