org.opengis.referencing.crs.GeodeticCRS Java Examples
The following examples show how to use
org.opengis.referencing.crs.GeodeticCRS.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CrsFactory.java From geomajas-project-server with GNU Affero General Public License v3.0 | 7 votes |
public static Crs getCrs(String id, CoordinateReferenceSystem base) { if (base instanceof CompoundCRS) { return new CompoundCrsImpl(id, (CompoundCRS) base); } if (base instanceof GeographicCRS) { return new GeographicCrsImpl(id, (GeographicCRS) base); } if (base instanceof GeodeticCRS) { return new GeodeticCrsImpl(id, (GeodeticCRS) base); } if (base instanceof ProjectedCRS) { return new ProjectedCrsImpl(id, (ProjectedCRS) base); } if (base instanceof GeneralDerivedCRS) { return new GeneralDerivedCrsImpl(id, (GeneralDerivedCRS) base); } if (base instanceof TemporalCRS) { return new TemporalCrsImpl(id, (TemporalCRS) base); } if (base instanceof SingleCRS) { return new SingleCrsImpl(id, (SingleCRS) base); } return new CrsImpl(id, base); }
Example #2
Source File: EllipsoidalHeightCombiner.java From sis with Apache License 2.0 | 6 votes |
/** * Returns the coordinate system if the given CRS is a two-dimensional geographic or projected CRS, * or {@code null} otherwise. The returned coordinate system is either ellipsoidal or Cartesian; * no other type is returned. */ private static CoordinateSystem getCsIfHorizontal2D(final CoordinateReferenceSystem crs) { final boolean isProjected = (crs instanceof ProjectedCRS); if (isProjected || crs instanceof GeodeticCRS) { final CoordinateSystem cs = crs.getCoordinateSystem(); if (cs.getDimension() == 2 && (isProjected || cs instanceof EllipsoidalCS)) { /* * ProjectedCRS are guaranteed to be associated to CartesianCS, so we do not test that. * GeodeticCRS may be associated to either CartesianCS or EllipsoidalCS, but this method * shall accept only EllipsoidalCS. Actually we should accept only GeographicCRS, but we * relax this condition by accepting GeodeticCRS with EllipsoidalCS. */ return cs; } } return null; }
Example #3
Source File: PropertyAccessorTest.java From sis with Apache License 2.0 | 6 votes |
/** * Tests the constructor with a method which override an other method with covariant return type. * This test may need to be updated if a future GeoAPI release modifies the {@link GeographicCRS} interface. */ @Test @DependsOnMethod("testConstructorWithInheritance") public void testConstructorWithCovariantReturnType() { final Class<?> type = GeographicCRS.class; assertMappingEquals(new PropertyAccessor(type, type, type), //……Declaring type……………………………Method……………………………………………JavaBeans……………………………UML identifier………………Sentence…………………………………Type………………………………………………………… GeographicCRS.class, "getCoordinateSystem", "coordinateSystem", "coordinateSystem", "Coordinate system", EllipsoidalCS.class, // Covariant return type GeodeticCRS.class, "getDatum", "datum", "datum", "Datum", GeodeticDatum.class, // Covariant return type IdentifiedObject.class, "getName", "name", "name", "Name", ReferenceIdentifier.class, IdentifiedObject.class, "getAlias", "alias", "alias", "Alias", GenericName[].class, ReferenceSystem.class, "getDomainOfValidity", "domainOfValidity", "domainOfValidity", "Domain of validity", Extent.class, IdentifiedObject.class, "getIdentifiers", "identifiers", "identifier", "Identifiers", ReferenceIdentifier[].class, IdentifiedObject.class, "getRemarks", "remarks", "remarks", "Remarks", InternationalString.class, ReferenceSystem.class, "getScope", "scope", "SC_CRS.scope", "Scope", InternationalString.class); }
Example #4
Source File: DefaultConcatenatedOperationTest.java From sis with Apache License 2.0 | 6 votes |
/** * Tests (un)marshalling of a concatenated operation. * * @throws JAXBException if an error occurred during (un)marshalling. */ @Test public void testXML() throws JAXBException { final DefaultConcatenatedOperation op = unmarshalFile(DefaultConcatenatedOperation.class, XML_FILE); Validators.validate(op); assertEquals("operations.size()", 2, op.getOperations().size()); final CoordinateOperation step1 = op.getOperations().get(0); final CoordinateOperation step2 = op.getOperations().get(1); final CoordinateReferenceSystem sourceCRS = op.getSourceCRS(); final CoordinateReferenceSystem targetCRS = op.getTargetCRS(); assertIdentifierEquals( "identifier", "test", "test", null, "concatenated", getSingleton(op .getIdentifiers())); assertIdentifierEquals("sourceCRS.identifier", "test", "test", null, "source", getSingleton(sourceCRS.getIdentifiers())); assertIdentifierEquals("targetCRS.identifier", "test", "test", null, "target", getSingleton(targetCRS.getIdentifiers())); assertIdentifierEquals( "step1.identifier", "test", "test", null, "step-1", getSingleton(step1 .getIdentifiers())); assertIdentifierEquals( "step2.identifier", "test", "test", null, "step-2", getSingleton(step2 .getIdentifiers())); assertInstanceOf("sourceCRS", GeodeticCRS.class, sourceCRS); assertInstanceOf("targetCRS", GeodeticCRS.class, targetCRS); assertSame("sourceCRS", step1.getSourceCRS(), sourceCRS); assertSame("targetCRS", step2.getTargetCRS(), targetCRS); assertSame("tmp CRS", step1.getTargetCRS(), step2.getSourceCRS()); /* * Test marshalling and compare with the original file. */ assertMarshalEqualsFile(XML_FILE, op, "xmlns:*", "xsi:schemaLocation"); }
Example #5
Source File: MultiAuthoritiesFactoryTest.java From sis with Apache License 2.0 | 6 votes |
/** * Tests consistency of the mock factory used by other tests in this class. * * @throws FactoryException if no object was found for a code. */ @Test public void testAuthorityFactoryMock() throws FactoryException { final AuthorityFactoryMock factory = new AuthorityFactoryMock("MOCK", null); final Class<?>[] types = { GeocentricCRS.class, GeographicCRS.class, GeodeticDatum.class, VerticalDatum.class, VerticalCRS.class, GeodeticCRS.class, PrimeMeridian.class, Datum.class, CoordinateReferenceSystem.class, IdentifiedObject.class }; for (final Class<?> type : types) { for (final String code : factory.getAuthorityCodes(type.asSubclass(IdentifiedObject.class))) { assertInstanceOf(code, type, factory.createObject(code)); } } }
Example #6
Source File: DefaultDerivedCRS.java From sis with Apache License 2.0 | 6 votes |
/** * Creates a derived CRS from a math transform and a type inferred from the given arguments. * This method expects the same arguments and performs the same work than the * {@linkplain #DefaultDerivedCRS(Map, SingleCRS, CoordinateReferenceSystem, OperationMethod, MathTransform, * CoordinateSystem) above constructor}, * except that the {@code DerivedCRS} instance returned by this method may additionally implement * the {@link GeodeticCRS}, {@link VerticalCRS}, {@link TemporalCRS}, {@link ParametricCRS} or * {@link EngineeringCRS} interface. * See the class javadoc for more information. * * @param properties the properties to be given to the {@link DefaultConversion} object * (with keys prefixed by {@code "conversion."}) and to the new derived CRS object. * @param baseCRS coordinate reference system to base the derived CRS on. * @param interpolationCRS the CRS of additional coordinates needed for the operation, or {@code null} if none. * @param method the coordinate operation method (mandatory in all cases). * @param baseToDerived transform from positions in the base CRS to positions in this target CRS. * @param derivedCS the coordinate system for the derived CRS. * @return the newly created derived CRS, potentially implementing an additional CRS interface. * @throws IllegalArgumentException if at least one argument has an incompatible number of dimensions. * * @see #DefaultDerivedCRS(Map, SingleCRS, CoordinateReferenceSystem, OperationMethod, MathTransform, CoordinateSystem) */ public static DefaultDerivedCRS create(final Map<String,?> properties, final SingleCRS baseCRS, final CoordinateReferenceSystem interpolationCRS, final OperationMethod method, final MathTransform baseToDerived, final CoordinateSystem derivedCS) { if (baseCRS != null && derivedCS != null) { final String type = getType(baseCRS, derivedCS); if (type != null) switch (type) { case WKTKeywords.GeodeticCRS: return new Geodetic (properties, (GeodeticCRS) baseCRS, interpolationCRS, method, baseToDerived, derivedCS); case WKTKeywords.VerticalCRS: return new Vertical (properties, (VerticalCRS) baseCRS, interpolationCRS, method, baseToDerived, (VerticalCS) derivedCS); case WKTKeywords.TimeCRS: return new Temporal (properties, (TemporalCRS) baseCRS, interpolationCRS, method, baseToDerived, (TimeCS) derivedCS); case WKTKeywords.ParametricCRS: return new Parametric(properties, (ParametricCRS) baseCRS, interpolationCRS, method, baseToDerived, (DefaultParametricCS) derivedCS); case WKTKeywords.EngineeringCRS: { if (baseCRS instanceof EngineeringCRS) { // See the comment in create(Map, SingleCRS, Conversion, CoordinateSystem) return new Engineering(properties, (EngineeringCRS) baseCRS, interpolationCRS, method, baseToDerived, derivedCS); } break; } } } return new DefaultDerivedCRS(properties, baseCRS, interpolationCRS, method, baseToDerived, derivedCS); }
Example #7
Source File: DefaultDerivedCRS.java From sis with Apache License 2.0 | 6 votes |
/** * Returns a SIS coordinate reference system implementation with the same values than the given * arbitrary implementation. If the given object is {@code null}, then this method returns {@code null}. * Otherwise if the given object is already a SIS implementation, then the given object is returned unchanged. * Otherwise a new SIS implementation is created and initialized to the attribute values of the given object. * * @param object the object to get as a SIS implementation, or {@code null} if none. * @return a SIS implementation containing the values of the given object (may be the * given object itself), or {@code null} if the argument was null. */ public static DefaultDerivedCRS castOrCopy(final DerivedCRS object) { if (object == null || object instanceof DefaultDerivedCRS) { return (DefaultDerivedCRS) object; } else { final String type = getType((SingleCRS) object.getBaseCRS(), object.getCoordinateSystem()); if (type != null) switch (type) { case WKTKeywords.GeodeticCRS: return new Geodetic (object); case WKTKeywords.VerticalCRS: return new Vertical (object); case WKTKeywords.TimeCRS: return new Temporal (object); case WKTKeywords.ParametricCRS: return new Parametric (object); case WKTKeywords.EngineeringCRS: return new Engineering(object); } return new DefaultDerivedCRS(object); } }
Example #8
Source File: DefaultCompoundCRS.java From sis with Apache License 2.0 | 5 votes |
/** * Verifies that the given array does not contain duplicated horizontal or vertical components. * Verifies also that if there is an horizontal component, then there is no ellipsoidal height * defined separately. * * @param properties the user-specified properties, for determining the locale of error messages. * @param components the components to verify. */ private static void verify(final Map<String,?> properties, final CoordinateReferenceSystem[] components) { int allTypes = 0; int isProjected = 0; // 0 for false, 1 for true. boolean isEllipsoidalHeight = false; for (final CoordinateReferenceSystem component : components) { final int type; if (component instanceof GeodeticCRS) { type = 1; // Must match the number used in Resources.Keys.DuplicatedSpatialComponents_1. } else if (component instanceof ProjectedCRS) { isProjected = 1; type = 1; // Intentionally same number than for GeographicCRS case. } else if (component instanceof VerticalCRS) { isEllipsoidalHeight = ReferencingUtilities.isEllipsoidalHeight(((VerticalCRS) component).getDatum()); type = 2; // Must match the number used in Resources.Keys.DuplicatedSpatialComponents_1. } else { continue; // Skip other types. In particular, we allow 2 temporal CRS (used in meteorology). } if (allTypes == (allTypes |= type)) { throw new IllegalArgumentException(Resources.forProperties(properties) .getString(Resources.Keys.DuplicatedSpatialComponents_1, type)); } } if (isEllipsoidalHeight && ((allTypes & 1) != 0)) { throw new IllegalArgumentException(Resources.forProperties(properties) .getString(Resources.Keys.EllipsoidalHeightNotAllowed_1, isProjected)); } }
Example #9
Source File: DefaultDerivedCRS.java From sis with Apache License 2.0 | 5 votes |
/** * Returns the WKT 2 keyword for a {@code DerivedCRS} having the given base CRS and derived coordinate system. * Note that an ambiguity exists if the given base CRS is a {@code GeodeticCRS}, as the result could be either * {@code "GeodeticCRS"} or {@code "EngineeringCRS"}. The current implementation returns the former if the * derived coordinate system is of the same kind than the base coordinate system. */ static String getType(final SingleCRS baseCRS, final CoordinateSystem derivedCS) { final Class<?> type; if (baseCRS instanceof AbstractIdentifiedObject) { /* * For avoiding ambiguity if a user chooses to implement more * than 1 CRS interface (not recommended, but may happen). */ type = ((AbstractIdentifiedObject) baseCRS).getInterface(); } else if (baseCRS != null) { type = baseCRS.getClass(); } else { return null; } if (GeodeticCRS.class.isAssignableFrom(type)) { if (Classes.implementSameInterfaces(derivedCS.getClass(), baseCRS.getCoordinateSystem().getClass(), CoordinateSystem.class)) { return WKTKeywords.GeodeticCRS; } else { return WKTKeywords.EngineeringCRS; } } else if (VerticalCRS.class.isAssignableFrom(type) && derivedCS instanceof VerticalCS) { return WKTKeywords.VerticalCRS; } else if (TemporalCRS.class.isAssignableFrom(type) && derivedCS instanceof TimeCS) { return WKTKeywords.TimeCRS; } else if (ParametricCRS.class.isAssignableFrom(type) && derivedCS instanceof DefaultParametricCS) { return WKTKeywords.ParametricCRS; } else if (ProjectedCRS.class.isAssignableFrom(type) || EngineeringCRS.class.isAssignableFrom(type)) { return WKTKeywords.EngineeringCRS; } else { return null; } }
Example #10
Source File: DefaultDerivedCRS.java From sis with Apache License 2.0 | 5 votes |
/** * Return the WKT 2 keyword for this {@code DerivedCRS}, or {@code null} if unknown. * Inner subclasses will override this method for returning a constant value instead * than trying to infer it from the components. */ String keyword(final Formatter formatter) { final String longKeyword = getType(getBaseCRS(), getCoordinateSystem()); final String shortKeyword; if (longKeyword == null) { return null; } switch (longKeyword) { case WKTKeywords.GeodeticCRS: shortKeyword = WKTKeywords.GeodCRS; break; case WKTKeywords.VerticalCRS: shortKeyword = WKTKeywords.VertCRS; break; case WKTKeywords.EngineeringCRS: shortKeyword = WKTKeywords.EngCRS; break; default: return longKeyword; } return formatter.shortOrLong(shortKeyword, longKeyword); }
Example #11
Source File: DefaultDerivedCRS.java From sis with Apache License 2.0 | 5 votes |
/** * Creates a derived CRS from a defining conversion and a type inferred from the given arguments. * This method expects the same arguments and performs the same work than the * {@linkplain #DefaultDerivedCRS(Map, SingleCRS, Conversion, CoordinateSystem) above constructor}, * except that the {@code DerivedCRS} instance returned by this method may additionally implement * the {@link GeodeticCRS}, {@link VerticalCRS}, {@link TemporalCRS}, {@link ParametricCRS} or * {@link EngineeringCRS} interface. * See the class javadoc for more information. * * @param properties the properties to be given to the new derived CRS object. * @param baseCRS coordinate reference system to base the derived CRS on. * @param conversion the defining conversion from a normalized base to a normalized derived CRS. * @param derivedCS the coordinate system for the derived CRS. The number of axes * must match the target dimension of the {@code baseToDerived} transform. * @return the newly created derived CRS, potentially implementing an additional CRS interface. * @throws MismatchedDimensionException if the source and target dimensions of {@code baseToDerived} * do not match the dimensions of {@code base} and {@code derivedCS} respectively. * * @see #DefaultDerivedCRS(Map, SingleCRS, Conversion, CoordinateSystem) * @see org.apache.sis.referencing.factory.GeodeticObjectFactory#createDerivedCRS(Map, CoordinateReferenceSystem, Conversion, CoordinateSystem) */ public static DefaultDerivedCRS create(final Map<String,?> properties, final SingleCRS baseCRS, final Conversion conversion, final CoordinateSystem derivedCS) throws MismatchedDimensionException { if (baseCRS != null && derivedCS != null) { final String type = getType(baseCRS, derivedCS); if (type != null) switch (type) { case WKTKeywords.GeodeticCRS: return new Geodetic (properties, (GeodeticCRS) baseCRS, conversion, derivedCS); case WKTKeywords.VerticalCRS: return new Vertical (properties, (VerticalCRS) baseCRS, conversion, (VerticalCS) derivedCS); case WKTKeywords.TimeCRS: return new Temporal (properties, (TemporalCRS) baseCRS, conversion, (TimeCS) derivedCS); case WKTKeywords.ParametricCRS: return new Parametric(properties, (ParametricCRS) baseCRS, conversion, (DefaultParametricCS) derivedCS); case WKTKeywords.EngineeringCRS: { /* * This case may happen for baseCRS of kind GeodeticCRS, ProjectedCRS or EngineeringCRS. * But only the later is associated to EngineeringDatum; the two formers are associated * to GeodeticDatum. Consequently we can implement the EngineeringCRS.getDatum() method * only if the base CRS is itself of kind EngineeringCRS. Otherwise we will return the * "type-neutral" DefaultDerivedCRS implementation. Note that even in the later case, * the WKT format will still be able to detect that the WKT keyword is "EngineeringCRS". */ if (baseCRS instanceof EngineeringCRS) { return new Engineering(properties, (EngineeringCRS) baseCRS, conversion, derivedCS); } break; } } } return new DefaultDerivedCRS(properties, baseCRS, conversion, derivedCS); }
Example #12
Source File: DefaultGeographicCRS.java From sis with Apache License 2.0 | 5 votes |
/** * For {@link SC_GeographicCRS} JAXB adapter only. This is needed because GML does not have "GeographicCRS" type. * Instead, the unmarshalling process will give us a "GeodeticCRS" object with the constraint that the coordinate * system shall be ellipsoidal. This constructor will be invoked for converting the GeodeticCRS instance to a * GeographicCRS instance. */ DefaultGeographicCRS(final GeodeticCRS crs) { super(crs); final CoordinateSystem cs = super.getCoordinateSystem(); if (!(cs instanceof EllipsoidalCS)) { throw new IllegalArgumentException(Errors.format( Errors.Keys.IllegalClass_2, EllipsoidalCS.class, cs.getClass())); } }
Example #13
Source File: DefaultGeodeticDatum.java From sis with Apache License 2.0 | 5 votes |
/** * Formats this datum as a <cite>Well Known Text</cite> {@code Datum[…]} element. * * <div class="note"><b>Example:</b> Well-Known Text of a WGS 84 datum. * * {@preformat wkt * Datum["World Geodetic System 1984", * Ellipsoid["WGS84", 6378137.0, 298.257223563, LengthUnit["metre", 1]], * Id["EPSG", 6326, Citation["IOGP"], URI["urn:ogc:def:datum:EPSG::6326"]]] * } * * <p>Same datum using WKT 1.</p> * * {@preformat wkt * DATUM["World Geodetic System 1984" * SPHEROID["WGS84", 6378137.0, 298.257223563], * AUTHORITY["EPSG", "6326"]] * } * </div> * * Note that the {@linkplain #getPrimeMeridian() prime meridian} shall be formatted by the caller * as a separated element after the geodetic datum (for compatibility with WKT 1). * * @return {@code "Datum"} or {@code "GeodeticDatum"}. * * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#51">WKT 2 specification §8.2</a> */ @Override protected String formatTo(final Formatter formatter) { super.formatTo(formatter); formatter.newLine(); formatter.append(toFormattable(getEllipsoid())); final boolean isWKT1 = formatter.getConvention().majorVersion() == 1; if (isWKT1) { /* * Note that at the different of other datum (in particular vertical datum), * WKT of geodetic datum do not have a numerical code for the datum type. */ if (bursaWolf != null) { for (final BursaWolfParameters candidate : bursaWolf) { if (candidate.isToWGS84()) { formatter.newLine(); formatter.append(candidate); break; } } } } /* * For the WKT 2 case, the ANCHOR[…] element is added by Formatter itself. */ formatter.newLine(); // For writing the ID[…] element on its own line. if (!isWKT1) { /* * In WKT 2, both "Datum" and "GeodeticDatum" keywords are permitted. The standard recommends * to use "Datum" for simplicity. We will follow this advice when the Datum element is inside * a GeodeticCRS element since the "Geodetic" aspect is more obvious in such case. But if the * Datum appears in another context, then we will use "GeodeticDatum" for clarity. */ if (!(formatter.getEnclosingElement(1) instanceof GeodeticCRS)) { return formatter.shortOrLong(WKTKeywords.Datum, WKTKeywords.GeodeticDatum); } } return WKTKeywords.Datum; }
Example #14
Source File: CRS.java From sis with Apache License 2.0 | 5 votes |
/** * If the given CRS would qualify as horizontal except for its number of dimensions, returns that number. * Otherwise returns 0. The number of dimensions can only be 2 or 3. */ private static int horizontalCode(final CoordinateReferenceSystem crs) { /* * In order to determine if the CRS is geographic, checking the CoordinateSystem type is more reliable * then checking if the CRS implements the GeographicCRS interface. This is because the GeographicCRS * type did not existed in ISO 19111:2007, so a CRS could be standard-compliant without implementing * the GeographicCRS interface. */ boolean isEngineering = false; final boolean isGeodetic = (crs instanceof GeodeticCRS); if (isGeodetic || crs instanceof ProjectedCRS || (isEngineering = (crs instanceof EngineeringCRS))) { final CoordinateSystem cs = crs.getCoordinateSystem(); final int dim = cs.getDimension(); if ((dim & ~1) == 2 && (!isGeodetic || (cs instanceof EllipsoidalCS))) { if (isEngineering) { int n = 0; for (int i=0; i<dim; i++) { if (AxisDirections.isCompass(cs.getAxis(i).getDirection())) n++; } // If we don't have exactly 2 east, north, etc. directions, consider as non-horizontal. if (n != 2) return 0; } return dim; } } return 0; }
Example #15
Source File: DefaultConversionTest.java From sis with Apache License 2.0 | 4 votes |
/** * Changes only the coordinate system of the given CRS, which is supposed geographic. */ private static GeographicCRS changeCS(final CoordinateReferenceSystem crs, final EllipsoidalCS cs) { return new DefaultGeographicCRS(Collections.singletonMap(DefaultGeographicCRS.NAME_KEY, crs.getName()), ((GeodeticCRS) crs).getDatum(), cs); }
Example #16
Source File: SingleOperationMarshallingTest.java From sis with Apache License 2.0 | 4 votes |
/** * Tests unmarshalling of a transformation. * * @throws JAXBException if an error occurred during marshalling or unmarshalling. */ @Test @DependsOnMethod("testConversionUnmarshalling") public void testTransformationUnmarshalling() throws JAXBException { final DefaultTransformation c = unmarshalFile(DefaultTransformation.class, "Transformation.xml"); assertEquals("name", "NTF (Paris) to NTF (1)", c.getName().getCode()); assertEquals("identifier", "1763", getSingleton(c.getIdentifiers()).getCode()); assertEquals("scope", "Change of prime meridian.", String.valueOf(c.getScope())); assertEquals("operationVersion", "IGN-Fra", c.getOperationVersion()); final OperationMethod method = c.getMethod(); assertNotNull("method", method); assertEquals ("method.name", "Longitude rotation", method.getName().getCode()); assertEquals ("method.identifier", "9601", getSingleton(method.getIdentifiers()).getCode()); assertEquals ("method.formula", "Target_longitude = Source_longitude + longitude_offset.", method.getFormula().getFormula().toString()); final ParameterDescriptor<?> descriptor = (ParameterDescriptor<?>) getSingleton(method.getParameters().descriptors()); assertEquals("descriptor.name", "Longitude offset", descriptor.getName().getCode()); assertEquals("descriptor.identifier", "8602", getSingleton(descriptor.getIdentifiers()).getCode()); assertEquals("descriptor.valueClass", Double.class, descriptor.getValueClass()); final ParameterValueGroup parameters = c.getParameterValues(); assertNotNull("parameters", parameters); assertSame("parameters.descriptors", method.getParameters(), parameters.getDescriptor()); final ParameterValue<?> parameter = (ParameterValue<?>) getSingleton(parameters.values()); assertSame ("parameters.descriptor", descriptor, parameter.getDescriptor()); assertEquals("parameters.unit", Units.GRAD, parameter.getUnit()); assertEquals("parameters.value", 2.5969213, parameter.getValue()); final CoordinateReferenceSystem sourceCRS = c.getSourceCRS(); assertInstanceOf("sourceCRS", GeodeticCRS.class, sourceCRS); assertEquals ("sourceCRS.name", "NTF (Paris)", sourceCRS.getName().getCode()); assertEquals ("sourceCRS.scope", "Geodetic survey.", sourceCRS.getScope().toString()); assertEquals ("sourceCRS.identifier", "4807", getSingleton(sourceCRS.getIdentifiers()).getCode()); final CoordinateReferenceSystem targetCRS = c.getTargetCRS(); assertInstanceOf("targetCRS", GeodeticCRS.class, targetCRS); assertEquals ("targetCRS.name", "NTF", targetCRS.getName().getCode()); assertEquals ("targetCRS.scope", "Geodetic survey.", targetCRS.getScope().toString()); assertEquals ("targetCRS.identifier", "4275", getSingleton(targetCRS.getIdentifiers()).getCode()); final MathTransform tr = c.getMathTransform(); assertInstanceOf("mathTransform", LinearTransform.class, tr); assertMatrixEquals("mathTransform.matrix", new Matrix3(1, 0, 0, 0, 1, 2.33722917, 0, 0, 1), ((LinearTransform) tr).getMatrix(), STRICT); Validators.validate(c); }
Example #17
Source File: GeodeticCrsImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
public GeodeticCrsImpl(String id, GeodeticCRS base) { this.id = id; this.base = base; }
Example #18
Source File: DefaultCompoundCRS.java From sis with Apache License 2.0 | 4 votes |
/** * Returns {@code true} if the sequence of single components is conform to the ISO 19162 restrictions. * The <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#111">WKT 2 specification at §16.1</a> * restricts {@code CompoundCRS} to the following components in that order: * * <ul> * <li>A mandatory horizontal CRS (only one of two-dimensional {@code GeographicCRS} * or {@code ProjectedCRS} or {@code EngineeringCRS}).</li> * <li>Optionally followed by a {@code VerticalCRS} or a {@code ParametricCRS} (but not both).</li> * <li>Optionally followed by a {@code TemporalCRS}.</li> * </ul> * * This method verifies the above criterion with the following flexibilities: * * <ul> * <li>Accepts three-dimensional {@code GeodeticCRS} followed by a {@code TemporalCRS}.</li> * </ul> * * This method does not verify recursively if the component are themselves standard compliant. * In particular, this method does not verify if the geographic CRS uses (latitude, longitude) * axes order as requested by ISO 19162. * * <p>This method is not yet public because of the above-cited limitations: a {@code true} return * value is not a guarantee that the CRS is really standard-compliant.</p> * * @return {@code true} if this CRS is "standard" compliant, except for the above-cited limitations. */ @SuppressWarnings("fallthrough") static boolean isStandardCompliant(final List<? extends CoordinateReferenceSystem> singles) { if (Containers.isNullOrEmpty(singles)) { return false; } /* * 0 if we expect a horizontal CRS: Geographic2D, projected or engineering. * 1 if we expect a vertical or parametric CRS (but not both). * 2 if we expect a temporal CRS. * 3 if we do not expect any other CRS. */ int state = 0; for (final CoordinateReferenceSystem crs : singles) { switch (state) { case 0: { if (crs instanceof GeodeticCRS || crs instanceof ProjectedCRS || crs instanceof EngineeringCRS) { switch (crs.getCoordinateSystem().getDimension()) { case 2: state = 1; continue; // Next CRS can be vertical, parametric or temporal. case 3: state = 2; continue; // Next CRS can only be temporal. } } return false; } case 1: { if (crs instanceof VerticalCRS || crs instanceof ParametricCRS) { state = 2; continue; // Next CRS can only be temporal. } // Fallthrough (the current CRS may be temporal) } case 2: { if (crs instanceof TemporalCRS) { state = 3; continue; // Do not expect any other CRS. } // Fallthrough (unexpected CRS). } default: { return false; } } } return true; }
Example #19
Source File: DefaultDerivedCRS.java From sis with Apache License 2.0 | 4 votes |
/** Returns the WKT keyword for this derived CRS type. */ @Override String keyword(final Formatter formatter) { return formatter.shortOrLong(WKTKeywords.GeodCRS, WKTKeywords.GeodeticCRS); }
Example #20
Source File: DefaultDerivedCRS.java From sis with Apache License 2.0 | 4 votes |
/** Returns a coordinate reference system of the same type than this CRS but with different axes. */ @Override AbstractCRS createSameType(final Map<String,?> properties, final CoordinateSystem derivedCS) { final Conversion conversionFromBase = getConversionFromBase(); return new Geodetic(properties, (GeodeticCRS) conversionFromBase.getSourceCRS(), conversionFromBase, derivedCS); }
Example #21
Source File: DefaultDerivedCRS.java From sis with Apache License 2.0 | 4 votes |
/** Creates a new geodetic CRS from the given properties. */ Geodetic(Map<String,?> properties, GeodeticCRS baseCRS, CoordinateReferenceSystem interpolationCRS, OperationMethod method, MathTransform baseToDerived, CoordinateSystem derivedCS) { super(properties, baseCRS, interpolationCRS, method, baseToDerived, derivedCS); }
Example #22
Source File: DefaultDerivedCRS.java From sis with Apache License 2.0 | 4 votes |
/** Creates a new geodetic CRS from the given properties. */ Geodetic(Map<String,?> properties, GeodeticCRS baseCRS, Conversion conversion, CoordinateSystem derivedCS) { super(properties, baseCRS, conversion, derivedCS); }
Example #23
Source File: SubTypes.java From sis with Apache License 2.0 | 4 votes |
/** * Returns a SIS implementation for the given coordinate reference system. * * @see AbstractCRS#castOrCopy(CoordinateReferenceSystem) */ static AbstractCRS castOrCopy(final CoordinateReferenceSystem object) { if (object instanceof DerivedCRS) { return DefaultDerivedCRS.castOrCopy((DerivedCRS) object); } if (object instanceof ProjectedCRS) { return DefaultProjectedCRS.castOrCopy((ProjectedCRS) object); } if (object instanceof GeodeticCRS) { if (object instanceof GeographicCRS) { return DefaultGeographicCRS.castOrCopy((GeographicCRS) object); } if (object instanceof GeocentricCRS) { return DefaultGeocentricCRS.castOrCopy((GeocentricCRS) object); } /* * The GeographicCRS and GeocentricCRS types are not part of ISO 19111. * ISO uses a single type, GeodeticCRS, for both of them and infer the * geographic or geocentric type from the coordinate system. We do this * check here for instantiating the most appropriate SIS type, but only * if we need to create a new object anyway (see below for rational). */ if (object instanceof DefaultGeodeticCRS) { /* * Result of XML unmarshalling — keep as-is. We avoid creating a new object because it * would break object identities specified in GML document by the xlink:href attribute. * However we may revisit this policy in the future. See SC_CRS.setElement(AbstractCRS). */ return (DefaultGeodeticCRS) object; } final Map<String,?> properties = IdentifiedObjects.getProperties(object); final GeodeticDatum datum = ((GeodeticCRS) object).getDatum(); final CoordinateSystem cs = object.getCoordinateSystem(); if (cs instanceof EllipsoidalCS) { return new DefaultGeographicCRS(properties, datum, (EllipsoidalCS) cs); } if (cs instanceof SphericalCS) { return new DefaultGeocentricCRS(properties, datum, (SphericalCS) cs); } if (cs instanceof CartesianCS) { return new DefaultGeocentricCRS(properties, datum, (CartesianCS) cs); } } if (object instanceof VerticalCRS) { return DefaultVerticalCRS.castOrCopy((VerticalCRS) object); } if (object instanceof TemporalCRS) { return DefaultTemporalCRS.castOrCopy((TemporalCRS) object); } if (object instanceof EngineeringCRS) { return DefaultEngineeringCRS.castOrCopy((EngineeringCRS) object); } if (object instanceof ImageCRS) { return DefaultImageCRS.castOrCopy((ImageCRS) object); } if (object instanceof CompoundCRS) { return DefaultCompoundCRS.castOrCopy((CompoundCRS) object); } /* * Intentionally check for AbstractCRS after the interfaces because user may have defined his own * subclass implementing the interface. If we were checking for AbstractCRS before the interfaces, * the returned instance could have been a user subclass without the JAXB annotations required * for XML marshalling. */ if (object == null || object instanceof AbstractCRS) { return (AbstractCRS) object; } return new AbstractCRS(object); }
Example #24
Source File: CRS.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the first horizontal coordinate reference system found in the given CRS, or {@code null} if there is * none. If the given CRS is already horizontal according {@link #isHorizontalCRS(CoordinateReferenceSystem)}, * then this method returns it as-is. Otherwise if the given CRS is compound, then this method searches for the * first horizontal component in the order of the {@linkplain #getSingleComponents(CoordinateReferenceSystem) * single components list}. * * <p>In the special case where a three-dimensional geographic or projected CRS is found, this method * will create a two-dimensional geographic or projected CRS without the vertical axis.</p> * * @param crs the coordinate reference system, or {@code null}. * @return the first horizontal CRS, or {@code null} if none. * * @category information */ public static SingleCRS getHorizontalComponent(final CoordinateReferenceSystem crs) { switch (horizontalCode(crs)) { /* * If the CRS is already two-dimensional and horizontal, return as-is. * We don't need to check if crs is an instance of SingleCRS since all * CRS accepted by horizontalCode(…) are SingleCRS. */ case 2: { return (SingleCRS) crs; } case 3: { /* * The CRS would be horizontal if we can remove the vertical axis. CoordinateSystems.replaceAxes(…) * will do this task for us. We can verify if the operation has been successful by checking that * the number of dimensions has been reduced by 1 (from 3 to 2). */ final CoordinateSystem cs = CoordinateSystems.replaceAxes(crs.getCoordinateSystem(), new AxisFilter() { @Override public boolean accept(final CoordinateSystemAxis axis) { return !AxisDirections.isVertical(axis.getDirection()); } }); if (cs.getDimension() != 2) break; /* * Most of the time, the CRS to rebuild will be geodetic. In such case we known that the * coordinate system is ellipsoidal because (i.e. the CRS is geographic) because it was * a condition verified by horizontalCode(…). A ClassCastException would be a bug. */ final Map<String, ?> properties = ReferencingUtilities.getPropertiesForModifiedCRS(crs); if (crs instanceof GeodeticCRS) { return new DefaultGeographicCRS(properties, ((GeodeticCRS) crs).getDatum(), (EllipsoidalCS) cs); } /* * In Apache SIS implementation, the Conversion contains the source and target CRS together with * a MathTransform. We need to recreate the same conversion, but without CRS and MathTransform * for letting SIS create or associate new ones, which will be two-dimensional now. */ if (crs instanceof ProjectedCRS) { final ProjectedCRS proj = (ProjectedCRS) crs; final GeographicCRS base = (GeographicCRS) getHorizontalComponent(proj.getBaseCRS()); Conversion fromBase = proj.getConversionFromBase(); fromBase = new DefaultConversion(IdentifiedObjects.getProperties(fromBase), fromBase.getMethod(), null, fromBase.getParameterValues()); return new DefaultProjectedCRS(properties, base, fromBase, (CartesianCS) cs); } /* * If the CRS is neither geographic or projected, then it is engineering. */ return new DefaultEngineeringCRS(properties, ((EngineeringCRS) crs).getDatum(), cs); } } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getComponents()) { final SingleCRS candidate = getHorizontalComponent(c); if (candidate != null) { return candidate; } } } return null; }
Example #25
Source File: GeodeticObjectVerifier.java From sis with Apache License 2.0 | 3 votes |
/** * Asserts that the given CRS is the WGS 84 one. * This method verifies the following properties: * * <table class="sis"> * <caption>Verified properties</caption> * <tr><th>Property</th> <th>Expected value</th></tr> * <tr><td>{@linkplain Identifier#getCode() Code} of the {@linkplain GeodeticCRS#getName() name}</td> * <td>{@code "WGS 84"}</td></tr> * <tr><td>{@linkplain GeodeticCRS#getDomainOfValidity() Domain of validity}</td> * <td>{@linkplain #assertIsWorld(GeographicBoundingBox) Is world} or absent</td></tr> * <tr><td>{@linkplain GeodeticCRS#getDatum() Datum}</td> * <td>{@linkplain #assertIsWGS84(GeodeticDatum, boolean) Is WGS84}</td></tr> * <tr><td>{@linkplain GeodeticCRS#getCoordinateSystem() Coordinate system}</td> * <td>{@linkplain #assertIsGeodetic2D(EllipsoidalCS, boolean) Is for a 2D geodetic CRS}</td></tr> * </table> * * @param crs the coordinate reference system to verify. * @param isExtentMandatory {@code true} if the CRS and datum domains of validity are required to contain an * {@code Extent} element for the world, or {@code false} if optional. * @param isRangeMandatory {@code true} if the coordinate system axes range and range meaning properties * shall be defined, or {@code false} if they are optional. */ public static void assertIsWGS84(final GeodeticCRS crs, final boolean isExtentMandatory, final boolean isRangeMandatory) { assertEquals("name", "WGS 84", crs.getName().getCode()); assertIsWorld(crs.getDomainOfValidity(), isExtentMandatory); assertIsWGS84(crs.getDatum(), isExtentMandatory); final CoordinateSystem cs = crs.getCoordinateSystem(); assertInstanceOf("coordinateSystem", EllipsoidalCS.class, cs); assertIsGeodetic2D((EllipsoidalCS) cs, isRangeMandatory); }
Example #26
Source File: DefaultGeodeticCRS.java From sis with Apache License 2.0 | 2 votes |
/** * Constructs a new coordinate reference system with the same values than the specified one. * This copy constructor provides a way to convert an arbitrary implementation into a SIS one * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific API. * * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p> * * @param crs the coordinate reference system to copy. */ protected DefaultGeodeticCRS(final GeodeticCRS crs) { super(crs); datum = crs.getDatum(); }
Example #27
Source File: DefaultGeodeticCRS.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the GeoAPI interface implemented by this class. * The SIS implementation returns {@code GeodeticCRS.class}. * Subclasses implementing a more specific GeoAPI interface shall override this method. * * @return the coordinate reference system interface implemented by this class. */ @Override public Class<? extends GeodeticCRS> getInterface() { return GeodeticCRS.class; }
Example #28
Source File: CRS.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the Greenwich longitude of the prime meridian of the given CRS in degrees. * If the prime meridian uses an other unit than degrees, then the value will be converted. * * @param crs the coordinate reference system from which to get the prime meridian. * @return the Greenwich longitude (in degrees) of the prime meridian of the given CRS. * * @see org.apache.sis.referencing.datum.DefaultPrimeMeridian#getGreenwichLongitude(Unit) * * @since 0.5 */ public static double getGreenwichLongitude(final GeodeticCRS crs) { ArgumentChecks.ensureNonNull("crs", crs); return ReferencingUtilities.getGreenwichLongitude(crs.getDatum().getPrimeMeridian(), Units.DEGREE); }