Skip to content

Commit 5c9e795

Browse files
committed
suppress SIS warning messages about unset environment variables
we don't care about it since we don't have the "proper" EPSG dataset available anyway
1 parent 3b47c85 commit 5c9e795

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

src/main/java/net/buildtheearth/terraplusplus/projection/sis/SISProjectionWrapper.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
import net.buildtheearth.terraplusplus.control.AdvancedEarthGui;
1111
import net.buildtheearth.terraplusplus.projection.GeographicProjection;
1212
import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException;
13+
import net.buildtheearth.terraplusplus.util.compat.sis.SISHelper;
1314
import net.daporkchop.lib.common.function.exception.EConsumer;
1415
import org.apache.sis.geometry.DirectPosition2D;
1516
import org.apache.sis.geometry.Envelopes;
1617
import org.apache.sis.geometry.GeneralEnvelope;
1718
import org.apache.sis.internal.referencing.AxisDirections;
1819
import org.apache.sis.parameter.DefaultParameterValueGroup;
1920
import org.apache.sis.parameter.ParameterBuilder;
20-
import org.apache.sis.referencing.CRS;
2121
import org.apache.sis.referencing.operation.matrix.Matrix2;
2222
import org.apache.sis.referencing.operation.transform.AbstractMathTransform;
2323
import org.apache.sis.referencing.operation.transform.DomainDefinition;
@@ -34,7 +34,6 @@
3434
import org.opengis.referencing.cs.CoordinateSystemAxis;
3535
import org.opengis.referencing.operation.MathTransform;
3636
import org.opengis.referencing.operation.TransformException;
37-
import org.opengis.util.FactoryException;
3837

3938
import java.text.ParseException;
4039
import java.util.Collection;
@@ -74,12 +73,11 @@ public SISProjectionWrapper(
7473
: TPP_GEO_CRS);
7574
}
7675

77-
@SneakyThrows(FactoryException.class)
7876
public SISProjectionWrapper(@NonNull CoordinateReferenceSystem projectedCRS) {
7977
this.projectedCRS = projectedCRS;
8078

81-
this.toGeo = CRS.findOperation(this.projectedCRS, this.geoCRS, null).getMathTransform();
82-
this.fromGeo = CRS.findOperation(this.geoCRS, this.projectedCRS, null).getMathTransform();
79+
this.toGeo = SISHelper.findOperation(this.projectedCRS, this.geoCRS).getMathTransform();
80+
this.fromGeo = SISHelper.findOperation(this.geoCRS, this.projectedCRS).getMathTransform();
8381
}
8482

8583
@JsonGetter("standard")

src/main/java/net/buildtheearth/terraplusplus/projection/sis/WKTStandard.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
import lombok.NonNull;
44
import lombok.SneakyThrows;
5+
import net.buildtheearth.terraplusplus.util.compat.sis.SISHelper;
56
import net.daporkchop.lib.common.reference.ReferenceStrength;
67
import net.daporkchop.lib.common.reference.cache.Cached;
8+
import org.apache.sis.internal.referencing.ReferencingFactoryContainer;
79
import org.apache.sis.io.wkt.Convention;
810
import org.apache.sis.io.wkt.KeywordCase;
911
import org.apache.sis.io.wkt.KeywordStyle;
1012
import org.apache.sis.io.wkt.Symbols;
1113
import org.apache.sis.io.wkt.WKTFormat;
14+
import org.opengis.referencing.crs.CRSFactory;
15+
import org.opengis.referencing.cs.CSFactory;
16+
import org.opengis.referencing.datum.DatumFactory;
17+
import org.opengis.referencing.operation.CoordinateOperationFactory;
18+
import org.opengis.referencing.operation.MathTransformFactory;
1219

