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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 29 07:49:52 PST 2018


Author: martinl
Date: 2018-01-29 07:49:52 -0800 (Mon, 29 Jan 2018)
New Revision: 72196

Modified:
   grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.py
Log:
r.sentinel.import: check projection, improve explanation, rename -o flag to -r

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-01-29 11:19:20 UTC (rev 72195)
+++ grass-addons/grass7/raster/r.sentinel/r.sentinel.import/r.sentinel.import.py	2018-01-29 15:49:52 UTC (rev 72196)
@@ -31,7 +31,7 @@
 #% description: File name pattern to import
 #%end
 #%flag
-#% key: o
+#% key: r
 #% description: Reproject raster data using r.import if needed
 #%end
 #%flag
@@ -43,7 +43,7 @@
 #% description: Import cloud masks as vector maps
 #%end
 #%rules
-#% exclusive: -l,-o
+#% exclusive: -l,-r
 #%end
 import os
 import sys
@@ -92,8 +92,27 @@
                 module = 'r.in.gdal'
 
         for f in self.files:
+            if link or (not link and not reproject):
+                if not self._check_projection(f):
+                    gs.fatal('Projection of dataset does not appear to match current location. '
+                             'Force reprojecting dataset by -r flag.')
+
             self._import_file(f, module)
 
+    def _check_projection(self, filename):
+        try:
+            # module is not so script friedly, so we discard all
+            # warning and errors
+            nuldev = open(os.devnull, 'w+')
+            gs.run_command('r.in.gdal', flags='j',
+                           input=filename, quiet=True,
+                           stderr = nuldev)
+            nuldev.close()
+        except CalledModuleError as e:
+            return False
+
+        return True
+
     def _import_file(self, filename, module):
         mapname = os.path.splitext(os.path.basename(filename))[0]
         gs.message('Processing <{}>...'.format(mapname))
@@ -123,7 +142,7 @@
 
     importer.filter(options['pattern'])
 
-    importer.import_products(flags['o'], flags['l'])
+    importer.import_products(flags['r'], flags['l'])
 
     if flags['c']:
         importer.import_cloud_masks()



More information about the grass-commit mailing list