28
28
29
29
/**
30
30
* Wraps a PROJ4J implementation behind the equivalent GeoAPI interface.
31
- * The CRS is assumed two-dimensional.
32
31
*
33
32
* @author Martin Desruisseaux (Geomatys)
34
33
*/
35
34
@ SuppressWarnings ("serial" )
36
35
abstract class AbstractCRS extends Wrapper implements SingleCRS , CoordinateSystem , Serializable {
37
36
/**
38
- * The number of dimensions of the CRS .
37
+ * The wrapped PROJ4 implementation .
39
38
*/
40
- private static final int BIDIMENSIONAL = 2 ;
39
+ final org . locationtech . proj4j . CoordinateReferenceSystem impl ;
41
40
42
41
/**
43
- * The wrapped PROJ4 implementation .
42
+ * Whether this CRS is three-dimensional instead of two-dimensional .
44
43
*/
45
- private final org . locationtech . proj4j . CoordinateReferenceSystem impl ;
44
+ final boolean is3D ;
46
45
47
46
/**
48
47
* The coordinate system axes, computed and cached when first requested.
@@ -55,23 +54,29 @@ abstract class AbstractCRS extends Wrapper implements SingleCRS, CoordinateSyste
55
54
/**
56
55
* Creates a new wrapper for the given PROJ4J implementation.
57
56
*/
58
- AbstractCRS (final org .locationtech .proj4j .CoordinateReferenceSystem impl ) {
57
+ AbstractCRS (final org .locationtech .proj4j .CoordinateReferenceSystem impl , final boolean is3D ) {
59
58
this .impl = impl ;
59
+ this .is3D = is3D ;
60
60
}
61
61
62
62
/**
63
63
* Wraps the given implementation.
64
64
*
65
65
* @param impl the implementation to wrap, or {@code null}
66
+ * @param is3D whether to return a three-dimensional CRS instead of a two-dimensional one
66
67
* @return the wrapper, or {@code null} if the given implementation was null
67
68
*/
68
- static AbstractCRS wrap (final org .locationtech .proj4j .CoordinateReferenceSystem impl ) {
69
+ static AbstractCRS wrap (final org .locationtech .proj4j .CoordinateReferenceSystem impl , final boolean is3D ) {
69
70
if (impl != null ) {
70
71
final Projection proj = impl .getProjection ();
71
72
if (proj == null || proj .isGeographic ()) {
72
- return new GeographicCRSWrapper (impl );
73
+ return new GeographicCRSWrapper (impl , is3D );
73
74
} else {
74
- // TODO
75
+ /*
76
+ * TODO: there is a possibility that the PROJ4J `projection` is actually for something
77
+ * else than a map projection. But there is apparently no easy way to determine that.
78
+ */
79
+ return new ProjectedCRSWrapper (impl , is3D );
75
80
}
76
81
}
77
82
return null ;
@@ -111,11 +116,11 @@ public CoordinateSystem getCoordinateSystem() {
111
116
}
112
117
113
118
/**
114
- * {@return the number of dimensions, which is fixed to 2 }.
119
+ * {@return the number of dimensions, which is 2 or 3 }.
115
120
*/
116
121
@ Override
117
122
public final int getDimension () {
118
- return BIDIMENSIONAL ;
123
+ return is3D ? TRIDIMENSIONAL : BIDIMENSIONAL ;
119
124
}
120
125
121
126
/**
@@ -147,7 +152,7 @@ public final CoordinateSystemAxis getAxis(int dimension) {
147
152
Axis [] axes = this .axes ;
148
153
if (axes == null ) {
149
154
final Axis [] axesForAllDirections = axesForAllDirections ();
150
- axes = Arrays .copyOfRange (axesForAllDirections , Axis .INDEX_OF_EAST , axesForAllDirections . length );
155
+ axes = Arrays .copyOfRange (axesForAllDirections , Axis .INDEX_OF_EAST , Axis . INDEX_OF_EAST + getDimension () );
151
156
final Projection proj = impl .getProjection ();
152
157
if (proj != null ) {
153
158
final AxisOrder order = proj .getAxisOrder ();
0 commit comments