1320
import java.text.ParseException;
1421
import java.util.Locale;
@@ -26,18 +33,33 @@ public enum WKTStandard {
2633

2734
static {
2835
{
29-
WKTFormat format = new WKTFormat(Locale.ROOT, TimeZone.getDefault());
30-
format.setKeywordCase(KeywordCase.UPPER_CASE);
31-
format.setKeywordStyle(KeywordStyle.SHORT);
32-
format.setConvention(Convention.WKT2);
33-
format.setSymbols(Symbols.SQUARE_BRACKETS);
34-
format.setIndentation(WKTFormat.SINGLE_LINE);
35-
WKT2_2015.format = Cached.threadLocal(format::clone, ReferenceStrength.SOFT);
36+
WKTFormat baseFormat = new WKTFormat(Locale.ROOT, TimeZone.getDefault());
37+
baseFormat.setKeywordCase(KeywordCase.UPPER_CASE);
38+
baseFormat.setKeywordStyle(KeywordStyle.SHORT);
39+
baseFormat.setConvention(Convention.WKT2);
40+
baseFormat.setSymbols(Symbols.SQUARE_BRACKETS);
41+
baseFormat.setIndentation(WKTFormat.SINGLE_LINE);
42+
WKT2_2015.setFormat(baseFormat);
3643
}
3744
}
3845

3946
private Cached<WKTFormat> format;
4047

48+
private void setFormat(@NonNull WKTFormat baseFormat) {
49+
this.format = Cached.threadLocal(() -> {
50+
ReferencingFactoryContainer factories = SISHelper.factories();
51+
52+
//clone the base WKTFormat instance, and configure it to use the thread-local factory instances from SISHelper.factories()
53+
WKTFormat format = baseFormat.clone();
54+
format.setFactory(CRSFactory.class, factories.getCRSFactory());
55+
format.setFactory(CSFactory.class, factories.getCSFactory());
56+
format.setFactory(DatumFactory.class, factories.getDatumFactory());
57+
format.setFactory(MathTransformFactory.class, factories.getMathTransformFactory());
58+
format.setFactory(CoordinateOperationFactory.class, factories.getCoordinateOperationFactory());
59+
return format;
60+
}, ReferenceStrength.SOFT);
61+
}
62+
4163
public Object parse(@NonNull String wkt) throws ParseException {
4264
return this.format.get().parseObject(wkt);
4365
}

src/main/java/net/buildtheearth/terraplusplus/util/compat/sis/SISHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.sis.geometry.Envelopes;
1414
import org.apache.sis.geometry.GeneralEnvelope;
1515
import org.apache.sis.internal.referencing.ReferencingFactoryContainer;
16+
import org.apache.sis.internal.system.DataDirectory;
1617
import org.apache.sis.metadata.iso.citation.Citations;
1718
import org.apache.sis.referencing.CRS;
1819
import org.apache.sis.referencing.ImmutableIdentifier;
@@ -39,6 +40,11 @@
3940
*/
4041
@UtilityClass
4142
public class SISHelper {
43+
static {
44+
//suppress 'The “SIS_DATA” environment variable is not set.' warnings in the log
45+
DataDirectory.quiet();
46+
}
47+
4248
private static final Citation TPP_CITATION = Citations.fromName("Terra++");
4349

4450
public static Citation tppCitation() {

src/test/java/projection/TestSISProjections.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ assert veryApproximateEquals(deriv1, deriv2, 0.01d, 2.2e-2d)
108108

109109
deriv1 = proj1.toGeoDerivative(x, y);
110110
deriv2 = proj2.toGeoDerivative(x, y);
111-
assert true || veryApproximateEquals(deriv1, deriv2, 0.01d, 1e-1d)
111+
assert veryApproximateEquals(deriv1, deriv2, 0.01d, 1e-1d)
112112
: "toGeoDerivative #" + i + " (" + lat + "°N, " + lon + "°E) -> (" + x + ", " + y + "):\n" + deriv1 + "!=\n" + deriv2;
113113
}
114114
}

0 commit comments

Comments
 (0)