Commit 2c44402b authored by Daniele Romagnoli's avatar Daniele Romagnoli
Browse files

GEOS-7035: Allows COMPARISON_TOLERANCE override through System Property

parent 5f9014fb
......@@ -14,3 +14,24 @@ If an EPSG code cannot be found, then either the data has no CRS or it is unknow
* Reproject from the native to the declared CRS. This is the best solution if the native CRS is correct, but cannot be matched to an EPSG number. (An alternative is to add a custom EPSG code that matches exactly the native SRS. See the section on :ref:`crs_custom` for more information.)
If your data has no native CRS information, the only option is to specify/force an EPSG code.
Increasing Comparison Tolerance
Decimal numbers comparisons are made using a comparison tolerance. This means, as an instance, that an ellipsoid's semi_major axis
equals a candidate EPSG's ellipsoid semi_major axis only if their difference is within that tolerance.
Default value is 10^-9 although it can be changed by setting a COMPARISON_TOLERANCE Java System property to your container's JVM to specify a different value.
.. warning::
The default value should be changed only if you are aware of use cases which require a wider tolerance.
Don't change it unless really needed (See the following example).
* Your sample dataset is known to be a LambertConformalConic projection and the related EPSG code defines latitude_of_origin value = 25.0.
* The coverageStore plugin is exposing raster projection details through a third party library which provides projection parameter definitions as float numbers.
* Due to the underlying math computations occurring in that third party library, the exposed projection parameters are subject to some accuracy loss, so that the provided latitude_of_origin is something like 25.0000012 whilst all the other params match the EPSG definition.
* You notice that the native CRS isn't properly recognized as the expected EPSG due to that small difference in latitude_of_origin
In that case you could consider increasing a bit the tolerance.
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014-2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -70,6 +70,10 @@ public class GeoserverInitStartupListener implements ServletContextListener {
private Iterator<Class<?>> products;
private final static double DEFAULT_COMPARISON_TOLERANCE = 1e-9;
public void contextInitialized(ServletContextEvent sce) {
// start up tctool - remove it before committing!!!!
// new tilecachetool.TCTool().setVisible(true);
......@@ -134,12 +138,25 @@ public class GeoserverInitStartupListener implements ServletContextListener {
Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING, "http");
Hints.putSystemDefault(Hints.LENIENT_DATUM_SHIFT, true);
// setup the referencing tolerance to make it more tolerant to tiny differences
// between projections (increases the chance of matching a random prj file content
// to an actual EPSG code
Hints.putSystemDefault(Hints.COMPARISON_TOLERANCE, 1e-9);
String comparisonToleranceProperty = GeoServerExtensions.getProperty(COMPARISON_TOLERANCE_PROPERTY);
double comparisonTolerance = DEFAULT_COMPARISON_TOLERANCE;
if (comparisonToleranceProperty != null) {
try {
comparisonTolerance = Double.parseDouble(comparisonToleranceProperty);
} catch (NumberFormatException nfe) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("Unable to parse the specified COMPARISON_TOLERANCE "
+ "system property: " + comparisonToleranceProperty +
" which should be a number. Using Default: " + DEFAULT_COMPARISON_TOLERANCE);
Hints.putSystemDefault(Hints.COMPARISON_TOLERANCE, comparisonTolerance);
final Hints defHints = GeoTools.getDefaultHints();
// Initialize GridCoverageFactory so that we don't make a lookup every time a factory is needed
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014-2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2014 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -16,6 +16,8 @@ import javax.servlet.ServletContextEvent;
import org.geotools.coverage.grid.GridCoverageFactory;
import org.geotools.factory.GeoTools;
import org.geotools.factory.Hints;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opengis.feature.FeatureFactory;
import org.opengis.filter.FilterFactory;
......@@ -25,6 +27,18 @@ import com.mockrunner.mock.web.MockServletContext;
public class GeoServerInitStartupListenerTest {
private static final double CUSTOM_TOLERANCE = 1E-7d;
public void init() {
System.setProperty("COMPARISON_TOLERANCE", Double.toString(CUSTOM_TOLERANCE));
public void reset() {
public void testStartupListener() {
GeoserverInitStartupListener listener = new GeoserverInitStartupListener();
......@@ -42,7 +56,7 @@ public class GeoServerInitStartupListenerTest {
final Object tolerance = hints.get(Hints.COMPARISON_TOLERANCE);
assertEquals((Double) tolerance, 1e-9d, 1e-12d);
assertEquals(CUSTOM_TOLERANCE, (Double) tolerance, 1e-12d);
final Object filterFactory = hints.get(Hints.FILTER_FACTORY);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment