[GRASS-SVN] r70284 - sandbox/martinl

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 6 10:59:14 PST 2017


Author: martinl
Date: 2017-01-06 10:59:14 -0800 (Fri, 06 Jan 2017)
New Revision: 70284

Modified:
   sandbox/martinl/tiles-rast-stats.py
Log:
tiles-rast-stats: improve spatial filter

Modified: sandbox/martinl/tiles-rast-stats.py
===================================================================
--- sandbox/martinl/tiles-rast-stats.py	2017-01-06 18:49:53 UTC (rev 70283)
+++ sandbox/martinl/tiles-rast-stats.py	2017-01-06 18:59:14 UTC (rev 70284)
@@ -126,12 +126,17 @@
         except CalledModuleError:
             sys.exit(1)
 
-    layer.SetSpatialFilter(ogr.CreateGeometryFromWkt(wkt))
+    # spatial filter is too rough, it uses bboxes
+    filter_geom = ogr.CreateGeometryFromWkt(wkt)
+    layer.SetSpatialFilter(filter_geom)
 
     tiles = []
     try:
         for feature in layer:
-            tiles.append(feature.GetField(keycolumn))
+            # improve filter
+            geom = feature.GetGeometryRef()
+            if geom.Intersects(filter_geom):
+                tiles.append(feature.GetField(keycolumn))
     except ValueError:
         grass.fatal("Column <{}> not found".format(keycolumn))
     grass.message("{} tiles filtered".format(len(tiles)))
@@ -268,7 +273,7 @@
                             "use the --overwrite flag".format(options['output_layer']))
 
     column_prefix = options['raster'] if not options['column_prefix'] else options['column_prefix']
-    
+
     # perform statistics
     perform_statistics(maps, options['raster'],
                        column_prefix,



More information about the grass-commit mailing list