[GRASS-SVN] r47116 - in grass-addons/grass7/raster/r.modis:
libmodis r.modis.import
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 14 13:16:37 EDT 2011
Author: lucadelu
Date: 2011-07-14 10:16:37 -0700 (Thu, 14 Jul 2011)
New Revision: 47116
Modified:
grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py
grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.html
grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py
Log:
add support for more projection system
Modified: grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py
===================================================================
--- grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py 2011-07-14 14:37:52 UTC (rev 47115)
+++ grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py 2011-07-14 17:16:37 UTC (rev 47116)
@@ -38,8 +38,7 @@
for i in listproj:
ilist = i.split(':')
proj[ilist[0].strip()] = ilist[1].strip()
- towgs = parse_command('g.proj',flags='d')
- proj['towgs84']=towgs['towgs84']
+ proj.update(parse_command('g.proj',flags='j'))
return proj
class product:
@@ -92,23 +91,65 @@
class projection:
"""Definition of projection for converting from sinusoidal projection to
another one. Not all projection systems are supported"""
- def __init__(self,value):
- self.proj = value
+ def __init__(self):
+ self.proj = get_proj()
+ self.val = self.proj['proj']
+ self.dat = self.proj['datum']
self.projections = {'ll':'GEO', 'lcc':'LAMBERT CONFORMAL CONIC',
'merc':'MERCATOR', 'polar':'POLAR STEREOGRAPHIC', 'utm':'UTM',
'tmerc':'TRANSVERSE MERCATOR'}
-
- def returned(self):
- return self.projections[self.proj]
-
-class datum:
- """Definition of datum for converting from sinusoidal projection. Not all
- datums are supported"""
- def __init__(self,value):
- self.datum = value
self.datumlist = {'none':'NONE', 'nad27':'NAD27', 'nad83':'NAD83',
'wgs66':'WGS66', 'wgs72':'WGS72', 'wgs84':'WGS84'}
def returned(self):
- return self.datumlist[self.datum]
+ """Return the projection in the MRT style"""
+ return self.projections[self.val]
+ def _par(self,key):
+ """Function use in return_params"""
+ if self.proj[key]:
+ SMinor = self.proj[key]
+ else:
+ SMinor = 0.0
+
+ def return_params(self):
+ """ Return the 13 paramaters for parameter file """
+ if self.val == 'll' or self.val == 'utm':
+ return '( 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 )'
+ elif self.val == 'lcc':
+ SMajor = self._par('+a')
+ SMinor = self._par('+b')
+ STDPR1 = self._par('+lat_1')
+ STDPR2 = self._par('+lat_2')
+ CentMer = self._par('+lon_0')
+ CentLat = self._par('+lat_0')
+ FE = self._par('+x_0')
+ FN = self._par('+y_0')
+ st = '( %i %i %d %d %d %d %d %d 0.0 0.0 0.0 0.0 0.0 0.0 0.0 )' % (
+ SMajor, SMinor, STDPR1, STDPR2, CentMer, CentLat, FE, FN )
+ return st
+ elif self.val == 'merc' or self.val == 'polar' or self.val == 'tmerc':
+ SMajor = self._par('+a')
+ SMinor = self._par('+b')
+ CentMer = self._par('+lon_0')
+ if self.val == 'tmerc':
+ Factor = self._par('+k_0')
+ else:
+ Factor = 0.0
+ TrueScale = self._par('+lat_ts')
+ FE = self._par('+x_0')
+ FN = self._par('+y_0')
+ st = '( %i %i %d 0.0 %d %d %d %d 0.0 0.0 0.0 0.0 0.0 0.0 0.0 )' % (
+ SMajor, SMinor, Factor, CentMer, TrueScale, FE, FN )
+ return st
+ else:
+ grass.fatal(_('Projection not supported, please contact the' \
+ 'GRASS-dev mailing list'))
+
+ def datum(self):
+ """Return the datum in the MRT style"""
+ return self.datumlist[self.dat]
+
+ def utmzone(self):
+ """Return the utm zone number"""
+ return self.proj['zone']
Modified: grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.html
===================================================================
--- grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.html 2011-07-14 14:37:52 UTC (rev 47115)
+++ grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.html 2011-07-14 17:16:37 UTC (rev 47116)
@@ -13,23 +13,32 @@
<b>Warning</b>:
<ul>
- <li>Currently it's tested and It work correctly only with Lat/Long</li>
- <li>Currently the mosaic flag it is not working</li>
+ <li>Currently it's tested only with Lat/Long, but also the follow projection systems are supported: Lambert Conformal Conic, Mercator, Polar Stereographic, Transverse Mercator, Universal Transverse Mercator</li>
</ul>
<h2>EXAMPLES</h2>
-Import file with the default subset without QA layer
+Import a single file with the default subset without QA layer
<div class="code"><pre>
+ r.modis.import dsn=/path/to/file mrtpath=/path/to/mrt
+</pre></div>
+
+Import a single file with your own subset of layers
+<div class="code"><pre>
+ r.modis.import dsn=/path/to/file mrtpath=/path/to/mrt spectral="( 1 0 1 0)"
+</pre></div>
+
+Import more files with the default subset without QA layer
+<div class="code"><pre>
r.modis.import filename=/path/to/listfile mrtpath=/path/to/mrt
</pre></div>
-Import file with the default subset with QA layer
+Import more files like a daily mosais with the default subset with QA layer
<div class="code"><pre>
- r.modis.import -q filename=/path/to/listfile mrtpath=/path/to/mrt
+ r.modis.import -qm filename=/path/to/listfile mrtpath=/path/to/mrt
</pre></div>
-Import file with the your own subset
+Import more files with your own subset of layers
<div class="code"><pre>
r.modis.import filename=/path/to/listfile mrtpath=/path/to/mrt spectral="( 1 )"
</pre></div>
Modified: grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py
===================================================================
--- grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py 2011-07-14 14:37:52 UTC (rev 47115)
+++ grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py 2011-07-14 17:16:37 UTC (rev 47116)
@@ -90,7 +90,7 @@
sys.path.append(libmodis)
# try to import pymodis (modis) and some class for r.modis.download
try:
- from rmodislib import resampling, product, get_proj, projection, datum
+ from rmodislib import resampling, product, get_proj, projection
from modis import parseModis, convertModis, createMosaic
except ImportError:
pass
@@ -145,14 +145,11 @@
# create parseModis class and the parameter file
pm = parseModis(hdf)
# return projection and datum
- inproj = get_proj()
- proj = projection(inproj['proj']).returned()
- if proj != 'GEO':
- grass.fatal(_('Projection different to Lat/Long is not working yet. Sorry'))
- return 0
- dat = datum(inproj['datum']).returned()
+ projObj = projection()
+ proj = projObj.returned()
+ dat = projObj.datum()
if proj == 'UTM':
- zone = prod['zone']
+ zone = projObj.utmzone()
else:
zone = None
cod = os.path.split(hdf)[1].split('.')[0]
@@ -163,8 +160,8 @@
spectr = spectral(opts, cod,q)
# resampling
resampl = resampling(opts['resampl']).returned()
- # projpar TO DO
- projpar = '( 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 )'
+ # projpar
+ projpar = projObj.return_params()
return pm.confResample(spectr, None, None, dat, resampl, proj, zone, projpar)
def import_tif(hdf,basedir,rem,target=False):
@@ -173,16 +170,24 @@
prefix = os.path.split(hdf)[1].rstrip('.hdf')
# list of tif files
tifiles = glob.glob1(basedir, prefix + "*.tif")
+ # check if is in latlong location to set flag l
+ if projection().val == 'll':
+ f = "l"
+ else:
+ f = None
# for each file import it
for t in tifiles:
basename = os.path.splitext(t)[0]
name = os.path.join(basedir,t)
- grass.run_command('r.in.gdal', input = name,
- output = basename, flags = "l", overwrite = True, quiet = True)
- if rem:
- os.remove(name)
- if target:
- shutil.move(name,target)
+ try:
+ grass.run_command('r.in.gdal', input = name,
+ output = basename, flags = f, overwrite = True, quiet = True)
+ if rem:
+ os.remove(name)
+ if target:
+ shutil.move(name,target)
+ except:
+ grass.fatal(_('Error during import'))
return 0
def single(options,remove,qa):
More information about the grass-commit
mailing list