diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentFactory.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentFactory.java index 756cf8f8640..943b61fce35 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentFactory.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentFactory.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding; import org.esa.snap.core.dataio.geocoding.forward.*; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCoding.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCoding.java index 22417aeb274..8f427322d0d 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCoding.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCoding.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding; import org.esa.snap.core.dataio.ProductSubsetDef; @@ -7,7 +25,6 @@ import org.esa.snap.core.util.SystemUtils; import org.geotools.referencing.crs.DefaultGeographicCRS; import org.opengis.referencing.crs.CoordinateReferenceSystem; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; import java.io.IOException; import java.util.stream.IntStream; @@ -150,6 +167,7 @@ public boolean transferGeoCoding(Scene srcScene, Scene destScene, ProductSubsetD SystemUtils.LOG.warning("error loading geolocation data: " + e.getMessage()); return false; } + ForwardCoding forwardCoding = null; if (this.forwardCoding != null) { forwardCoding = ComponentFactory.getForward(this.forwardCoding.getKey()); @@ -239,7 +257,7 @@ public void dispose() { @Override @Deprecated public Datum getDatum() { - throw new NotImplementedException(); + throw new IllegalStateException("Method not implemented!"); } @Override @@ -258,6 +276,7 @@ public GeoCoding clone() { final ComponentGeoCoding clone = new ComponentGeoCoding(geoRaster, cloneForward, cloneInverse, geoChecks); clone.isInitialized = this.isInitialized; + clone.isCrossingAntiMeridian = this.isCrossingAntiMeridian; return clone; } @@ -334,6 +353,8 @@ private GeoRaster calculateGeoRaster(Scene destScene, ProductSubsetDef subsetDef subsamplingX = lonTPG.getSubSamplingX(); subsamplingY = lonTPG.getSubSamplingY(); } else { + // this is based on already subsetted geo-location data, we take + // the subset in full resolution of the subset here tb 2021-05-12 gridWidth = lonRaster.getRasterWidth(); gridHeight = lonRaster.getRasterHeight(); @@ -348,7 +369,8 @@ private GeoRaster calculateGeoRaster(Scene destScene, ProductSubsetDef subsetDef geoRaster = new GeoRaster(longitudes, latitudes, lonVariableName, latVariableName, gridWidth, gridHeight, destScene.getRasterWidth(), destScene.getRasterHeight(), - this.geoRaster.getRasterResolutionInKm() * subsetDef.getSubSamplingX(), + // @todo 1 tb/tb this should also take the subsampling in y direction into account + this.geoRaster.getRasterResolutionInKm() * subsamplingY, offsetX, offsetY, subsamplingX, subsamplingY); return geoRaster; } diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistable.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistable.java index e5f2f1074c4..d85e562c912 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistable.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistable.java @@ -1,23 +1,48 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding; import org.esa.snap.core.dataio.dimap.spi.DimapPersistable; import org.esa.snap.core.dataio.geocoding.forward.PixelForward; import org.esa.snap.core.dataio.geocoding.forward.PixelInterpolatingForward; +import org.esa.snap.core.dataio.geocoding.inverse.PixelGeoIndexInverse; import org.esa.snap.core.dataio.geocoding.inverse.PixelQuadTreeInverse; import org.esa.snap.core.dataio.geocoding.util.RasterUtils; import org.esa.snap.core.datamodel.Product; import org.esa.snap.core.datamodel.RasterDataNode; import org.esa.snap.core.datamodel.TiePointGrid; import org.esa.snap.core.util.SystemUtils; +import org.esa.snap.runtime.Config; import org.geotools.referencing.CRS; import org.jdom.Element; import org.opengis.referencing.FactoryException; import org.opengis.referencing.crs.CoordinateReferenceSystem; +import java.awt.*; import java.io.IOException; -import java.awt.Dimension; +import java.util.prefs.Preferences; import java.util.stream.IntStream; +/** + * @deprecated dont further use this class. Now it is wrapped by {@link ComponentGeoCodingPersistenceConverter} + */ +@Deprecated public class ComponentGeoCodingPersistable implements DimapPersistable { public static final String TAG_COMPONENT_GEO_CODING = "ComponentGeoCoding"; @@ -107,15 +132,15 @@ public Object createObjectFromXml(Element element, Product product, Dimension re } if (forwardInvalid - || inverseInvalid - || geoChecksInvalid - || lonVarNameInvalid - || latVarNameInvalid - || resolutionKmInvalid - || resolutionInKm == null - || geoChecksName == null - || invalidValueGeoChecks - || geoCRS == null) { + || inverseInvalid + || geoChecksInvalid + || lonVarNameInvalid + || latVarNameInvalid + || resolutionKmInvalid + || resolutionInKm == null + || geoChecksName == null + || invalidValueGeoChecks + || geoCRS == null) { SystemUtils.LOG.warning("Unable to create " + TAG_COMPONENT_GEO_CODING + "."); return null; } @@ -176,14 +201,18 @@ public Object createObjectFromXml(Element element, Product product, Dimension re resolutionInKm); } - // TODO preliminary location to overwrite non-interpolating spec of input product e.g. for binning with supersampling, mb, 2021-03-31 - // Tom, please find a better solution. - if (Boolean.getBoolean(ComponentGeoCoding.SYSPROP_SNAP_PIXEL_CODING_FRACTION_ACCURACY) && PixelForward.KEY.equals(forwardKey)) { - forwardKey = PixelInterpolatingForward.KEY; + final Preferences snapPreferences = Config.instance("snap").preferences(); + final boolean isFractionalEnabled = snapPreferences.getBoolean(ComponentGeoCoding.SYSPROP_SNAP_PIXEL_CODING_FRACTION_ACCURACY, false); + if (isFractionalEnabled && PixelForward.KEY.equals(forwardKey)) { + forwardKey = PixelInterpolatingForward.KEY; + } + if (isFractionalEnabled && PixelQuadTreeInverse.KEY.equals(inverseKey)) { + inverseKey = PixelQuadTreeInverse.KEY_INTERPOLATING; } - if (Boolean.getBoolean(ComponentGeoCoding.SYSPROP_SNAP_PIXEL_CODING_FRACTION_ACCURACY) && PixelQuadTreeInverse.KEY.equals(inverseKey)) { - inverseKey = PixelQuadTreeInverse.KEY_INTERPOLATING; + if (isFractionalEnabled && PixelGeoIndexInverse.KEY.equals(inverseKey)) { + inverseKey = PixelGeoIndexInverse.KEY_INTERPOLATING; } + final ForwardCoding forwardCoding = ComponentFactory.getForward(forwardKey); final InverseCoding inverseCoding = ComponentFactory.getInverse(inverseKey); final ComponentGeoCoding geoCoding = new ComponentGeoCoding(geoRaster, forwardCoding, inverseCoding, GeoChecks.valueOf(geoChecksName), geoCRS); diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistableSpi.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistableSpi.java index 750a425dcef..a47d1b6182b 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistableSpi.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistableSpi.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding; import org.esa.snap.core.dataio.dimap.spi.DimapPersistable; @@ -6,6 +24,10 @@ import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_COMPONENT_GEO_CODING; +/** + * @deprecated use {@link ComponentGeoCodingPersistenceSpi} instead + */ +@Deprecated public class ComponentGeoCodingPersistableSpi implements DimapPersistableSpi { @Override public boolean canDecode(Element element) { diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/Discontinuity.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/Discontinuity.java index ecd54162c0a..84bb6c280a2 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/Discontinuity.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/Discontinuity.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding; public enum Discontinuity { diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ForwardCoding.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ForwardCoding.java index 9309734423c..90bdb4ffcb1 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ForwardCoding.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/ForwardCoding.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding; import org.esa.snap.core.datamodel.GeoPos; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/GeoChecks.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/GeoChecks.java index 1864de0c2f6..68af339e039 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/GeoChecks.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/GeoChecks.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding; public enum GeoChecks { diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/GeoRaster.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/GeoRaster.java index eea7a9d096e..a3728df1bc9 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/GeoRaster.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/GeoRaster.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding; public class GeoRaster { diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/InverseCoding.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/InverseCoding.java index 44689e93fc6..aabb81fb3c7 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/InverseCoding.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/InverseCoding.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding; import org.esa.snap.core.datamodel.GeoPos; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/ForwardPlugin.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/ForwardPlugin.java index 9d1620a34f8..5b16adb83af 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/ForwardPlugin.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/ForwardPlugin.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.forward; import org.esa.snap.core.dataio.geocoding.ForwardCoding; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/PixelForward.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/PixelForward.java index d6c8f31c176..af4790173f3 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/PixelForward.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/PixelForward.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.forward; import org.esa.snap.core.dataio.geocoding.ForwardCoding; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/PixelInterpolatingForward.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/PixelInterpolatingForward.java index 5d0c1da0442..abcef4529d4 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/PixelInterpolatingForward.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/PixelInterpolatingForward.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.forward; import org.esa.snap.core.dataio.geocoding.ForwardCoding; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointBilinearForward.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointBilinearForward.java index 6ba9e89ec2a..93d64a047c3 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointBilinearForward.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointBilinearForward.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.forward; import org.esa.snap.core.dataio.geocoding.ForwardCoding; @@ -26,9 +44,9 @@ public void initialize(GeoRaster geoRaster, boolean containsAntiMeridian, PixelP int discontinuity = containsAntiMeridian ? TiePointGrid.DISCONT_AT_180 : TiePointGrid.DISCONT_NONE; lonGrid = new TiePointGrid("lon", geoRaster.getRasterWidth(), geoRaster.getRasterHeight(), - geoRaster.getOffsetX(), geoRaster.getOffsetY(), - geoRaster.getSubsamplingX(), geoRaster.getSubsamplingY(), - RasterUtils.toFloat(geoRaster.getLongitudes()), discontinuity); + geoRaster.getOffsetX(), geoRaster.getOffsetY(), + geoRaster.getSubsamplingX(), geoRaster.getSubsamplingY(), + RasterUtils.toFloat(geoRaster.getLongitudes()), discontinuity); latGrid = new TiePointGrid("lat", geoRaster.getRasterWidth(), geoRaster.getRasterHeight(), geoRaster.getOffsetX(), geoRaster.getOffsetY(), @@ -52,7 +70,7 @@ public GeoPos getGeoPos(PixelPos pixelPos, GeoPos geoPos) { geoPos = new GeoPos(); } if (pixelPos.x < 0 || pixelPos.x > sceneWidth - || pixelPos.y < 0 || pixelPos.y > sceneHeight) { + || pixelPos.y < 0 || pixelPos.y > sceneHeight) { geoPos.setInvalid(); } else { geoPos.lat = latGrid.getPixelDouble(pixelPos.x, pixelPos.y); diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointForward.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointForward.java index f40e85db5d9..024dfd42be2 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointForward.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointForward.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.forward; import org.esa.snap.core.dataio.geocoding.ForwardCoding; @@ -8,11 +26,11 @@ abstract class TiePointForward implements ForwardCoding { void checkGrids(TiePointGrid lonGrid, TiePointGrid latGrid) { if (lonGrid.getGridWidth() != latGrid.getGridWidth() || - lonGrid.getGridHeight() != latGrid.getGridHeight() || - lonGrid.getOffsetX() != latGrid.getOffsetX() || - lonGrid.getOffsetY() != latGrid.getOffsetY() || - lonGrid.getSubSamplingX() != latGrid.getSubSamplingX() || - lonGrid.getSubSamplingY() != latGrid.getSubSamplingY()) { + lonGrid.getGridHeight() != latGrid.getGridHeight() || + lonGrid.getOffsetX() != latGrid.getOffsetX() || + lonGrid.getOffsetY() != latGrid.getOffsetY() || + lonGrid.getSubSamplingX() != latGrid.getSubSamplingX() || + lonGrid.getSubSamplingY() != latGrid.getSubSamplingY()) { throw new IllegalArgumentException("lonGrid is not compatible with latGrid"); } } diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointSplineForward.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointSplineForward.java index 6e1340e2b4d..0d85cc5119b 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointSplineForward.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/forward/TiePointSplineForward.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.forward; import org.esa.snap.core.dataio.geocoding.ForwardCoding; @@ -45,7 +63,7 @@ public GeoPos getGeoPos(PixelPos pixelPos, GeoPos geoPos) { final double y = pixelPos.y - geoRaster.getOffsetY(); if (x < 0 || x > geoRaster.getSceneWidth() - || y < 0 || y > geoRaster.getSceneHeight()) { + || y < 0 || y > geoRaster.getSceneHeight()) { geoPos.setInvalid(); } else { final InterpolationContext ic = contextTL.get(); diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/InversePlugin.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/InversePlugin.java index 47f1e092cf3..904f34d4760 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/InversePlugin.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/InversePlugin.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.inverse; import org.esa.snap.core.dataio.geocoding.InverseCoding; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/PixelGeoIndexInverse.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/PixelGeoIndexInverse.java index cbda79172da..833854babae 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/PixelGeoIndexInverse.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/PixelGeoIndexInverse.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.inverse; import org.esa.snap.core.dataio.geocoding.GeoRaster; @@ -76,7 +94,8 @@ public PixelPos getPixelPos(GeoPos geoPos, PixelPos pixelPos) { if (distance < epsilon) { if (fractionalAccuracy) { final InterpolationContext context = InterpolationContext.extract((int) pixelPos.x, (int) pixelPos.y, longitudes, latitudes, geoRaster.getSceneWidth(), geoRaster.getSceneHeight()); - pixelPos = interpolator.interpolate(geoPos, pixelPos, context); + final PixelPos interpolated = interpolator.interpolate(geoPos, pixelPos, context); + pixelPos.setLocation(interpolated.x, interpolated.y); } pixelPos.x = pixelPos.x + geoRaster.getOffsetX(); diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/PixelQuadTreeInverse.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/PixelQuadTreeInverse.java index 69635cf3a80..155907ccd9e 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/PixelQuadTreeInverse.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/PixelQuadTreeInverse.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.inverse; import org.esa.snap.core.dataio.geocoding.GeoRaster; @@ -379,7 +397,10 @@ static Segment[] splitAtAntiMeridian(Segment segment, SegmentCoverage segmentCov lon_r = geoPos.lon; } - if (y_l < MIN_DIMENSION && y_r < MIN_DIMENSION) { + final int segmentMinY = segment.y_min + MIN_DIMENSION; + final int segmentMaxY = segment.y_max - MIN_DIMENSION; + if ((y_l < segmentMinY || y_l > segmentMaxY) && + (y_r < segmentMinY || y_r > segmentMaxY) ) { // antimeridian not passing through segment in a way that enables across-swath splitting return new Segment[0]; } @@ -417,7 +438,9 @@ static Segment[] splitAtAntiMeridian(Segment segment, SegmentCoverage segmentCov } lon_b = geoPos.lon; } - if (x_t < MIN_DIMENSION && x_b < MIN_DIMENSION) { + final int segmentMinX = segment.x_min + MIN_DIMENSION; + final int segmentMaxX = segment.x_max - MIN_DIMENSION; + if ((x_t < segmentMinX || x_t > segmentMaxX) && (x_b < segmentMinX || x_b > segmentMaxX)) { // antimeridian not passing through segment in a way that enables across-swath splitting return new Segment[0]; } @@ -499,8 +522,8 @@ public PixelPos getPixelPos(GeoPos geoPos, PixelPos pixelPos) { if (minDelta < epsilon && minDeltaResult != null) { if (fractionalAccuracy) { final InterpolationContext context = InterpolationContext.extract(minDeltaResult.x, minDeltaResult.y, longitudes, latitudes, rasterWidth, rasterHeight); - pixelPos = interpolator.interpolate(geoPos, pixelPos, context); - pixelPos.setLocation(pixelPos.x + offsetX, pixelPos.y + offsetY); + final PixelPos interpolated = interpolator.interpolate(geoPos, pixelPos, context); + pixelPos.setLocation(interpolated.x + offsetX, interpolated.y + offsetY); } else { pixelPos.setLocation(minDeltaResult.x + offsetX, minDeltaResult.y + offsetY); } @@ -674,6 +697,11 @@ private boolean quadTreeSearch(final int depth, } final int idx = (int) Math.floor((Math.abs(latMin) + Math.abs(latMax)) / 2 * 10); + if (idx < 0 || idx >= epsilonLon.length) { + // this might be triggered by fillValue pixels tb 2021-06-10 + return false; + } + final double epsLon = epsilonLon[idx]; if (isCrossingMeridian && isCrossingAntiMeridianInsideQuad(lonArray)) { boolean lonOutside = false; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/Result.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/Result.java index 23a3bec7ab1..44a5968fafd 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/Result.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/Result.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.inverse; class Result { diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/TiePointInverse.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/TiePointInverse.java index 47433f707ca..8cf655119cc 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/TiePointInverse.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/inverse/TiePointInverse.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.inverse; import org.esa.snap.core.dataio.geocoding.GeoRaster; @@ -39,10 +57,12 @@ static Approximation getBestApproximation(Approximation[] approximations, double double minSquareDistance = Double.MAX_VALUE; for (final Approximation approx : approximations) { - final double squareDistance = approx.getSquareDistance(lat, lon); - if (squareDistance < minSquareDistance && squareDistance < approx.getMinSquareDistance()) { - minSquareDistance = squareDistance; - approximation = approx; + if (approx != null) { + final double squareDistance = approx.getSquareDistance(lat, lon); + if (squareDistance < minSquareDistance && squareDistance < approx.getMinSquareDistance()) { + minSquareDistance = squareDistance; + approximation = approx; + } } } @@ -135,9 +155,6 @@ static Approximation[] getApproximations(TiePointGrid lonGrid, TiePointGrid latG final Rectangle[] rectangles = MathUtils.subdivideRectangle(width, height, numTilesI, numTilesJ, 1); for (int i = 0; i < rectangles.length; i++) { final Approximation approximation = createApproximation(lonGrid, latGrid, rectangles[i]); - if (approximation == null) { - return null; - } approximations[i] = approximation; } diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/Approximation.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/Approximation.java index 9bc9c8cf770..e1b0ffbc4bc 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/Approximation.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/Approximation.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.util; import org.esa.snap.core.util.math.FXYSum; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/DistanceWeightingInterpolator.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/DistanceWeightingInterpolator.java index ba89278ef9f..0a3e37efe2d 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/DistanceWeightingInterpolator.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/DistanceWeightingInterpolator.java @@ -53,11 +53,6 @@ public PixelPos interpolate(GeoPos geoPos, PixelPos pixelPos, InterpolationConte } inv_sum = 1.0 / inv_sum; - if (pixelPos == null) { - pixelPos = new PixelPos(); - } - pixelPos.x = x_sum * inv_sum; - pixelPos.y = y_sum * inv_sum; - return pixelPos; + return new PixelPos(x_sum * inv_sum, y_sum * inv_sum); } } diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/EllipsoidDistance.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/EllipsoidDistance.java index b46ef6bac2b..3b459b6a1fd 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/EllipsoidDistance.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/EllipsoidDistance.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.util; import org.esa.snap.core.util.math.DistanceMeasure; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/InterpolationContext.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/InterpolationContext.java index 72840d6f790..286590f5a44 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/InterpolationContext.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/InterpolationContext.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.util; import org.esa.snap.core.util.math.EuclideanDistance; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/RasterUtils.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/RasterUtils.java index ae1e3c64995..49073512f70 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/RasterUtils.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/RasterUtils.java @@ -20,7 +20,6 @@ import org.esa.snap.core.dataio.geocoding.Discontinuity; import org.esa.snap.core.dataio.geocoding.GeoRaster; -import org.esa.snap.core.datamodel.GeoPos; import org.esa.snap.core.datamodel.PixelPos; import org.esa.snap.core.datamodel.ProductData; import org.esa.snap.core.datamodel.RasterDataNode; @@ -29,7 +28,8 @@ import org.geotools.referencing.crs.DefaultGeographicCRS; import org.opengis.referencing.datum.Ellipsoid; -import java.awt.*; +import java.awt.Dimension; +import java.awt.Rectangle; import java.awt.image.DataBufferDouble; import java.awt.image.Raster; import java.awt.image.SampleModel; @@ -173,7 +173,7 @@ public static float[] toFloat(double[] doubles) { return floats; } - static double[] toDouble(float[] floats) { + public static double[] toDouble(float[] floats) { final double[] doubles = new double[floats.length]; for (int i = 0; i < floats.length; i++) { @@ -228,15 +228,17 @@ public static double[] loadGeoData(RasterDataNode dataNode) throws IOException { } } - // returns al (x/y) positions that have a latitude above the defined pole-angle threshold - private static ArrayList findPoleCandidates(GeoRaster geoRaster, double maxLat, double minLat) { + // returns all (x/y) positions that have a latitude above the defined pole-angle threshold + static ArrayList findPoleCandidates(GeoRaster geoRaster, double maxLat, double minLat) { final ArrayList poleCandidates = new ArrayList<>(); final double[] latitudes = geoRaster.getLatitudes(); final int rasterWidth = geoRaster.getRasterWidth(); - for (int y = 0; y < geoRaster.getRasterHeight(); y++) { + final int rasterHeight = geoRaster.getRasterHeight(); + // skip boundary pixels, subsequent longitude iteration will fail, if candidate is on the edge of the scene + for (int y = 1; y < rasterHeight - 1; y++) { final int lineOffset = y * rasterWidth; - for (int x = 0; x < rasterWidth; x++) { + for (int x = 1; x < rasterWidth - 1; x++) { final double lat = latitudes[lineOffset + x]; if ((lat >= maxLat) || (lat <= minLat)) { poleCandidates.add(new PixelPos(x, y)); @@ -284,10 +286,6 @@ public static double computeResolutionInKm(double[] lonData, double[] latData, f return distanceMeanRadian * meanEarthRadiusKm; } - public static void printPointWkt(GeoPos geoPos) { - System.out.println("POINT( " + geoPos.lon + " " + geoPos.lat + ")"); - } - private static Rectangle getCenterExtractWindow(int width, int height) { final Rectangle R = new Rectangle(0, 0, 10, 10); R.width = Math.min(R.width, width); diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/SplineInterpolator.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/SplineInterpolator.java index 2009afdae8b..289f44e1b50 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/SplineInterpolator.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/SplineInterpolator.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.util; import java.util.Arrays; diff --git a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/XYInterpolator.java b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/XYInterpolator.java index 05c779576a9..33965be46ff 100644 --- a/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/XYInterpolator.java +++ b/snap-core/src/main/java/org/esa/snap/core/dataio/geocoding/util/XYInterpolator.java @@ -1,3 +1,21 @@ +/* + * + * Copyright (C) 2020 Brockmann Consult GmbH (info@brockmann-consult.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + * + */ + package org.esa.snap.core.dataio.geocoding.util; import org.esa.snap.core.datamodel.GeoPos; @@ -7,6 +25,14 @@ public interface XYInterpolator { String SYSPROP_GEOCODING_INTERPOLATOR = "snap.core.geocoding.interpolator"; + /** + * Interpolates the PixelPos based on the GeoPos + * + * @param geoPos the geo position + * @param pixelPos the pixel position + * @param context the interpolation context + * @return the new interpolated pixel position + */ PixelPos interpolate(GeoPos geoPos, PixelPos pixelPos, InterpolationContext context); enum Type { diff --git a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistableTest.java b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistableTest.java index 0ac2faee7dd..d83a7231c79 100644 --- a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistableTest.java +++ b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersistableTest.java @@ -6,10 +6,29 @@ import org.junit.Before; import org.junit.Test; -import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.*; -import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingTestUtils.*; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_COMPONENT_GEO_CODING; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_FORWARD_CODING_KEY; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_GEO_CHECKS; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_GEO_CRS; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_INVERSE_CODING_KEY; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_LAT_VARIABLE_NAME; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_LON_VARIABLE_NAME; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_OFFSET_X; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_OFFSET_Y; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_RASTER_RESOLUTION_KM; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_SUBSAMPLING_X; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_SUBSAMPLING_Y; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingTestUtils.createProduct; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingTestUtils.initializeWithBands; +import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingTestUtils.initializeWithTiePoints; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertNotSame; public class ComponentGeoCodingPersistableTest { @@ -17,7 +36,7 @@ public class ComponentGeoCodingPersistableTest { private Product product; private static final String LS = System.lineSeparator(); - private static String EXPECTED_GEO_CRS = "GEOGCS[\"WGS84(DD)\", " + LS + + private static final String EXPECTED_GEO_CRS = "GEOGCS[\"WGS84(DD)\", " + LS + " DATUM[\"WGS84\", " + LS + " SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], " + LS + " PRIMEM[\"Greenwich\", 0.0], " + LS + diff --git a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersitableSpiTest.java b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersitableSpiTest.java index 65f22da248e..7a9484d2d4a 100644 --- a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersitableSpiTest.java +++ b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingPersitableSpiTest.java @@ -6,8 +6,8 @@ import org.junit.Test; import static org.esa.snap.core.dataio.geocoding.ComponentGeoCodingPersistable.TAG_COMPONENT_GEO_CODING; -import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; public class ComponentGeoCodingPersitableSpiTest { diff --git a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingTest.java b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingTest.java index c45587550b9..871bf932d96 100644 --- a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingTest.java +++ b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingTest.java @@ -17,7 +17,6 @@ import org.junit.Before; import org.junit.Test; import org.opengis.referencing.operation.MathTransform; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -432,8 +431,8 @@ public void testGetDatum() { try { geoCoding.getDatum(); - fail("NotImplementedException expected"); - } catch (NotImplementedException expected) { + fail("IllegalStateException expected"); + } catch (IllegalStateException expected) { } } } diff --git a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingTestUtils.java b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingTestUtils.java index e9addf44f59..335d217cde2 100644 --- a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingTestUtils.java +++ b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/ComponentGeoCodingTestUtils.java @@ -143,10 +143,10 @@ public static float[][] createTiePointFloats(boolean withAntimeridian) { return new float[][]{lon, lat}; } - public static double[] toD(float[] lons) { - final double[] doubles = new double[lons.length]; - for (int i = 0; i < lons.length; i++) { - doubles[i] = lons[i]; + public static double[] toD(float[] floats) { + final double[] doubles = new double[floats.length]; + for (int i = 0; i < floats.length; i++) { + doubles[i] = floats[i]; } return doubles; } diff --git a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/forward/PixelForwardTest.java b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/forward/PixelForwardTest.java index 26f2da040fb..45d0d99637f 100644 --- a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/forward/PixelForwardTest.java +++ b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/forward/PixelForwardTest.java @@ -152,4 +152,46 @@ public void testPluginCreate() { final ForwardCoding forwardCoding = plugin.create(); assertTrue(forwardCoding instanceof PixelForward); } + + @Test + public void testNoInterpolationX() { + final GeoRaster geoRaster = TestData.get_FlatEarth(); + + pixelForward.initialize(geoRaster, false, new PixelPos[0]); + + final PixelPos pixelPos = new PixelPos(5.5, 5.5); + + GeoPos geoPos = null; + for (int i = 0; i <= 10; i++) { + pixelPos.x = 5.5 + (0.1 * i); + geoPos = pixelForward.getGeoPos(pixelPos, null); + if (i < 5) { + assertEquals(25.0, geoPos.lon, 1e-8); + } else { + assertEquals(26.0, geoPos.lon, 1e-8); + } + assertEquals(44.0, geoPos.lat, 1e-8); + } + } + + @Test + public void testNoInterpolationY() { + final GeoRaster geoRaster = TestData.get_FlatEarth(); + + pixelForward.initialize(geoRaster, false, new PixelPos[0]); + + final PixelPos pixelPos = new PixelPos(5.5, 5.5); + + GeoPos geoPos = null; + for (int i = 0; i <= 10; i++) { + pixelPos.y = 5.5 + (0.1 * i); + geoPos = pixelForward.getGeoPos(pixelPos, null); + assertEquals(25.0, geoPos.lon, 1e-8); + if (i < 5) { + assertEquals(44.0, geoPos.lat, 1e-8); + } else { + assertEquals(43.0, geoPos.lat, 1e-8); + } + } + } } diff --git a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/forward/PixelInterpolatingForwardTest.java b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/forward/PixelInterpolatingForwardTest.java index 0ea8c95ac89..63d86971f23 100644 --- a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/forward/PixelInterpolatingForwardTest.java +++ b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/forward/PixelInterpolatingForwardTest.java @@ -197,4 +197,46 @@ public void testPlugin_create() { final ForwardCoding forwardCoding = plugin.create(); assertTrue(forwardCoding instanceof PixelInterpolatingForward); } + + @Test + public void testInterpolationX() { + final GeoRaster geoRaster = TestData.get_FlatEarth(); + + pixelForward.initialize(geoRaster, false, new PixelPos[0]); + + final double[] pixelPosX = { + 5.5, 5.6, 5.7, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5 + }; + final double[] expGeoLon = { + 25.0, 25.1, 25.2, 25.3, 25.4, 25.5, 25.6, 25.7, 25.8, 25.9, 26.0 + }; + GeoPos geoPos = null; + for (int i = 0; i <= 10; i++) { + final double x = pixelPosX[i]; + geoPos = pixelForward.getGeoPos(new PixelPos(x, 5.5), null); + assertEquals(expGeoLon[i], geoPos.lon, 1e-8); + assertEquals(44.0, geoPos.lat, 1e-8); + } + } + + @Test + public void testInterpolationY() { + final GeoRaster geoRaster = TestData.get_FlatEarth(); + + pixelForward.initialize(geoRaster, false, new PixelPos[0]); + + final double[] pixelPosY = { + 5.5, 5.6, 5.7, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5 + }; + final double[] expGeoLat = { + 44.0, 43.9, 43.8, 43.7, 43.6, 43.5, 43.4, 43.3, 43.2, 43.1, 43.0 + }; + GeoPos geoPos = null; + for (int i = 0; i <= 10; i++) { + final double y = pixelPosY[i]; + geoPos = pixelForward.getGeoPos(new PixelPos(5.5, y), null); + assertEquals(25.0, geoPos.lon, 1e-8); + assertEquals(expGeoLat[i], geoPos.lat, 1e-8); + } + } } diff --git a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/inverse/PixelQuadTreeInverseTest.java b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/inverse/PixelQuadTreeInverseTest.java index 9531cfa35cb..283328d12de 100644 --- a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/inverse/PixelQuadTreeInverseTest.java +++ b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/inverse/PixelQuadTreeInverseTest.java @@ -16,10 +16,7 @@ import static java.lang.Double.NaN; import static org.esa.snap.core.dataio.geocoding.TestData.get_SLSTR_OL; import static org.esa.snap.core.dataio.geocoding.util.XYInterpolator.SYSPROP_GEOCODING_INTERPOLATOR; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; public class PixelQuadTreeInverseTest { @@ -136,7 +133,7 @@ public void testGetPixelPos_OLCI_interpolating_geodetic_distance() { // interpolate in y direction between replicated pixels pixelPos = inverse.getPixelPos(new GeoPos(66.49456, -24.169599), null); assertEquals(6, pixelPos.x, 1e-8); - assertEquals(13.750093939267787, pixelPos.y, 1e-8); + assertEquals(13.750093939267787, pixelPos.y, 1e-7); // interpolate in lat-direction pixelPos = inverse.getPixelPos(new GeoPos(66.44213, -24.22587), null); @@ -1113,10 +1110,23 @@ public void testSplitAtAntiMeridian_AlongTrack_tooSmallSegment() { segment.lat_min = 0.0; segment.lat_max = 60.0; + // splitpoint is at x = 3 final Segment[] segments = PixelQuadTreeInverse.splitAtAntiMeridian(segment, SegmentCoverage.ALONG, new MockCalculator(179.8)); assertEquals(0, segments.length); } + @Test + public void testSplitAtAntiMeridian_AcrossTrack_tooSmallSegment() { + final Segment segment = new Segment(0, 199, 0, 399); + segment.lon_min = 170.0; + segment.lon_max = 30.0; + segment.lat_min = 0.0; + segment.lat_max = 60.0; + + final Segment[] segments = PixelQuadTreeInverse.splitAtAntiMeridian(segment, SegmentCoverage.ACROSS, new MockCalculator(160.3)); + assertEquals(0, segments.length); + } + @Test public void testSplitAtAntiMeridian_Invalid() { final Segment segment = new Segment(0, 99, 0, 399); diff --git a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/inverse/TiePointInverseTest.java b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/inverse/TiePointInverseTest.java index bff821b045e..07f4b417e20 100644 --- a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/inverse/TiePointInverseTest.java +++ b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/inverse/TiePointInverseTest.java @@ -1,6 +1,12 @@ package org.esa.snap.core.dataio.geocoding.inverse; -import org.esa.snap.core.dataio.geocoding.*; +import org.esa.snap.core.dataio.geocoding.AMSR2; +import org.esa.snap.core.dataio.geocoding.AMSRE; +import org.esa.snap.core.dataio.geocoding.AMSUB; +import org.esa.snap.core.dataio.geocoding.GeoRaster; +import org.esa.snap.core.dataio.geocoding.InverseCoding; +import org.esa.snap.core.dataio.geocoding.MERIS; +import org.esa.snap.core.dataio.geocoding.TestData; import org.esa.snap.core.dataio.geocoding.util.Approximation; import org.esa.snap.core.dataio.geocoding.util.RasterUtils; import org.esa.snap.core.datamodel.GeoPos; @@ -9,10 +15,14 @@ import org.esa.snap.core.util.math.FXYSum; import org.junit.Test; -import java.awt.*; +import java.awt.Rectangle; import static java.lang.Double.NaN; -import static org.junit.Assert.*; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; public class TiePointInverseTest { @@ -20,7 +30,7 @@ public class TiePointInverseTest { public void testNormalizeLonGrid_no_anti_meridian() { final float[] floatLongitudes = RasterUtils.toFloat(MERIS.MER_RR_LON); final TiePointGrid lonGrid = new TiePointGrid("lon", 5, 5, 0.5, 0.5, - 16, 16, floatLongitudes); + 16, 16, floatLongitudes); final TiePointGrid normalizedLonGrid = TiePointInverse.normalizeLonGrid(lonGrid); assertArrayEquals(floatLongitudes, normalizedLonGrid.getTiePoints(), 1e-8f); @@ -31,7 +41,7 @@ public void testNormalizeLonGrid_no_anti_meridian() { public void testNormalizeLonGrid_anti_meridian_east_normalized() { final float[] floatLongitudes = RasterUtils.toFloat(AMSUB.AMSUB_ANTI_MERID_LON); final TiePointGrid lonGrid = new TiePointGrid("lon", 31, 31, 0.5, 0.5, - 1.0, 1.0, floatLongitudes); + 1.0, 1.0, floatLongitudes); final TiePointGrid normalizedLonGrid = TiePointInverse.normalizeLonGrid(lonGrid); final float[] tiePoints = normalizedLonGrid.getTiePoints(); @@ -47,7 +57,7 @@ public void testNormalizeLonGrid_anti_meridian_east_normalized() { public void testNormalizeLonGrid_anti_meridian_west_normalized() { final float[] floatLongitudes = RasterUtils.toFloat(AMSR2.AMSR2_ANTI_MERID_LON); final TiePointGrid lonGrid = new TiePointGrid("lon", 32, 26, 0.5, 0.5, - 1.0, 1.0, floatLongitudes); + 1.0, 1.0, floatLongitudes); final TiePointGrid normalizedLonGrid = TiePointInverse.normalizeLonGrid(lonGrid); final float[] tiePoints = normalizedLonGrid.getTiePoints(); @@ -62,7 +72,7 @@ public void testNormalizeLonGrid_anti_meridian_west_normalized() { @Test public void testInitLatLonMinMax() { final TiePointInverse.Boundaries boundaries = TiePointInverse.initLatLonMinMax(RasterUtils.toFloat(MERIS.MER_RR_LON), - RasterUtils.toFloat(MERIS.MER_RR_LAT)); + RasterUtils.toFloat(MERIS.MER_RR_LAT)); assertEquals(17.256619943847657, boundaries.normalizedLonMin, 1e-8); assertEquals(19.767063604125976, boundaries.normalizedLonMax, 1e-8); @@ -76,7 +86,7 @@ public void testInitLatLonMinMax() { @Test public void testInitLatLonMinMax_overlap_start_corrected() { final TiePointInverse.Boundaries boundaries = TiePointInverse.initLatLonMinMax(new float[]{-181, -180, -179, -178}, - new float[]{11, 12, 13, 14}); + new float[]{11, 12, 13, 14}); assertEquals(-181.00001, boundaries.normalizedLonMin, 1e-8); assertEquals(-177.99999, boundaries.normalizedLonMax, 1e-8); @@ -90,7 +100,7 @@ public void testInitLatLonMinMax_overlap_start_corrected() { @Test public void testInitLatLonMinMax_overlap_end_corrected() { final TiePointInverse.Boundaries boundaries = TiePointInverse.initLatLonMinMax(new float[]{179, 180, 181, 182}, - new float[]{12, 13, 14, 15}); + new float[]{12, 13, 14, 15}); assertEquals(178.99999, boundaries.normalizedLonMin, 1e-8); assertEquals(182.00001, boundaries.normalizedLonMax, 1e-8); @@ -119,9 +129,9 @@ public void testDetermineWarpParameters() { @Test public void testCreateWarpPoints() { final TiePointGrid lonGrid = new TiePointGrid("lon", 9, 9, 0.5, 0.5, - 3, 3, RasterUtils.toFloat(TestData.getSubSampled(3, AMSRE.AMSRE_HIGH_RES_LON, 25))); + 3, 3, RasterUtils.toFloat(TestData.getSubSampled(3, AMSRE.AMSRE_HIGH_RES_LON, 25))); final TiePointGrid latGrid = new TiePointGrid("lat", 9, 9, 0.5, 0.5, - 3, 3, RasterUtils.toFloat(TestData.getSubSampled(3, AMSRE.AMSRE_HIGH_RES_LAT, 25))); + 3, 3, RasterUtils.toFloat(TestData.getSubSampled(3, AMSRE.AMSRE_HIGH_RES_LAT, 25))); final Rectangle subsetRect = new Rectangle(2, 1, 6, 6); final double[][] warpPoints = TiePointInverse.createWarpPoints(lonGrid, latGrid, subsetRect); @@ -228,9 +238,9 @@ public void testGetBestPolynomial_linear_six_points_highRes() { @Test public void testCreateApproximation() { final TiePointGrid lonGrid = new TiePointGrid("lon", 5, 5, 0.5, 0.5, - 16, 16, RasterUtils.toFloat(MERIS.MER_RR_LON)); + 16, 16, RasterUtils.toFloat(MERIS.MER_RR_LON)); final TiePointGrid latGrid = new TiePointGrid("lat", 5, 5, 0.5, 0.5, - 16, 16, RasterUtils.toFloat(MERIS.MER_RR_LAT)); + 16, 16, RasterUtils.toFloat(MERIS.MER_RR_LAT)); final Rectangle subsetRect = new Rectangle(2, 1, 3, 3); final Approximation approximation = TiePointInverse.createApproximation(lonGrid, latGrid, subsetRect); @@ -245,9 +255,9 @@ public void testCreateApproximation() { @Test public void testGetApproximations_MER_RR_standard() { final TiePointGrid lonGrid = new TiePointGrid("lon", 5, 5, 0.5, 0.5, - 16, 16, RasterUtils.toFloat(MERIS.MER_RR_LON)); + 16, 16, RasterUtils.toFloat(MERIS.MER_RR_LON)); final TiePointGrid latGrid = new TiePointGrid("lat", 5, 5, 0.5, 0.5, - 16, 16, RasterUtils.toFloat(MERIS.MER_RR_LAT)); + 16, 16, RasterUtils.toFloat(MERIS.MER_RR_LAT)); final Approximation[] approximations = TiePointInverse.getApproximations(lonGrid, latGrid); assertNotNull(approximations); @@ -291,6 +301,38 @@ public void testGetApproximations_MER_RR__highRes() { } } + @Test + public void testGetApproximations_withFillValues() { + final int gridWidth = 26; + final int gridHeight = 35; + final float[] lonPoints = RasterUtils.toFloat(MERIS.MER_FSG_LON); + final float[] latPoints = RasterUtils.toFloat(MERIS.MER_FSG_LAT); + // create Regions with fill values + for (int i = 30 * gridWidth; i < latPoints.length; i++) { + latPoints[i] = -9999.9f; + lonPoints[i] = -9999.9f; + } + final TiePointGrid lonGrid = new TiePointGrid("lon", gridWidth, gridHeight, 0.5, 0.5, + 16, 16, lonPoints); + final TiePointGrid latGrid = new TiePointGrid("lat", gridWidth, gridHeight, 0.5, 0.5, + 16, 16, latPoints); + + final Approximation[] approximations = TiePointInverse.getApproximations(lonGrid, latGrid); + assertNotNull(approximations); + assertEquals(88, approximations.length); + assertNull(approximations[80]); + assertNull(approximations[87]); + + final Approximation approximation = approximations[0]; + assertEquals(15.23906010389328, approximation.getCenterLon(), 1e-8); + assertEquals(65.63226270675659, approximation.getCenterLat(), 1e-8); + assertEquals(2.0255989219997164E-4, approximation.getMinSquareDistance(), 1e-8); + //noinspection ConstantConditions + assertTrue(approximation.getFX() instanceof FXYSum); + //noinspection ConstantConditions + assertTrue(approximation.getFY() instanceof FXYSum); + } + @Test public void testNormalizeLat() { assertEquals(NaN, TiePointInverse.normalizeLat(-91.1), 1e-8); diff --git a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/util/RasterUtilsTest.java b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/util/RasterUtilsTest.java index 1cfd485d161..1cde3bec75b 100644 --- a/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/util/RasterUtilsTest.java +++ b/snap-core/src/test/java/org/esa/snap/core/dataio/geocoding/util/RasterUtilsTest.java @@ -1,10 +1,20 @@ package org.esa.snap.core.dataio.geocoding.util; -import org.esa.snap.core.dataio.geocoding.*; +import org.esa.snap.core.dataio.geocoding.AMSRE; +import org.esa.snap.core.dataio.geocoding.AMSUB; +import org.esa.snap.core.dataio.geocoding.Discontinuity; +import org.esa.snap.core.dataio.geocoding.GeoRaster; +import org.esa.snap.core.dataio.geocoding.MERIS; +import org.esa.snap.core.dataio.geocoding.TestData; import org.esa.snap.core.datamodel.PixelPos; import org.junit.Test; -import static org.junit.Assert.*; +import java.util.ArrayList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class RasterUtilsTest { @@ -41,6 +51,35 @@ public void testConstainsAntiMeridian_realData() { assertTrue(RasterUtils.containsAntiMeridian(AMSUB.AMSUB_ANTI_MERID_LON, 30)); } + @Test + public void testFindPoleCandidates() { + double[] longitudes = new double[]{ + 14.37, 32.99, 97.55, 144.09, + 2.05, 11.87, 115.3, 160.25, + -11.13, -15.76, -151.63, 178.72, + -23.9, -40.01, -115.36, -163.88 + }; + double[] latitudes = new double[]{ + 89.998, 89.959, 89.973, 89.946, + 89.932, 89.967, 89.987, 89.951, + 89.932, 89.968, 89.992, 89.952, + 89.930, 89.962, 89.979, 89.948 + }; + final GeoRaster geoRaster = new GeoRaster(longitudes, latitudes, null, null, 4, 4, 1.0); + + final double deltaToPole = RasterUtils.getLatDeltaToPole(10); + double maxLat = 90.0 - deltaToPole; + double minLat = -90.0 + deltaToPole; + + final ArrayList poleCandidates = RasterUtils.findPoleCandidates(geoRaster, maxLat, minLat); + assertEquals(4, poleCandidates.size()); // edge pixels are excluded + for (PixelPos pixelPos : poleCandidates) { + if (pixelPos.x == 0 || pixelPos.y == 0 || pixelPos.x == 3 && pixelPos.y == 3) { + fail("Pole candidate position [" + pixelPos.x + "," + pixelPos.y + "] not expected"); + } + } + } + @Test public void testGetPoleLocations_no_pole() { double[] longitudes = new double[]{54., 55., 56., 57., 58., 59f};