Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[GEOS-5279][2] ImageMosaic Filter option does not work #29

Merged
merged 3 commits into from over 1 year ago

2 participants

Carlo Cancellieri Simone Giannecchini
carlo cancel... added some commits August 23, 2012
GEOS-5279 9c609af
Improved IM filter junit tests e31bedf
Carlo Cancellieri
Collaborator

Is it possible to have this patch merged pls?

Simone Giannecchini simboss merged commit 2fa4ec6 into from October 23, 2012
Simone Giannecchini simboss closed this October 23, 2012
Simone Giannecchini
Collaborator

Carlo, can we have a similar pull request on 2.2.x as well after release 2.2.1?

Carlo Cancellieri
Collaborator

Thank you Simone for the merge.

Here is the backport pull request:
#45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 2 authors.

Sep 17, 2012
GEOS-5279 9c609af
Improved IM filter junit tests e31bedf
Oct 10, 2012
Carlo Cancellieri added check for null readParameters and fix format e20c513
This page is out of date. Refresh to see the latest.
5  doc/en/user/source/tutorials/image_mosaic_plugin/imagemosaic.rst
Source Rendered
@@ -165,6 +165,11 @@ The Coverage Editor gives users the possibility to set a few control parameters
165 165
      - Set the maximum number of the tiles that can be load simulatenously for a request. In case of a large mosaic this parameter should be opportunely set to not saturating the server with too many granules loaded at  the same  time.
166 166
    * - *BackgroundValues*
167 167
      - Set the value of the mosaic background. Depending on the nature of the mosaic it is wise to set a value for the 'no data' area (usually -9999). This value is repeated on all the mosaic bands.
  168
+   * - *Filter* 
  169
+     - Set the default mosaic filter. It should be a valid ECQL query which will be used as default if no 'cql_filter' are specified (instead of Filter.INCLUDE). If the cql_filter is specified in the request it will be overriden.
  170
+
  171
+.. note:: Do not use this filter to change time or elevation dimensions defaults. It will be added as AND condition with CURRENT for 'time' and LOWER for 'elevation'.
  172
+
168 173
    * - *OutputTransparentColor*
169 174
      - Set the transparent color for the created mosaic. See below for an example:
170 175
 
17  src/main/src/main/java/org/geoserver/data/util/CoverageUtils.java
@@ -18,10 +18,12 @@
18 18
 
19 19
 import org.geotools.coverage.grid.GeneralGridGeometry;
20 20
 import org.geotools.coverage.grid.io.AbstractGridFormat;
  21
+import org.geotools.filter.text.ecql.ECQL;
21 22
 import org.geotools.geometry.GeneralEnvelope;
22 23
 import org.geotools.parameter.DefaultParameterDescriptor;
23 24
 import org.geotools.referencing.CRS;
24 25
 import org.geotools.util.Converters;
  26
+import org.opengis.filter.Filter;
25 27
 import org.opengis.parameter.GeneralParameterDescriptor;
26 28
 import org.opengis.parameter.GeneralParameterValue;
27 29
 import org.opengis.parameter.ParameterDescriptor;
@@ -345,13 +347,24 @@ public static Object getCvParamValue(final String key, ParameterValue param, fin
345 347
                         value=backgroundValues;
346 348
                         
347 349
                     } 
348  
-                } 
349  
-                else if (key.equalsIgnoreCase("InputImageThresholdValue")) {
  350
+                } else if (key.equalsIgnoreCase("InputImageThresholdValue")) {
350 351
                     if (params.get(key) != null) {
351 352
                         String temp = (String) params.get(key);
352 353
                         value=Double.valueOf(temp);
353 354
                         
354 355
                     } 
  356
+                } else if (key.equalsIgnoreCase("Filter")) {
  357
+    	            	Object sfilter=params.get(key);
  358
+    	            	if (sfilter!=null){
  359
+    	            		if (sfilter instanceof String){
  360
+    	            			value=ECQL.toFilter((String)sfilter);
  361
+    	            		} else if (sfilter instanceof Filter){
  362
+    	            			value=(Filter)sfilter;
  363
+    	            		}
  364
+    	        		} else {
  365
+    	        			value=param.getValue();
  366
+    	        		}
  367
+            		 
355 368
                 } else {
356 369
                     value = params.get(key);
357 370
                     if(value != null) {
8  src/wms/src/main/java/org/geoserver/wms/GetMap.java
@@ -47,7 +47,6 @@
47 47
 import org.geotools.renderer.lite.MetaBufferEstimator;
48 48
 import org.geotools.renderer.lite.RendererUtilities;
49 49
 import org.geotools.renderer.lite.StreamingRenderer;
50  
-import org.geotools.resources.CRSUtilities;
51 50
 import org.geotools.styling.FeatureTypeConstraint;
52 51
 import org.geotools.styling.FeatureTypeStyle;
53 52
 import org.geotools.styling.Rule;
@@ -135,12 +134,6 @@ public WebMap run(final GetMapRequest request, WMSMapContent mapContent)
135 134
 
136 135
         GetMapOutputFormat delegate = getDelegate(outputFormat);
137 136
 
138  
-        // if there's a crs in the request, use that. If not, assume its 4326
139  
-        final CoordinateReferenceSystem mapcrs = request.getCrs();
140  
-
141  
-        final List<MapLayerInfo> layers = request.getLayers();
142  
-        final Style[] styles = request.getStyles().toArray(new Style[] {});
143  
-        final Filter[] filters = buildLayersFilters(request.getFilter(), layers);
144 137
         final boolean isTiled = MetatileMapOutputFormat.isRequestTiled(request, delegate);
145 138
 
146 139
         //
@@ -633,6 +626,7 @@ private void assertMandatory(GetMapRequest request) throws ServiceException {
633 626
      */
634 627
     private Filter[] buildLayersFilters(List<Filter> requestFilters, List<MapLayerInfo> layers) {
635 628
         final int nLayers = layers.size();
  629
+
636 630
         if (requestFilters == null || requestFilters.size() == 0) {
637 631
             requestFilters = Collections.nCopies(layers.size(), (Filter) Filter.INCLUDE);
638 632
         } else if (requestFilters.size() != nLayers) {
41  src/wms/src/main/java/org/geoserver/wms/WMS.java
@@ -4,11 +4,7 @@
4 4
  */
5 5
 package org.geoserver.wms;
6 6
 
7  
-import static org.geoserver.ows.util.ResponseUtils.buildURL;
8  
-
9 7
 import java.io.IOException;
10  
-import java.net.MalformedURLException;
11  
-import java.net.URL;
12 8
 import java.nio.charset.Charset;
13 9
 import java.util.ArrayList;
14 10
 import java.util.Arrays;
@@ -16,7 +12,6 @@
16 12
 import java.util.Date;
17 13
 import java.util.HashSet;
18 14
 import java.util.List;
19  
-import java.util.Map;
20 15
 import java.util.Set;
21 16
 import java.util.TreeSet;
22 17
 import java.util.concurrent.ExecutorService;
@@ -30,7 +25,6 @@
30 25
 import org.geoserver.catalog.FeatureTypeInfo;
31 26
 import org.geoserver.catalog.LayerGroupInfo;
32 27
 import org.geoserver.catalog.LayerInfo;
33  
-import org.geoserver.catalog.MetadataLinkInfo;
34 28
 import org.geoserver.catalog.MetadataMap;
35 29
 import org.geoserver.catalog.NamespaceInfo;
36 30
 import org.geoserver.catalog.ResourceInfo;
@@ -41,8 +35,6 @@
41 35
 import org.geoserver.config.GeoServerInfo;
42 36
 import org.geoserver.config.JAIInfo;
43 37
 import org.geoserver.data.util.CoverageUtils;
44  
-import org.geoserver.ows.URLMangler.URLType;
45  
-import org.geoserver.ows.util.KvpUtils;
46 38
 import org.geoserver.platform.GeoServerExtensions;
47 39
 import org.geoserver.platform.ServiceException;
48 40
 import org.geoserver.wms.WMSInfo.WMSInterpolation;
@@ -52,10 +44,8 @@
52 44
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
53 45
 import org.geotools.data.FeatureSource;
54 46
 import org.geotools.data.Query;
55  
-import org.geotools.data.QueryCapabilities;
56 47
 import org.geotools.data.ows.Layer;
57 48
 import org.geotools.data.ows.WMSCapabilities;
58  
-import org.geotools.data.simple.SimpleFeatureCollection;
59 49
 import org.geotools.factory.CommonFactoryFinder;
60 50
 import org.geotools.factory.GeoTools;
61 51
 import org.geotools.feature.FeatureCollection;
@@ -64,20 +54,19 @@
64 54
 import org.geotools.feature.visitor.MinVisitor;
65 55
 import org.geotools.feature.visitor.UniqueVisitor;
66 56
 import org.geotools.filter.Filters;
67  
-import org.geotools.filter.SortByImpl;
68  
-import org.geotools.resources.coverage.FeatureUtilities;
69 57
 import org.geotools.styling.Style;
70  
-import org.geotools.util.*;
  58
+import org.geotools.util.Converters;
  59
+import org.geotools.util.Range;
  60
+import org.geotools.util.Version;
71 61
 import org.geotools.util.logging.Logging;
72 62
 import org.opengis.feature.type.Name;
73 63
 import org.opengis.filter.Filter;
74 64
 import org.opengis.filter.FilterFactory;
75 65
 import org.opengis.filter.expression.Literal;
76 66
 import org.opengis.filter.expression.PropertyName;
77  
-import org.opengis.filter.sort.SortBy;
78  
-import org.opengis.filter.sort.SortOrder;
79 67
 import org.opengis.parameter.GeneralParameterDescriptor;
80 68
 import org.opengis.parameter.GeneralParameterValue;
  69
+import org.opengis.parameter.ParameterValue;
81 70
 import org.opengis.parameter.ParameterValueGroup;
82 71
 import org.springframework.beans.BeansException;
83 72
 import org.springframework.context.ApplicationContext;
@@ -801,7 +790,6 @@ public boolean isQueryable(LayerGroupInfo layerGroup) {
801 790
         GeneralParameterValue[] readParameters = CoverageUtils.getParameters(
802 791
                 readParametersDescriptor, coverage.getParameters(), readGeom);
803 792
         ReaderDimensionsAccessor dimensions = new ReaderDimensionsAccessor(reader);
804  
-
805 793
         // pass down time
806 794
         final DimensionInfo timeInfo = metadata.get(ResourceInfo.TIME, DimensionInfo.class);
807 795
         final List<GeneralParameterDescriptor> parameterDescriptors = readParametersDescriptor
@@ -834,9 +822,24 @@ public boolean isQueryable(LayerGroupInfo layerGroup) {
834 822
                     fixedElevations, "ELEVATION", "Elevation");
835 823
         }
836 824
 
837  
-        if (layerFilter != null) {
838  
-            readParameters = CoverageUtils.mergeParameter(parameterDescriptors, readParameters,
839  
-                    layerFilter, "FILTER", "Filter");
  825
+        if (layerFilter != null && readParameters != null) {
  826
+            // test for default [empty is replaced with INCLUDE filter] ]filter
  827
+            for (int i = 0; i < readParameters.length; i++) {
  828
+
  829
+                GeneralParameterValue param = readParameters[i];
  830
+                GeneralParameterDescriptor pd = param.getDescriptor();
  831
+
  832
+                if (pd.getName().getCode().equalsIgnoreCase("FILTER")) {
  833
+                    final ParameterValue pv = (ParameterValue) pd.createValue();
  834
+                    // if something different from the default INCLUDE filter is specified
  835
+                    if (layerFilter != Filter.INCLUDE) {
  836
+                        // override the default filter
  837
+                        pv.setValue(layerFilter);
  838
+                        readParameters[i] = pv;
  839
+                    }
  840
+                    break;
  841
+                }
  842
+            }
840 843
         }
841 844
         return readParameters;
842 845
     }
31  src/wms/src/test/java/org/geoserver/wms/WMSFilterMosaicTestSupport.java
... ...
@@ -0,0 +1,31 @@
  1
+package org.geoserver.wms;
  2
+
  3
+import org.geoserver.catalog.CoverageInfo;
  4
+import org.geoserver.wms.wms_1_1_1.FilterMosaicGetMapTest;
  5
+
  6
+/**
  7
+ * The following will provide data to test the default ImageMosaic cql filter
  8
+ * The added mosaic is used WITHOUT dimensions which are instead used as attributes.
  9
+ * 
  10
+ * @see {@link FilterMosaicGetMapTest}
  11
+ * 
  12
+ * @author carlo cancellieri
  13
+ *
  14
+ */
  15
+public class WMSFilterMosaicTestSupport extends WMSDimensionsTestSupport {
  16
+        
  17
+    /**
  18
+     * Here we setup the default mosaic filter to the layer 
  19
+     * @param metadata
  20
+     * @param presentation
  21
+     * @param resolution
  22
+     */
  23
+    protected void setupMosaicFilter(String filter, String layer) {
  24
+        CoverageInfo info = getCatalog().getCoverageByName(layer);
  25
+        
  26
+        info.getParameters().put("Filter", filter);
  27
+        
  28
+        getCatalog().save(info);
  29
+    }
  30
+    
  31
+}
6  src/wms/src/test/java/org/geoserver/wms/wms_1_1_1/DimensionsRasterGetMapTest.java
@@ -71,12 +71,6 @@ public void testTimeTwice() throws Exception {
71 71
         // should be similar to the default, but with different shades of color
72 72
         assertPixel(image, 36, 31, new Color(246, 246, 255));
73 73
         assertPixel(image, 68, 72, new Color(255, 182, 182));
74  
-        
75  
-        image = getAsImage(BASE_URL + "&time=2008-10-31T00:00:00.000Z", "image/png");
76  
-
77  
-        // should be similar to the default, but with different shades of color
78  
-        assertPixel(image, 36, 31, new Color(246, 246, 255));
79  
-        assertPixel(image, 68, 72, new Color(255, 182, 182));
80 74
 
81 75
     }
82 76
     
127  src/wms/src/test/java/org/geoserver/wms/wms_1_1_1/FilterMosaicGetMapTest.java
... ...
@@ -0,0 +1,127 @@
  1
+/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
  2
+ * This code is licensed under the GPL 2.0 license, availible at the root
  3
+ * application directory.
  4
+ */
  5
+package org.geoserver.wms.wms_1_1_1;
  6
+
  7
+import java.awt.Color;
  8
+import java.awt.image.BufferedImage;
  9
+
  10
+import org.geoserver.wms.WMSFilterMosaicTestSupport;
  11
+
  12
+/**
  13
+ * Class to test ImageMosaic cql filter
  14
+ * 
  15
+ * @see {@link WMSFilterMosaicTestSupport}
  16
+ * 
  17
+ * @author carlo cancellieri
  18
+ * 
  19
+ */
  20
+public class FilterMosaicGetMapTest extends WMSFilterMosaicTestSupport {
  21
+
  22
+    final static String layer = WATTEMP.getLocalPart();
  23
+
  24
+    final static String BASE_URL = "wms?service=WMS&version=1.1.0" + "&request=GetMap&layers="
  25
+            + layer + "&styles=" + "&bbox=0.237,40.562,14.593,44.558&width=200&height=80"
  26
+            + "&srs=EPSG:4326&format=image/png";
  27
+
  28
+    final static String MIME = "image/png";
  29
+
  30
+    // specifying default filter
  31
+    final static String cql_filter = "elevation=100 AND ingestion=\'2008-10-31T00:00:00.000Z\'";
  32
+
  33
+    public void testAsCQL() throws Exception {
  34
+        // CASE 'MOSAIC WITH DEFAULT FILTERS'
  35
+
  36
+        // setting the default filter
  37
+        super.setupMosaicFilter(cql_filter, layer);
  38
+
  39
+        // get mosaic using the default filter
  40
+        BufferedImage image = getAsImage(BASE_URL, "image/png");
  41
+
  42
+        // at this elevation the pixel is black
  43
+        assertPixel(image, 36, 31, new Color(0, 0, 0));
  44
+        assertPixel(image, 68, 72, new Color(240, 240, 255));
  45
+
  46
+    }
  47
+
  48
+    public void testCaseDefault() throws Exception {
  49
+        // CASE 'MOSAIC WITHOUT FILTERS'
  50
+
  51
+        // disable the default filter
  52
+        super.setupMosaicFilter("", layer);
  53
+
  54
+        // get mosaic without the default filter
  55
+        BufferedImage image = getAsImage(BASE_URL, "image/png");
  56
+
  57
+        // at this elevation the pixel is black
  58
+        assertPixel(image, 36, 31, new Color(246, 246, 255));
  59
+        assertPixel(image, 68, 72, new Color(255, 182, 182));
  60
+    }
  61
+
  62
+    public void testCaseElev100andIngestion31Oct() throws Exception {
  63
+        // CASE 'MOSAIC WITH FILTERS'
  64
+
  65
+        // overriding the default filter using cql_filter parameter
  66
+        BufferedImage image = getAsImage(BASE_URL
  67
+                + "&cql_filter=elevation=100 AND ingestion=\'2008-10-31T00:00:00.000Z\'",
  68
+                "image/png");
  69
+
  70
+        // setting the default filter
  71
+        super.setupMosaicFilter(cql_filter, layer);
  72
+
  73
+        // at this elevation the pixel is black
  74
+        assertPixel(image, 36, 31, new Color(0, 0, 0));
  75
+        assertPixel(image, 68, 72, new Color(240, 240, 255));
  76
+    }
  77
+
  78
+    public void testCaseElev100andIngestion01Nov() throws Exception {
  79
+
  80
+        // CASE 'MOSAIC WITH FILTERS'
  81
+
  82
+        // overriding the default filter using cql_filter parameter
  83
+        BufferedImage image = getAsImage(BASE_URL
  84
+                + "&cql_filter=elevation=100 AND ingestion=\'2008-11-01T00:00:00.000Z\'",
  85
+                "image/png");
  86
+
  87
+        // setting the default filter
  88
+        super.setupMosaicFilter(cql_filter, layer);
  89
+
  90
+        // at this elevation the pixel is black
  91
+        assertPixel(image, 36, 31, new Color(0, 0, 0));
  92
+        assertPixel(image, 68, 72, new Color(246, 246, 255));
  93
+
  94
+    }
  95
+
  96
+    public void testCaseElev0andIngestion31Oct() throws Exception {
  97
+        // CASE 'MOSAIC WITH FILTERS'
  98
+
  99
+        // overriding the default filter using cql_filter parameter
  100
+        BufferedImage image = getAsImage(BASE_URL
  101
+                + "&cql_filter=elevation=0 AND ingestion=\'2008-10-31T00:00:00.000Z\'", "image/png");
  102
+
  103
+        // setting the default filter
  104
+        super.setupMosaicFilter(cql_filter, layer);
  105
+
  106
+        // should be similar to the default, but with different shades of color
  107
+        assertPixel(image, 36, 31, new Color(246, 246, 255));
  108
+        assertPixel(image, 68, 72, new Color(255, 182, 182));
  109
+    }
  110
+
  111
+    public void testCaseElev0andIngestion01Nov() throws Exception {
  112
+        // CASE 'MOSAIC WITH FILTERS'
  113
+
  114
+        // overriding the default filter using cql_filter parameter
  115
+        BufferedImage image = getAsImage(BASE_URL
  116
+                + "&cql_filter=elevation=0 AND ingestion=\'2008-11-01T00:00:00.000Z\'", "image/png");
  117
+
  118
+        // setting the default filter
  119
+        super.setupMosaicFilter(cql_filter, layer);
  120
+
  121
+        assertPixel(image, 36, 31, new Color(246, 246, 255));
  122
+        // and this one a light blue, but slightly darker than before
  123
+        assertPixel(image, 68, 72, new Color(255, 185, 185));
  124
+
  125
+    }
  126
+
  127
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.