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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 10 06:49:41 EDT 2010


Author: epifanio
Date: 2010-04-10 06:49:41 -0400 (Sat, 10 Apr 2010)
New Revision: 41770

Modified:
   grass-addons/ossim_grass/r.planet/r.planet.py
   grass-addons/ossim_grass/v.planet/v.planet.py
Log:
adjusted indentation, added check for overview files (if no present make it, this avoid a possible crash when ossimplanet tries to build overview itself), fixed units parametres in the zoom-to action. 

Modified: grass-addons/ossim_grass/r.planet/r.planet.py
===================================================================
--- grass-addons/ossim_grass/r.planet/r.planet.py	2010-04-10 10:46:16 UTC (rev 41769)
+++ grass-addons/ossim_grass/r.planet/r.planet.py	2010-04-10 10:49:41 UTC (rev 41770)
@@ -42,7 +42,7 @@
 #%end
 #%option
 #% key: dport
-#% type: double
+#% type: integer
 #% key_desc: dport
 #% answer: 8000
 #% description: Data Port 
@@ -50,7 +50,7 @@
 #%end
 #%option
 #% key: pport
-#% type: double
+#% type: integer
 #% key_desc: port
 #% answer: 7000
 #% description: Position Port 
@@ -84,242 +84,250 @@
 import osgeo.gdal as gdal
 
 def main():
-	add = flags['a']
-	remove = flags['r']
-	orthoigen = flags['d']
-	host = options['host']
-	dport = options['dport']
-	pport = options['pport']
-	tile = options['tile']
-	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 == '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'
+    add = flags['a']
+    remove = flags['r']
+    orthoigen = flags['d']
+    host = options['host']
+    dport = options['dport']
+    pport = options['pport']
+    tile = options['tile']
+    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))
+    gdal.GetDriverByName('GTiff').CreateCopy(outfile,gdal.Open(infile))
 
 
 
 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()
-	
+    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()
-
+    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()
+    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)
+    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
+    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
+    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
+    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)
+    d = os.path.dirname(path)
+    if not os.path.exists(d):
+        os.makedirs(d)
 
 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 = 'export DYLD_FRAMEWORK_PATH=/Users/sasha/OssimBuilds/Release/ ; '
-	instr += '/Users/sasha/OssimBuilds/Release/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
+    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/ ; '
+    instr += '/Users/sasha/OssimBuilds/Release/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
 
 
+def makeoverview(input):
+    os.system("ossim-img2rr %s" % input)
+
+
 if __name__ == "__main__":
-	options, flags = grass.parser()
-	sys.exit(main())
+    options, flags = grass.parser()
+    sys.exit(main())
 
 

Modified: grass-addons/ossim_grass/v.planet/v.planet.py
===================================================================
--- grass-addons/ossim_grass/v.planet/v.planet.py	2010-04-10 10:46:16 UTC (rev 41769)
+++ grass-addons/ossim_grass/v.planet/v.planet.py	2010-04-10 10:49:41 UTC (rev 41770)
@@ -107,173 +107,185 @@
 import string
 
 try:
-	from osgeo import osr, ogr, gdal
+    from osgeo import osr, ogr, gdal
 except ImportError:
-	import osr, ogr, gdal
+    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)
-		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 == '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 vector file :', mappa[0]
-		print 'Camera positioned to : '
-		print 'Longitude = ',lon
-		print 'Latitude = ', lat
-		print 'Altitude = ' , distance
-	if remove :
-		removefile(output,host,dport)
-		print 'Removed vector file :', mappa[0]
+    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)
+        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):
-	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()
+    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()
+    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()
+    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)
+    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
+    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
+    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
+    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):
+    os.system("ossim-img2rr %s" % input)
 
+
+
 if __name__ == "__main__":
-	options, flags = grass.parser()
-	sys.exit(main())
+    options, flags = grass.parser()
+    sys.exit(main())
 
 



More information about the grass-commit mailing list