[GRASS-SVN] r72282 - grass-addons/grass7/raster/r.sentinel/r.sentinel.import

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Feb 26 04:10:12 PST 2018


Author: martinl
Date: 2018-02-26 04:10:12 -0800 (Mon, 26 Feb 2018)
New Revision: 72282

Modified:
   grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.html
   grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.py
Log:
r.sentinel.import: add -p flag to print files to be imported


Modified: grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.html
===================================================================
--- grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.html	2018-02-26 12:01:02 UTC (rev 72281)
+++ grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.html	2018-02-26 12:10:12 UTC (rev 72282)
@@ -29,6 +29,18 @@
 
 <h2>EXAMPLES</h2>
 
+At first, print list of raster files to be imported by <b>-p</b>. For
+each file also projection match with current location is printed
+including detected input data EPSG code.
+
+<div class="code"><pre>
+r.sentinel.import -p input=data
+
+data/S2B_MSIL1C_20180216T102059_N0206_R065_T32UPB_20180216T140508.SAFE/GRANULE/.../T32UPB_20180216T102059_B04.jp2 1 (EPSG: 32632)
+data/S2B_MSIL1C_20180216T102059_N0206_R065_T32UPB_20180216T140508.SAFE/GRANULE/.../T32UPB_20180216T102059_B07.jp2 1 (EPSG: 32632)
+data/S2B_MSIL1C_20180216T102059_N0206_R065_T32UPB_20180216T140508.SAFE/GRANULE/.../T32UPB_20180216T102059_B11.jp2 1 (EPSG: 32632)
+</pre></div>
+
 Import all Sentinel bands found in <i>data</i> directory.
 
 <div class="code"><pre>

Modified: grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.py
===================================================================
--- grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.py	2018-02-26 12:01:02 UTC (rev 72281)
+++ grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.py	2018-02-26 12:10:12 UTC (rev 72282)
@@ -42,8 +42,12 @@
 #% key: c
 #% description: Import cloud masks as vector maps
 #%end
+#%flag
+#% key: p
+#% description: Print raster data to be imported and exit
+#%end
 #%rules
-#% exclusive: -l,-r
+#% exclusive: -l,-r,-p
 #%end
 import os
 import sys
@@ -118,9 +122,27 @@
             gs.fatal(_("Flag -r requires GDAL library: {}").format(e))
         dsn = gdal.Open(filename)
         trans = dsn.GetGeoTransform()
+        
+        ret = int(trans[1])
+        dsn = None
 
-        return int(trans[1])
-                     
+        return ret
+    
+    def _raster_epsg(self, filename):
+        try:
+            from osgeo import gdal, osr
+        except ImportError as e:
+            gs.fatal(_("Flag -r requires GDAL library: {}").format(e))
+        dsn = gdal.Open(filename)
+
+        srs = osr.SpatialReference()
+        srs.ImportFromWkt(dsn.GetProjectionRef())
+    
+        ret = srs.GetAuthorityCode(None)
+        dsn = None
+
+        return ret
+        
     def _import_file(self, filename, module, args):
         mapname = os.path.splitext(os.path.basename(filename))[0]
         gs.message(_('Processing <{}>...').format(mapname))
@@ -147,11 +169,24 @@
             except CalledModuleError as e:
                 pass # error already printed
 
+    def print_products(self):
+        for f in self.files:
+            sys.stdout.write('{} {} (EPSG: {}){}'.format(
+                f,
+                '1' if self._check_projection(f) else '0',
+                self._raster_epsg(f),
+                os.linesep
+            ))
+
 def main():
     importer = SentinelImporter(options['input'])
 
     importer.filter(options['pattern'])
 
+    if flags['p']:
+        importer.print_products()
+        return 0
+    
     importer.import_products(flags['r'], flags['l'])
 
     if flags['c']:



More information about the grass-commit mailing list