/** * Returns the first vertical coordinate reference system found in a the given CRS, or {@code * null} if there is none. * * @param crs The coordinate reference system, or {@code null}. * @return The vertical CRS, or {@code null} if none. * @since 2.4 */ public static VerticalCRS getVerticalCRS(final CoordinateReferenceSystem crs) { if (crs instanceof VerticalCRS) { return (VerticalCRS) crs; } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getCoordinateReferenceSystems()) { final VerticalCRS candidate = getVerticalCRS(c); if (candidate != null) { return candidate; } } } return null; }
/** * A simple test * @throws Exception if the test fails */ @Test public void compoundCrs() throws Exception { CoordinateReferenceSystem c = CompoundCRSDecoder.decode("urn:ogc:def:crs,crs:EPSG:6.12:3068,crs:EPSG:6.12:5783"); assertEquals(CRS.decode("EPSG:3068"), CRS.getHorizontalCRS(c)); assertEquals(CRS.decode("EPSG:5783"), CRS.getVerticalCRS(c)); } }