Browse Source

Generate an ISIS3 map template from actual location

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57127 15284696-431f-4ddb-bdfa-cd5b030d7da7
Yann Chemin 12 years ago
parent
commit
661080a162
4 changed files with 181 additions and 0 deletions
  1. 1 0
      scripts/Makefile
  2. 7 0
      scripts/g.isis3mt/Makefile
  3. 15 0
      scripts/g.isis3mt/g.isis3mt.html
  4. 158 0
      scripts/g.isis3mt/g.isis3mt.py

+ 1 - 0
scripts/Makefile

@@ -15,6 +15,7 @@ SUBDIRS = \
 	db.test \
 	g.extension \
 	g.extension.rebuild.all \
+	g.isis3mt \
 	g.manual \
 	i.image.mosaic \
 	i.in.spotvgt \

+ 7 - 0
scripts/g.isis3mt/Makefile

@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM=g.isis3mt
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

+ 15 - 0
scripts/g.isis3mt/g.isis3mt.html

@@ -0,0 +1,15 @@
+<h2>DESCRIPTION</h2>
+
+<em>g.isis3mt</em> Generates an ISIS3 map template file according to the
+ current GRASS projection parameters
+
+<h2>NOTE</h2>
+
+The ISIS3 user should use  matchmap=yes in cam2map
+
+<h2>AUTHOR</h2>
+
+Alessandro Frigeri, INA, Ispra, Italy
+Added to GRASS 7 by Yann Chemin
+
+<p><i>Last changed: $Date$</i>

+ 158 - 0
scripts/g.isis3mt/g.isis3mt.py

@@ -0,0 +1,158 @@
+#!/usr/bin/env python
+#
+############################################################################
+#
+# MODULE:      g.isis3mt
+# AUTHOR(S):   Alessandro Frigeri; 
+# PURPOSE:     Generates an ISIS3 map template file according to the current
+#              GRASS projection parameters
+# COPYRIGHT:   (C) 2009,2010 by Alessandro Frigeri for 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.
+# HISTORY:     Apr 15th, 2010: Time for the first public release
+#              Sep 15th, 2010: added LatLon Range and mpp/ppd resolution 
+#                              options
+# 
+#############################################################################
+
+# TODO
+#  Add a note to the user to use  matchmap=yes in cam2map
+ 
+#%module
+#%  description: Generates an ISIS3 map template file according to the current GRASS coordinate reference system
+#%  keywords: generic, projection
+#%end
+
+#%option
+#% key: body
+#% type: string
+#% description: Target planetary body
+#% options: MOON,MERCURY,VENUS,MARS,Phobos,Deimos,JUPITER,Amalthea,Io,Europa,Ganymede,Callisto,SATURN,Janus,Epimetheus,Mimas,Enceladus,Tethys,Dione,Rhea,Titan,Hyperion,Iapetus,URANUS,Miranda,Ariel,Umbriel,Titania,Oberon,NEPTUNE
+#% required : yes
+#%end
+
+#%option
+#% key: out
+#% type: string
+#% gisprompt: new_file,file,output
+#% description: Filename for the ISIS3 maptemplate to be generated
+#% required : yes
+#%end
+
+#%option
+#% key: outres
+#% type: double
+#% description: Resolution of the ISIS3 projected data (default is: camera resolution) 
+#% required : no
+#%end
+
+#%Option
+#% key: restype
+#% type: string
+#% required: no
+#% multiple: no
+#% options: mpp,ppd
+#% description: Resolution type: meters per pixel (mpp) or pixels per degree (ppd)
+#% answer: mpp
+#%End
+
+#%flag
+#% key: a
+#% description: Align ISIS3 data to the extents of the current GRASS region 
+#%end
+
+import subprocess,sys,os,platform
+import grass.script as grass
+from grass.lib import gis as grasslib
+from grass.lib import proj as grassproj
+from UserDict import *
+import re,string
+
+if "GISBASE" not in os.environ:
+    print "You must be in GRASS GIS to run this program."
+    sys.exit(1)
+
+# initialize
+grasslib.G_gisinit('')
+
+
+projdict = {'sinu':'Sinusoidal',
+            'merc':'Mercator',
+            'tmerc':'TransverseMercator',
+            'ortho':'Orthographic',
+            'stere':'PolarStereographic',
+            'cc':'SimpleCylindrical',
+            'eqc':'Equirectangular',
+            'lcc':'LambertConformal'
+           }
+
+paradict = {'proj' :'ProjectionName',         # Name of the projection
+            'lon_0':'CenterLongitude',        # Center Longitude
+            'lat_0':'CenterLatitude',         # Center Latitude
+            'k':'ScaleFactor',                # Scale Factor
+            'lat_1':'FirstStandardParallel',  # First standard parallel
+            'lat_2':'SecondStandardParallel', # Second standard parallel
+            'a':'EquatorialRadius',           # semi major axis
+            'b':'PolarRadius',                # semi minor axis
+            'to_meter':None,                  # no map on isis3
+            'y_0':None,  	              # false northing
+            'x_0':None,                       # false easting
+           }
+           
+class IsisMapTemplate(IterableUserDict):
+   def __init__(self,isisdict):      
+      UserDict.__init__(self)      
+      if isisdict is not None:
+          UserDict.__init__(self,isisdict)    
+      self['LatitudeType'] = 'Planetographic'
+      self['LongitudeDirection'] = 'PositiveEast'
+      self['LongitudeDomain'] = '180'
+
+   def dump(self,out):
+       out.write("Group = Mapping\n")
+       keys = self.keys()
+       for k in self.keys():
+           if k != None:               
+              myk = string.rjust(k, 30)
+              myv = string.ljust(self[k], 20)
+              out.write("%s = %s\n"%(myk,myv))
+       out.write("End_Group\nEnd")
+       
+
+def main():
+    isis3 = {}
+    outfile = options['out']
+    body = options['body']
+    pj = grasslib.G_get_projinfo()
+    if options['outres'] and options['restype']=='mpp' : isis3['PixelResolution'] = "%f <meters>"%float(options['outres'])
+    if options['outres'] and options['restype']=='ppd' : isis3['Scale'] = "%f <pixel/degree>"%float(options['outres'])
+    isis3['TargetName'] = body
+    if flags['a']:
+        ret = grass.start_command("g.region", flags="gl", stdout = subprocess.PIPE)
+        exec(ret.communicate()[0])
+        isis3['MinimumLatitude'] = "%f"%min(se_lat,sw_lat)
+        isis3['MaximumLatitude'] = "%f"%max(ne_lat,nw_lat)
+        isis3['MinimumLongitude'] = "%f"%min(sw_long,nw_long)
+        isis3['MaximumLongitude'] = "%f"%max(se_long,ne_long)
+        
+    for p in paradict.keys():
+        if grasslib.G_find_key_value(p, pj):
+            k = paradict[p]
+            v = grasslib.G_find_key_value(p, pj)
+            if p == 'a' or p == 'b': v = v + ' <meters>'
+            if p == 'proj' and v == 'll': sys.exit("This GRASS location is in LatLong, no cartographic projection is set.\nExiting...")
+            if p == 'proj':  k,v = 'ProjectionName', projdict[v]                   
+            isis3[k] = v
+    isis3mt =  IsisMapTemplate(isis3)
+    of = open(outfile,'w')
+    isis3mt.dump(of)
+    sys.stderr.write("Done writing %s ISIS3 MapTemplate file\n"%outfile)     
+    
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()
+
+
+