Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Oct 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -165,6 +165,11 @@ The Coverage Editor gives users the possibility to set a few control parameters
- 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.
* - *BackgroundValues*
- 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.
* - *Filter*
- 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.

.. 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'.

* - *OutputTransparentColor*
- Set the transparent color for the created mosaic. See below for an example:

Expand Down
17 changes: 15 additions & 2 deletions src/main/src/main/java/org/geoserver/data/util/CoverageUtils.java
Expand Up @@ -18,10 +18,12 @@

import org.geotools.coverage.grid.GeneralGridGeometry;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.filter.text.ecql.ECQL;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.parameter.DefaultParameterDescriptor;
import org.geotools.referencing.CRS;
import org.geotools.util.Converters;
import org.opengis.filter.Filter;
import org.opengis.parameter.GeneralParameterDescriptor;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterDescriptor;
Expand Down Expand Up @@ -345,13 +347,24 @@ public static Object getCvParamValue(final String key, ParameterValue param, fin
value=backgroundValues;

}
}
else if (key.equalsIgnoreCase("InputImageThresholdValue")) {
} else if (key.equalsIgnoreCase("InputImageThresholdValue")) {
if (params.get(key) != null) {
String temp = (String) params.get(key);
value=Double.valueOf(temp);

}
} else if (key.equalsIgnoreCase("Filter")) {
Object sfilter=params.get(key);
if (sfilter!=null){
if (sfilter instanceof String){
value=ECQL.toFilter((String)sfilter);
} else if (sfilter instanceof Filter){
value=(Filter)sfilter;
}
} else {
value=param.getValue();
}

} else {
value = params.get(key);
if(value != null) {
Expand Down
8 changes: 1 addition & 7 deletions src/wms/src/main/java/org/geoserver/wms/GetMap.java
Expand Up @@ -47,7 +47,6 @@
import org.geotools.renderer.lite.MetaBufferEstimator;
import org.geotools.renderer.lite.RendererUtilities;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.resources.CRSUtilities;
import org.geotools.styling.FeatureTypeConstraint;
import org.geotools.styling.FeatureTypeStyle;
import org.geotools.styling.Rule;
Expand Down Expand Up @@ -135,12 +134,6 @@ public WebMap run(final GetMapRequest request, WMSMapContent mapContent)

GetMapOutputFormat delegate = getDelegate(outputFormat);

// if there's a crs in the request, use that. If not, assume its 4326
final CoordinateReferenceSystem mapcrs = request.getCrs();

final List<MapLayerInfo> layers = request.getLayers();
final Style[] styles = request.getStyles().toArray(new Style[] {});
final Filter[] filters = buildLayersFilters(request.getFilter(), layers);
final boolean isTiled = MetatileMapOutputFormat.isRequestTiled(request, delegate);

//
Expand Down Expand Up @@ -633,6 +626,7 @@ private void assertMandatory(GetMapRequest request) throws ServiceException {
*/
private Filter[] buildLayersFilters(List<Filter> requestFilters, List<MapLayerInfo> layers) {
final int nLayers = layers.size();

if (requestFilters == null || requestFilters.size() == 0) {
requestFilters = Collections.nCopies(layers.size(), (Filter) Filter.INCLUDE);
} else if (requestFilters.size() != nLayers) {
Expand Down
41 changes: 22 additions & 19 deletions src/wms/src/main/java/org/geoserver/wms/WMS.java
Expand Up @@ -4,19 +4,14 @@
*/
package org.geoserver.wms;

import static org.geoserver.ows.util.ResponseUtils.buildURL;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ExecutorService;
Expand All @@ -30,7 +25,6 @@
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerGroupInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.MetadataLinkInfo;
import org.geoserver.catalog.MetadataMap;
import org.geoserver.catalog.NamespaceInfo;
import org.geoserver.catalog.ResourceInfo;
Expand All @@ -41,8 +35,6 @@
import org.geoserver.config.GeoServerInfo;
import org.geoserver.config.JAIInfo;
import org.geoserver.data.util.CoverageUtils;
import org.geoserver.ows.URLMangler.URLType;
import org.geoserver.ows.util.KvpUtils;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.platform.ServiceException;
import org.geoserver.wms.WMSInfo.WMSInterpolation;
Expand All @@ -52,10 +44,8 @@
import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
import org.geotools.data.FeatureSource;
import org.geotools.data.Query;
import org.geotools.data.QueryCapabilities;
import org.geotools.data.ows.Layer;
import org.geotools.data.ows.WMSCapabilities;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.GeoTools;
import org.geotools.feature.FeatureCollection;
Expand All @@ -64,20 +54,19 @@
import org.geotools.feature.visitor.MinVisitor;
import org.geotools.feature.visitor.UniqueVisitor;
import org.geotools.filter.Filters;
import org.geotools.filter.SortByImpl;
import org.geotools.resources.coverage.FeatureUtilities;
import org.geotools.styling.Style;
import org.geotools.util.*;
import org.geotools.util.Converters;
import org.geotools.util.Range;
import org.geotools.util.Version;
import org.geotools.util.logging.Logging;
import org.opengis.feature.type.Name;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.PropertyName;
import org.opengis.filter.sort.SortBy;
import org.opengis.filter.sort.SortOrder;
import org.opengis.parameter.GeneralParameterDescriptor;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterValue;
import org.opengis.parameter.ParameterValueGroup;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -801,7 +790,6 @@ public GeneralParameterValue[] getWMSReadParameters(final GetMapRequest request,
GeneralParameterValue[] readParameters = CoverageUtils.getParameters(
readParametersDescriptor, coverage.getParameters(), readGeom);
ReaderDimensionsAccessor dimensions = new ReaderDimensionsAccessor(reader);

// pass down time
final DimensionInfo timeInfo = metadata.get(ResourceInfo.TIME, DimensionInfo.class);
final List<GeneralParameterDescriptor> parameterDescriptors = readParametersDescriptor
Expand Down Expand Up @@ -834,9 +822,24 @@ public GeneralParameterValue[] getWMSReadParameters(final GetMapRequest request,
fixedElevations, "ELEVATION", "Elevation");
}

if (layerFilter != null) {
readParameters = CoverageUtils.mergeParameter(parameterDescriptors, readParameters,
layerFilter, "FILTER", "Filter");
if (layerFilter != null && readParameters != null) {
// test for default [empty is replaced with INCLUDE filter] ]filter
for (int i = 0; i < readParameters.length; i++) {

GeneralParameterValue param = readParameters[i];
GeneralParameterDescriptor pd = param.getDescriptor();

if (pd.getName().getCode().equalsIgnoreCase("FILTER")) {
final ParameterValue pv = (ParameterValue) pd.createValue();
// if something different from the default INCLUDE filter is specified
if (layerFilter != Filter.INCLUDE) {
// override the default filter
pv.setValue(layerFilter);
readParameters[i] = pv;
}
break;
}
}
}
return readParameters;
}
Expand Down
@@ -0,0 +1,31 @@
package org.geoserver.wms;

import org.geoserver.catalog.CoverageInfo;
import org.geoserver.wms.wms_1_1_1.FilterMosaicGetMapTest;

/**
* The following will provide data to test the default ImageMosaic cql filter
* The added mosaic is used WITHOUT dimensions which are instead used as attributes.
*
* @see {@link FilterMosaicGetMapTest}
*
* @author carlo cancellieri
*
*/
public class WMSFilterMosaicTestSupport extends WMSDimensionsTestSupport {

/**
* Here we setup the default mosaic filter to the layer
* @param metadata
* @param presentation
* @param resolution
*/
protected void setupMosaicFilter(String filter, String layer) {
CoverageInfo info = getCatalog().getCoverageByName(layer);

info.getParameters().put("Filter", filter);

getCatalog().save(info);
}

}
Expand Up @@ -71,12 +71,6 @@ public void testTimeTwice() throws Exception {
// should be similar to the default, but with different shades of color
assertPixel(image, 36, 31, new Color(246, 246, 255));
assertPixel(image, 68, 72, new Color(255, 182, 182));

image = getAsImage(BASE_URL + "&time=2008-10-31T00:00:00.000Z", "image/png");

// should be similar to the default, but with different shades of color
assertPixel(image, 36, 31, new Color(246, 246, 255));
assertPixel(image, 68, 72, new Color(255, 182, 182));

}

Expand Down
@@ -0,0 +1,127 @@
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.geoserver.wms.wms_1_1_1;

import java.awt.Color;
import java.awt.image.BufferedImage;

import org.geoserver.wms.WMSFilterMosaicTestSupport;

/**
* Class to test ImageMosaic cql filter
*
* @see {@link WMSFilterMosaicTestSupport}
*
* @author carlo cancellieri
*
*/
public class FilterMosaicGetMapTest extends WMSFilterMosaicTestSupport {

final static String layer = WATTEMP.getLocalPart();

final static String BASE_URL = "wms?service=WMS&version=1.1.0" + "&request=GetMap&layers="
+ layer + "&styles=" + "&bbox=0.237,40.562,14.593,44.558&width=200&height=80"
+ "&srs=EPSG:4326&format=image/png";

final static String MIME = "image/png";

// specifying default filter
final static String cql_filter = "elevation=100 AND ingestion=\'2008-10-31T00:00:00.000Z\'";

public void testAsCQL() throws Exception {
// CASE 'MOSAIC WITH DEFAULT FILTERS'

// setting the default filter
super.setupMosaicFilter(cql_filter, layer);

// get mosaic using the default filter
BufferedImage image = getAsImage(BASE_URL, "image/png");

// at this elevation the pixel is black
assertPixel(image, 36, 31, new Color(0, 0, 0));
assertPixel(image, 68, 72, new Color(240, 240, 255));

}

public void testCaseDefault() throws Exception {
// CASE 'MOSAIC WITHOUT FILTERS'

// disable the default filter
super.setupMosaicFilter("", layer);

// get mosaic without the default filter
BufferedImage image = getAsImage(BASE_URL, "image/png");

// at this elevation the pixel is black
assertPixel(image, 36, 31, new Color(246, 246, 255));
assertPixel(image, 68, 72, new Color(255, 182, 182));
}

public void testCaseElev100andIngestion31Oct() throws Exception {
// CASE 'MOSAIC WITH FILTERS'

// overriding the default filter using cql_filter parameter
BufferedImage image = getAsImage(BASE_URL
+ "&cql_filter=elevation=100 AND ingestion=\'2008-10-31T00:00:00.000Z\'",
"image/png");

// setting the default filter
super.setupMosaicFilter(cql_filter, layer);

// at this elevation the pixel is black
assertPixel(image, 36, 31, new Color(0, 0, 0));
assertPixel(image, 68, 72, new Color(240, 240, 255));
}

public void testCaseElev100andIngestion01Nov() throws Exception {

// CASE 'MOSAIC WITH FILTERS'

// overriding the default filter using cql_filter parameter
BufferedImage image = getAsImage(BASE_URL
+ "&cql_filter=elevation=100 AND ingestion=\'2008-11-01T00:00:00.000Z\'",
"image/png");

// setting the default filter
super.setupMosaicFilter(cql_filter, layer);

// at this elevation the pixel is black
assertPixel(image, 36, 31, new Color(0, 0, 0));
assertPixel(image, 68, 72, new Color(246, 246, 255));

}

public void testCaseElev0andIngestion31Oct() throws Exception {
// CASE 'MOSAIC WITH FILTERS'

// overriding the default filter using cql_filter parameter
BufferedImage image = getAsImage(BASE_URL
+ "&cql_filter=elevation=0 AND ingestion=\'2008-10-31T00:00:00.000Z\'", "image/png");

// setting the default filter
super.setupMosaicFilter(cql_filter, layer);

// should be similar to the default, but with different shades of color
assertPixel(image, 36, 31, new Color(246, 246, 255));
assertPixel(image, 68, 72, new Color(255, 182, 182));
}

public void testCaseElev0andIngestion01Nov() throws Exception {
// CASE 'MOSAIC WITH FILTERS'

// overriding the default filter using cql_filter parameter
BufferedImage image = getAsImage(BASE_URL
+ "&cql_filter=elevation=0 AND ingestion=\'2008-11-01T00:00:00.000Z\'", "image/png");

// setting the default filter
super.setupMosaicFilter(cql_filter, layer);

assertPixel(image, 36, 31, new Color(246, 246, 255));
// and this one a light blue, but slightly darker than before
assertPixel(image, 68, 72, new Color(255, 185, 185));

}

}