[GRASS-SVN] r73131 - grass-addons/grass7/imagery/i.sentinel/i.sentinel.import

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Aug 21 09:57:50 PDT 2018


Author: martinl
Date: 2018-08-21 09:57:50 -0700 (Tue, 21 Aug 2018)
New Revision: 73131

Modified:
   grass-addons/grass7/imagery/i.sentinel/i.sentinel.import/i.sentinel.import.py
Log:
i.sentinel.import: check if clouds layer exists, fix debug message

Modified: grass-addons/grass7/imagery/i.sentinel/i.sentinel.import/i.sentinel.import.py
===================================================================
--- grass-addons/grass7/imagery/i.sentinel/i.sentinel.import/i.sentinel.import.py	2018-08-21 16:33:24 UTC (rev 73130)
+++ grass-addons/grass7/imagery/i.sentinel/i.sentinel.import/i.sentinel.import.py	2018-08-21 16:57:50 UTC (rev 73131)
@@ -72,7 +72,10 @@
         for dirname in self._dir_list:
             dirpath = os.path.join(self.input_dir, dirname)
             gs.debug('Removing <{}>'.format(dirpath))
-            shutil.rmtree(dirpath)
+            try:
+                shutil.rmtree(dirpath)
+            except OSError:
+                pass
             
     def filter(self, pattern=None):
         if pattern:
@@ -80,7 +83,7 @@
         else:
             filter_p = r'.*_B.*.jp2$'
 
-        gs.debug('Filter: {}'.format(filter_p), 0)
+        gs.debug('Filter: {}'.format(filter_p), 1)
         self.files = self._filter(filter_p)
 
     @staticmethod
@@ -188,6 +191,8 @@
             pass # error already printed
 
     def import_cloud_masks(self):
+        from osgeo import ogr
+
         files = self._filter("MSK_CLOUDS_B00.gml")
 
         for f in files:
@@ -194,6 +199,13 @@
             safe_dir = os.path.dirname(f).split(os.path.sep)[-4]
             items = safe_dir.split('_')
             map_name = '_'.join([items[5],items[2], 'MSK', 'CLOUDS'])
+            # check if any OGR layer
+            dsn = ogr.Open(f)
+            layer_count = dsn.GetLayerCount()
+            dsn.Destroy()
+            if layer_count < 1:
+                gs.info('No clouds layer found in <{}>. Import skipped'.format(f))
+                continue
             try:
                 gs.run_command('v.import', input=f,
                                flags='o', # same SRS as data



More information about the grass-commit mailing list