You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2022/05/24 16:49:09 UTC
[sis] branch geoapi-4.0 updated (9adfa358f6 -> 270416850b)
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
from 9adfa358f6 Add sliders for selecting the slice to show in a 3 (or more) dimensional data cube. Slider graduation is okay but selecting a value does not yet have an effect.
new b74a638936 Fix an erroneous temporal coordinate shown in the status bar with the CRS is (x,y,t).
new 6664478fd9 More compact representation of the temporal coordinate in a (x,y,t) tuple.
new 72c433cb3a Add a `GridExtent.setRange(…)` method. Change the order of some other methods for grouping related methods.
new 20be7e050e Build new `GridExtent` from slider positions.
new 270416850b More tolerant parsing of NaN value for GDAL_NODATA in TIFF file. It is sometime written as "nan" (all lower case).
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/sis/gui/coverage/GridSliceSelector.java | 66 ++++++++
.../java/org/apache/sis/gui/map/StatusBar.java | 19 +--
.../java/org/apache/sis/gui/map/package-info.java | 2 +-
.../org/apache/sis/coverage/grid/GridExtent.java | 179 +++++++++++++--------
.../apache/sis/coverage/grid/GridExtentTest.java | 58 ++++---
.../org/apache/sis/geometry/CoordinateFormat.java | 27 +++-
.../java/org/apache/sis/geometry/package-info.java | 2 +-
.../java/org/apache/sis/storage/geotiff/Type.java | 7 +-
8 files changed, 251 insertions(+), 109 deletions(-)
[sis] 02/05: More compact representation of the temporal coordinate in a (x,y,t) tuple.
Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 6664478fd9674bcb575257c9c68ade2eb1521676
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue May 24 18:44:33 2022 +0200
More compact representation of the temporal coordinate in a (x,y,t) tuple.
---
.../org/apache/sis/geometry/CoordinateFormat.java | 27 +++++++++++++++++++++-
.../java/org/apache/sis/geometry/package-info.java | 2 +-
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java b/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java
index 7fd75e5ea1..e00e4329e7 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java
@@ -100,7 +100,7 @@ import static java.util.logging.Logger.getLogger;
* transform the position} before to format it.</p>
*
* @author Martin Desruisseaux (MPO, IRD, Geomatys)
- * @version 1.2
+ * @version 1.3
*
* @see AngleFormat
* @see org.apache.sis.measure.UnitFormat
@@ -1333,6 +1333,31 @@ abort: if (dimensions != 0 && groundAccuracy != null) try {
return DirectPosition.class;
}
+ /**
+ * Creates a new format to use for parsing and formatting values of the given type.
+ * This method is invoked by {@link #getFormat(Class)} the first time that a format
+ * is needed for the given type.
+ *
+ * <p>See {@linkplain CompoundFormat#createFormat(Class) super-class} for a description of recognized types.
+ * This method override uses the short date pattern instead of the (longer) default one.</p>
+ *
+ * @param valueType the base type of values to parse or format.
+ * @return the format to use for parsing of formatting values of the given type, or {@code null} if none.
+ */
+ @Override
+ protected Format createFormat(final Class<?> valueType) {
+ if (valueType == Date.class) {
+ final Locale locale = super.getLocale();
+ if (!Locale.ROOT.equals(locale)) {
+ final DateFormat format;
+ format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
+ format.setTimeZone(getTimeZone());
+ return format;
+ }
+ }
+ return super.createFormat(valueType);
+ }
+
/**
* Formats the given coordinate.
* The type of each coordinate value (number, angle or date) is determined by the CRS of the given
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/package-info.java b/core/sis-referencing/src/main/java/org/apache/sis/geometry/package-info.java
index 16eb301b67..f4500dbb9a 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/package-info.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/package-info.java
@@ -87,7 +87,7 @@
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @author Alexis Manin (Geomatys)
- * @version 1.2
+ * @version 1.3
* @since 0.3
* @module
*/
[sis] 05/05: More tolerant parsing of NaN value for GDAL_NODATA in TIFF file. It is sometime written as "nan" (all lower case).
Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 270416850b5bdc9b3bcd4dcddbe9bb9760bbfa91
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue May 24 18:46:58 2022 +0200
More tolerant parsing of NaN value for GDAL_NODATA in TIFF file.
It is sometime written as "nan" (all lower case).
---
.../src/main/java/org/apache/sis/storage/geotiff/Type.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java
index 893b0e51cc..dce49e9c21 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java
@@ -388,8 +388,11 @@ enum Type {
}
@Override public double readDouble(final ChannelDataInput input, final long count) throws IOException {
- final String text = readString(input, count, false);
- return (text != null) ? Double.parseDouble(text) : Double.NaN;
+ String text = readString(input, count, false);
+ if (text == null || (text = text.trim()).isEmpty() || text.equalsIgnoreCase("NaN")) {
+ return Double.NaN;
+ }
+ return Double.parseDouble(text);
}
@Override public Object readArray(final ChannelDataInput input, final int count) throws IOException {
[sis] 01/05: Fix an erroneous temporal coordinate shown in the status bar with the CRS is (x,y,t).
Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit b74a6389366d6f31515f7c264213d9ee5fb53d4a
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue May 24 18:43:48 2022 +0200
Fix an erroneous temporal coordinate shown in the status bar with the CRS is (x,y,t).
---
.../main/java/org/apache/sis/gui/map/StatusBar.java | 19 +++++++------------
.../java/org/apache/sis/gui/map/package-info.java | 2 +-
2 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java
index 1f2496a503..6688f8d3b2 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java
@@ -110,7 +110,7 @@ import org.apache.sis.referencing.IdentifiedObjects;
* {@link #setLocalCoordinates(double, double)} explicitly instead.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.2
+ * @version 1.3
* @since 1.1
* @module
*/
@@ -271,8 +271,8 @@ public class StatusBar extends Widget implements EventHandler<MouseEvent> {
/**
* The source local indices before conversion to geospatial coordinates (never {@code null}).
* The number of dimensions is often {@value #BIDIMENSIONAL}. May be the same array than
- * <code>{@linkplain #targetCoordinates}.coordinates</code> because some transforms are
- * faster when the source and destination arrays are the same.
+ * <code>{@linkplain #targetCoordinates}.coordinates</code> if both are two-dimensional
+ * (if more than 2 dimensions, we need to avoid overwriting values in extra dimensions).
*
* @see #targetCoordinates
* @see #position
@@ -660,7 +660,7 @@ public class StatusBar extends Widget implements EventHandler<MouseEvent> {
*/
((LocalToObjective) localToObjectiveCRS).setNoCheck(localToCRS);
targetCoordinates = new GeneralDirectPosition(tgtDim);
- sourceCoordinates = (srcDim == tgtDim) ? targetCoordinates.coordinates : new double[srcDim];
+ sourceCoordinates = new double[srcDim];
objectiveCRS = crs;
localToPositionCRS = localToCRS; // May be updated again below.
inflatePrecisions = inflate;
@@ -709,10 +709,6 @@ public class StatusBar extends Widget implements EventHandler<MouseEvent> {
if (tgtDim != 0 && tgtDim != targetCoordinates.getDimension()) {
precisions = null;
targetCoordinates = new GeneralDirectPosition(tgtDim);
- if (sourceCoordinates.length == tgtDim) {
- // Sharing the same array make some transforms faster.
- sourceCoordinates = targetCoordinates.coordinates;
- }
}
targetCoordinates.setCoordinateReferenceSystem(crs);
}
@@ -1102,10 +1098,9 @@ public class StatusBar extends Widget implements EventHandler<MouseEvent> {
}
/*
* Estimate the precision by looking at the maximal displacement in the CRS caused by
- * a displacement of one cell (i.e. when moving by one row or column). We search for
- * maximal displacement instead of minimal because we expect the displacement to be
- * zero along some axes (e.g. one row down does not change longitude value in a Plate
- * Carrée projection).
+ * a displacement of one cell (i.e. when moving by one row or column). We search for
+ * maximal displacement because we expect the displacement to be zero along some axes
+ * (e.g. one row down does not change longitude value in a Plate Carrée projection).
*/
for (int j=derivative.getNumRow(); --j >= 0;) {
double p = 0;
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/package-info.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/package-info.java
index 694f2d9bd8..4ddaa18730 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/package-info.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/package-info.java
@@ -22,7 +22,7 @@
* {@link org.apache.sis.gui.map.MapCanvasAWT} is a specialization for painting the map using Java2D.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.2
+ * @version 1.3
* @since 1.1
* @module
*/
[sis] 04/05: Build new `GridExtent` from slider positions.
Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 20be7e050ed43aea5c5dd6d5d5da6f0da86c2d44
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue May 24 18:47:36 2022 +0200
Build new `GridExtent` from slider positions.
---
.../apache/sis/gui/coverage/GridSliceSelector.java | 66 ++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridSliceSelector.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridSliceSelector.java
index 8137bf0c81..0868d3f495 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridSliceSelector.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridSliceSelector.java
@@ -36,6 +36,7 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyProperty;
+import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.SimpleObjectProperty;
import org.opengis.geometry.Envelope;
import org.opengis.util.FactoryException;
@@ -98,6 +99,13 @@ public class GridSliceSelector extends Widget {
*/
public final ObjectProperty<GridGeometry> gridGeometry;
+ /**
+ * The currently selected grid extent.
+ *
+ * @see #selectedExtentProperty()
+ */
+ private final ReadOnlyObjectWrapper<GridExtent> selectedExtent;
+
/**
* The locale to use for axis labels, or {@code null} for a default locale.
*/
@@ -142,6 +150,7 @@ public class GridSliceSelector extends Widget {
view.setVgap(9);
view.setHgap(12);
view.setPadding(PADDING);
+ selectedExtent = new ReadOnlyObjectWrapper<>(this, "selectedExtent");
gridGeometry = new SimpleObjectProperty<>(this, "gridGeometry");
gridGeometry.addListener((p,o,n) -> setGridGeometry(n));
}
@@ -166,6 +175,7 @@ public class GridSliceSelector extends Widget {
int childrenCount = 0;
int row = -BIDIMENSIONAL - 1;
final GridExtent extent = gg.getExtent();
+ GridExtent selected = extent;
final int dimension = extent.getDimension();
for (int dim=0; dim < dimension; dim++) {
final long min = extent.getLow (dim);
@@ -196,6 +206,7 @@ public class GridSliceSelector extends Widget {
converter = new Converter();
slider.setLabelFormatter(converter);
slider.widthProperty().addListener(converter);
+ slider.valueChangingProperty().addListener(new Listener(dim));
}
/*
* Configure the slider for the current grid axis.
@@ -215,6 +226,7 @@ public class GridSliceSelector extends Widget {
slider.setMin(min);
slider.setMax(max);
slider.setValue(min);
+ selected = selected.setRange(dim, min, min); // Initially selected slice.
converter.configure(gg, gridToCRS, dim, min, max, envelope, resolution);
converter.setTickSpacing(slider, slider.getWidth());
/*
@@ -232,8 +244,12 @@ public class GridSliceSelector extends Widget {
}
}
children.remove(childrenCount, children.size());
+ selectedExtent.set(selected);
}
+
+
+
/**
* Handle conversion of grid indices to "real world" coordinates or dates.
*/
@@ -451,6 +467,56 @@ public class GridSliceSelector extends Widget {
}
}
+
+
+
+ /**
+ * Listener notified when the position of a slider changed. We take the change only after
+ * the user finished to drag the slider in order to avoid causing to many load requests.
+ */
+ private final class Listener implements ChangeListener<Boolean> {
+ /**
+ * Index of the grid axis where the position changed.
+ */
+ private final int dimension;
+
+ /**
+ * Creates a new listener for the grid axis on the specified dimension.
+ *
+ * @param dimension index of the grid axis where the position can change.
+ */
+ Listener(final int dimension) {
+ this.dimension = dimension;
+ }
+
+ /**
+ * Invoked when the slider changed its position.
+ */
+ @Override
+ public void changed(final ObservableValue<? extends Boolean> property, final Boolean oldValue, final Boolean newValue) {
+ if (!newValue) {
+ final GridExtent extent = selectedExtent.get();
+ if (extent != null) {
+ final Slider slider = (Slider) ((ReadOnlyProperty) property).getBean();
+ final long p = Math.round(slider.getValue());
+ if (p != extent.getLow(dimension)) {
+ selectedExtent.set(extent.setRange(dimension, p, p));
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the property for the currently selected grid extent.
+ * This value varies after the user finished to drag the slider.
+ *
+ * @return the currently selected grid extent as a read-only property.
+ */
+ public final ReadOnlyProperty<GridExtent> selectedExtentProperty() {
+ return selectedExtent.getReadOnlyProperty();
+ }
+
/**
* Returns the encapsulated JavaFX component to add in a scene graph for making the selectors visible.
* The {@code Region} subclass is implementation dependent and may change in any future SIS version.
[sis] 03/05: Add a `GridExtent.setRange(…)` method. Change the order of some other methods for grouping related methods.
Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 72c433cb3a5401f535e70d91330c27f0d71e0903
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue May 24 18:46:08 2022 +0200
Add a `GridExtent.setRange(…)` method. Change the order of some other methods for grouping related methods.
---
.../org/apache/sis/coverage/grid/GridExtent.java | 179 +++++++++++++--------
.../apache/sis/coverage/grid/GridExtentTest.java | 58 ++++---
2 files changed, 145 insertions(+), 92 deletions(-)
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index 9064f91fdd..cf38ad7140 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -88,7 +88,7 @@ import org.opengis.coverage.PointOutsideCoverageException;
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @author Alexis Manin (Geomatys)
- * @version 1.2
+ * @version 1.3
* @since 1.0
* @module
*/
@@ -126,7 +126,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
/**
* A pool of shared {@link DimensionNameType} arrays. We use a pool
- * because a small amount of arrays is shared by most grid extent.
+ * because a small amount of arrays is shared by most grid extents.
*/
private static final WeakValueHashMap<DimensionNameType[],DimensionNameType[]> POOL = new WeakValueHashMap<>(DimensionNameType[].class);
@@ -221,9 +221,9 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Creates an initially empty grid envelope with the given number of dimensions.
+ * Creates an initially empty grid extent with the given number of dimensions.
* All grid coordinate values are initialized to zero. This constructor is private
- * since {@code GridExtent} coordinate values can not be modified by public API.
+ * because {@code GridExtent} coordinate values can not be modified by public API.
*
* @param dimension number of dimensions.
* @param axisTypes the axis types, or {@code null} if unspecified.
@@ -290,7 +290,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Constructs a new grid envelope set to the specified coordinates.
+ * Constructs a new grid extent set to the specified coordinates.
* The given arrays contain a minimum (inclusive) and maximum value for each dimension of the grid coverage.
* The lowest valid grid coordinates are often zero, but this is not mandatory.
* As a convenience for this common case, a null {@code low} array means that all low coordinates are zero.
@@ -578,7 +578,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
* Creates a copy of the given grid extent. The {@link #coordinates} array is cloned
* while the {@link #types} array is shared between the two instances. This constructor
* is reserved to methods that modify the coordinates after construction. It must be
- * private since we do not allow coordinates modifications by public API.
+ * private because we do not allow coordinates modifications by public API.
*
* @see #GridExtent(int, DimensionNameType[])
*/
@@ -588,9 +588,9 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Creates a new grid envelope as a copy of the given one.
+ * Creates a new grid extent as a copy of the given one.
*
- * @param extent the grid envelope to copy.
+ * @param extent the grid extent to copy.
* @throws IllegalArgumentException if a coordinate value in the low part is
* greater than the corresponding coordinate value in the high part.
*
@@ -609,12 +609,12 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Returns the given grid envelope as a {@code GridExtent} implementation.
+ * Returns the given grid extent as a {@code GridExtent} implementation.
* If the given extent is already a {@code GridExtent} instance or is null, then it is returned as-is.
* Otherwise a new extent is created using the {@linkplain #GridExtent(GridEnvelope) copy constructor}.
*
- * @param extent the grid envelope to cast or copy, or {@code null}.
- * @return the grid envelope as a {@code GridExtent}, or {@code null} if the given extent was null.
+ * @param extent the grid extent to cast or copy, or {@code null}.
+ * @return the grid extent as a {@code GridExtent}, or {@code null} if the given extent was null.
*/
public static GridExtent castOrCopy(final GridEnvelope extent) {
if (extent == null || extent instanceof GridExtent) {
@@ -686,6 +686,8 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
* The sequence contains a minimum value for each dimension of the grid coverage.
*
* @return the valid minimum grid coordinates, inclusive.
+ *
+ * @see #getLow(int)
*/
@Override
public GridCoordinates getLow() {
@@ -697,6 +699,8 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
* The sequence contains a maximum value for each dimension of the grid coverage.
*
* @return the valid maximum grid coordinates, <strong>inclusive</strong>.
+ *
+ * @see #getHigh(int)
*/
@Override
public GridCoordinates getHigh() {
@@ -713,6 +717,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
*
* @see #getLow()
* @see #getHigh(int)
+ * @see #setRange(int, long, long)
*/
@Override
public long getLow(final int index) {
@@ -730,6 +735,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
*
* @see #getHigh()
* @see #getLow(int)
+ * @see #setRange(int, long, long)
*/
@Override
public long getHigh(final int index) {
@@ -750,6 +756,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
*
* @see #getLow(int)
* @see #getHigh(int)
+ * @see #resize(long...)
*/
@Override
public long getSize(final int index) {
@@ -920,6 +927,37 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
return indexShown;
}
+ /**
+ * Returns a grid extent identical to this grid extent except for the coordinate values in the specified dimension.
+ *
+ * @param index the dimension for which to set the coordinate values.
+ * @param low the low coordinate value at the given dimension, inclusive.
+ * @param high the high coordinate value at the given dimension, <strong>inclusive</strong>.
+ * @return a grid extent with the specified coordinate values, or {@code this} if values are unchanged.
+ * @throws IllegalArgumentException if the low coordinate value is greater than the high coordinate value.
+ *
+ * @see #getLow(int)
+ * @see #getHigh(int)
+ *
+ * @since 1.3
+ */
+ public GridExtent setRange(final int index, final long low, final long high) {
+ int ih = getDimension();
+ ArgumentChecks.ensureValidIndex(ih, index);
+ ih += index;
+ if (coordinates[index] == low && coordinates[ih] == high) {
+ return this;
+ }
+ if (low > high) {
+ throw new IllegalArgumentException(Resources.format(
+ Resources.Keys.IllegalGridEnvelope_3, getAxisIdentification(index, index), low, high));
+ }
+ final GridExtent copy = new GridExtent(this);
+ copy.coordinates[index] = low;
+ copy.coordinates[ih] = high;
+ return copy;
+ }
+
/**
* Transforms this grid extent to a "real world" envelope using the given transform.
* The transform shall map <em>cell corner</em> to real world coordinates.
@@ -1055,7 +1093,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Returns a new grid envelope with the specified dimension inserted at the given index in this grid envelope.
+ * Returns a new grid extent with the specified dimension inserted at the given index in this grid extent.
* To append a new dimension after all existing dimensions, set {@code offset} to {@link #getDimension()}.
*
* @param offset where to insert the new dimension, from 0 to {@link #getDimension()} inclusive.
@@ -1065,7 +1103,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
* @param isHighIncluded {@code true} if the {@code high} value is inclusive (as in ISO 19123 specification),
* or {@code false} if it is exclusive (as in Java2D usage).
* This argument does not apply to {@code low} value, which is always inclusive.
- * @return a new grid envelope with the specified dimension added.
+ * @return a new grid extent with the specified dimension added.
* @throws IllegalArgumentException if the low coordinate value is greater than the high coordinate value.
*
* @since 1.1
@@ -1097,6 +1135,30 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
return ex;
}
+ /**
+ * Returns a grid extent that encompass only some dimensions of this grid extent.
+ * This method copies the specified dimensions of this grid extent into a new grid extent.
+ * The given dimensions must be in strictly ascending order without duplicated values.
+ * The number of dimensions of the sub grid extent will be {@code dimensions.length}.
+ *
+ * <p>This method performs a <cite>dimensionality reduction</cite> and can be used as the
+ * converse of {@link #insertDimension(int, DimensionNameType, long, long, boolean)}.
+ * This method can not be used for changing dimension order.</p>
+ *
+ * @param dimensions the dimensions to select, in strictly increasing order.
+ * @return the sub-envelope, or {@code this} if the given array contains all dimensions of this grid extent.
+ * @throws IndexOutOfBoundsException if an index is out of bounds.
+ *
+ * @see #getSubspaceDimensions(int)
+ * @see GridGeometry#reduce(int...)
+ *
+ * @since 1.1
+ */
+ public GridExtent reduceDimension(int... dimensions) {
+ dimensions = verifyDimensions(dimensions, getDimension());
+ return (dimensions != null) ? reorder(dimensions) : this;
+ }
+
/**
* Verifies the validity of a given {@code dimensions} argument.
*
@@ -1122,6 +1184,29 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
throw new IndexOutOfBoundsException(Errors.format(Errors.Keys.IndexOutOfBounds_1, d));
}
+ /**
+ * Changes axis order or reduces the number of dimensions.
+ * It is caller responsibility to ensure that the given dimensions are valid.
+ */
+ final GridExtent reorder(final int[] dimensions) {
+ final int sd = getDimension();
+ final int td = dimensions.length;
+ DimensionNameType[] tt = null;
+ if (types != null) {
+ tt = new DimensionNameType[td];
+ for (int i=0; i<td; i++) {
+ tt[i] = types[dimensions[i]];
+ }
+ }
+ final GridExtent sub = new GridExtent(td, tt);
+ for (int i=0; i<td; i++) {
+ final int j = dimensions[i];
+ sub.coordinates[i] = coordinates[j];
+ sub.coordinates[i+td] = coordinates[j+sd];
+ }
+ return sub;
+ }
+
/**
* Returns a grid extent expanded by the given amount of cells on both sides along each dimension.
* This method adds the given margins to the {@linkplain #getHigh(int) high coordinates}
@@ -1208,6 +1293,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
* @return a grid extent having the given sizes, or {@code this} if there is no change.
* @throws ArithmeticException if resizing this extent to the given size overflows {@code long} capacity.
*
+ * @see #getSize(int)
* @see GridDerivation#subgrid(GridExtent, int...)
*/
public GridExtent resize(final long... sizes) {
@@ -1238,53 +1324,6 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
return Arrays.equals(c, coordinates) ? this : resize;
}
- /**
- * Returns a grid extent that encompass only some dimensions of this grid extent.
- * This method copies the specified dimensions of this grid extent into a new grid extent.
- * The given dimensions must be in strictly ascending order without duplicated values.
- * The number of dimensions of the sub grid envelope will be {@code dimensions.length}.
- *
- * <p>This method performs a <cite>dimensionality reduction</cite> and can be used as the
- * converse of {@link #insertDimension(int, DimensionNameType, long, long, boolean)}.
- * This method can not be used for changing dimension order.</p>
- *
- * @param dimensions the dimensions to select, in strictly increasing order.
- * @return the sub-envelope, or {@code this} if the given array contains all dimensions of this grid extent.
- * @throws IndexOutOfBoundsException if an index is out of bounds.
- *
- * @see #getSubspaceDimensions(int)
- * @see GridGeometry#reduce(int...)
- *
- * @since 1.1
- */
- public GridExtent reduceDimension(int... dimensions) {
- dimensions = verifyDimensions(dimensions, getDimension());
- return (dimensions != null) ? reorder(dimensions) : this;
- }
-
- /**
- * Changes axis order or reduces the number of dimensions.
- * It is caller responsibility to ensure that the given dimensions are valid.
- */
- final GridExtent reorder(final int[] dimensions) {
- final int sd = getDimension();
- final int td = dimensions.length;
- DimensionNameType[] tt = null;
- if (types != null) {
- tt = new DimensionNameType[td];
- for (int i=0; i<td; i++) {
- tt[i] = types[dimensions[i]];
- }
- }
- final GridExtent sub = new GridExtent(td, tt);
- for (int i=0; i<td; i++) {
- final int j = dimensions[i];
- sub.coordinates[i] = coordinates[j];
- sub.coordinates[i+td] = coordinates[j+sd];
- }
- return sub;
- }
-
/**
* Creates a new grid extent subsampled by the given amount of cells along each grid dimensions.
* This method divides {@linkplain #getLow(int) low coordinates} and {@linkplain #getSize(int) grid sizes}
@@ -1535,10 +1574,10 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Returns a hash value for this grid envelope. This value needs not to remain
+ * Returns a hash value for this grid extent. This value needs not to remain
* consistent between different implementations of the same class.
*
- * @return a hash value for this grid envelope.
+ * @return a hash value for this grid extent.
*/
@Override
public int hashCode() {
@@ -1546,11 +1585,11 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Compares the specified object with this grid envelope for equality.
+ * Compares the specified object with this grid extent for equality.
* This method delegates to {@code equals(object, ComparisonMode.STRICT)}.
*
- * @param object the object to compare with this grid envelope for equality.
- * @return {@code true} if the given object is equal to this grid envelope.
+ * @param object the object to compare with this grid extent for equality.
+ * @return {@code true} if the given object is equal to this grid extent.
*/
@Override
public final boolean equals(final Object object) {
@@ -1558,13 +1597,13 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Compares the specified object with this grid envelope for equality.
+ * Compares the specified object with this grid extent for equality.
* If the mode is {@link ComparisonMode#IGNORE_METADATA} or more flexible,
* then the {@linkplain #getAxisType(int) axis types} are ignored.
*
- * @param object the object to compare with this grid envelope for equality.
+ * @param object the object to compare with this grid extent for equality.
* @param mode the strictness level of the comparison.
- * @return {@code true} if the given object is equal to this grid envelope.
+ * @return {@code true} if the given object is equal to this grid extent.
*
* @since 1.1
*/
@@ -1588,7 +1627,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Returns a string representation of this grid envelope. The returned string
+ * Returns a string representation of this grid extent. The returned string
* is implementation dependent and is provided for debugging purposes only.
*/
@Override
@@ -1603,7 +1642,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
}
/**
- * Writes a string representation of this grid envelope in the given buffer.
+ * Writes a string representation of this grid extent in the given buffer.
* This method is provided for allowing caller to recycle the same buffer.
*
* @param out where to write the string representation.
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
index b5fd1c0511..169740150b 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
@@ -45,7 +45,7 @@ import static org.apache.sis.test.ReferencingAssert.*;
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @author Alexis Manin (Geomatys)
- * @version 1.2
+ * @version 1.3
* @since 1.0
* @module
*/
@@ -137,12 +137,13 @@ public final strictfp class GridExtentTest extends TestCase {
* with {@code offset} set to {@link GridExtent#getDimension()}.
*/
@Test
- public void testAppend() {
+ public void testAppendDimension() {
appendOrInsert(2, 1);
}
/**
- * Tests {@link GridExtent#insertDimension(int, DimensionNameType, long, long, boolean)}.
+ * Tests {@link GridExtent#insertDimension(int, DimensionNameType, long, long, boolean)}
+ * with {@code offset} somewhere in the middle of the extent.
*/
@Test
public void testInsertDimension() {
@@ -165,6 +166,38 @@ public final strictfp class GridExtentTest extends TestCase {
assertEquals(DimensionNameType.TIME, extent.getAxisType(offset).get());
}
+ /**
+ * Tests {@link GridExtent#reduceDimension(int[])}.
+ */
+ @Test
+ public void testReduceDimension() {
+ final GridExtent extent = create3D();
+ GridExtent reduced = extent.reduceDimension(0, 1);
+ assertEquals("dimension", 2, reduced.getDimension());
+ assertExtentEquals(reduced, 0, 100, 499);
+ assertExtentEquals(reduced, 1, 200, 799);
+ assertEquals(DimensionNameType.COLUMN, reduced.getAxisType(0).get());
+ assertEquals(DimensionNameType.ROW, reduced.getAxisType(1).get());
+
+ reduced = extent.reduceDimension(2);
+ assertEquals("dimension", 1, reduced.getDimension());
+ assertExtentEquals(reduced, 0, 40, 49);
+ assertEquals(DimensionNameType.TIME, reduced.getAxisType(0).get());
+ }
+
+ /**
+ * Tests {@link GridExtent#setRange(int, long, long)}.
+ */
+ @Test
+ public void testSetRange() {
+ GridExtent extent = create3D();
+ assertSame(extent, extent.setRange(1, 200, 799));
+ extent = extent.setRange(2, 30, 60);
+ assertExtentEquals(extent, 0, 100, 499);
+ assertExtentEquals(extent, 1, 200, 799);
+ assertExtentEquals(extent, 2, 30, 60);
+ }
+
/**
* Tests {@link GridExtent#expand(long...)}.
*/
@@ -228,25 +261,6 @@ public final strictfp class GridExtentTest extends TestCase {
assertSame(extent.intersect(domain), extent);
}
- /**
- * Tests {@link GridExtent#reduceDimension(int[])}.
- */
- @Test
- public void testReduceDimension() {
- final GridExtent extent = create3D();
- GridExtent reduced = extent.reduceDimension(0, 1);
- assertEquals("dimension", 2, reduced.getDimension());
- assertExtentEquals(reduced, 0, 100, 499);
- assertExtentEquals(reduced, 1, 200, 799);
- assertEquals(DimensionNameType.COLUMN, reduced.getAxisType(0).get());
- assertEquals(DimensionNameType.ROW, reduced.getAxisType(1).get());
-
- reduced = extent.reduceDimension(2);
- assertEquals("dimension", 1, reduced.getDimension());
- assertExtentEquals(reduced, 0, 40, 49);
- assertEquals(DimensionNameType.TIME, reduced.getAxisType(0).get());
- }
-
/**
* Tests {@link GridExtent#slice(DirectPosition, int[])}.
*/