org.opengis.referencing.crs.GeographicCRS Java Examples

The following examples show how to use org.opengis.referencing.crs.GeographicCRS. 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 vote down vote up
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: CommonCRSTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the {@link CommonCRS#normalizedGeographic()} method.
 */
@Test
@DependsOnMethod("testGeographic")
public void testNormalizedGeographic() {
    final GeographicCRS geographic = CommonCRS.WGS84.geographic();
    final GeographicCRS normalized = CommonCRS.WGS84.normalizedGeographic();
    Validators.validate(normalized);
    assertSame(geographic.getDatum(), normalized.getDatum());
    /*
     * Compare axes. Note that axes in different order have different EPSG codes.
     */
    final CoordinateSystem φλ = geographic.getCoordinateSystem();
    final CoordinateSystem λφ = normalized.getCoordinateSystem();
    assertEqualsIgnoreMetadata(φλ.getAxis(1), λφ.getAxis(0));       // Longitude
    assertEqualsIgnoreMetadata(φλ.getAxis(0), λφ.getAxis(1));       // Latitude
    assertSame("Cached value", normalized, CommonCRS.WGS84.normalizedGeographic());
}
 
Example #3
Source File: CoordinateOperationsTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link CoordinateOperations#wrapAroundChanges(CoordinateReferenceSystem, CoordinateSystem)}.
 */
@Test
@DependsOnMethod("testIsWrapAround")
public void testWrapAroundChanges() {
    CoordinateReferenceSystem sourceCRS = HardCodedCRS.WGS84_3D;
    CoordinateSystem          targetCS = HardCodedCS.GEODETIC_2D;
    assertTrue("(λ,φ,h) → (λ,φ)", CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).isEmpty());

    sourceCRS = HardCodedCRS.WGS84_3D.forConvention(AxesConvention.POSITIVE_RANGE);
    assertArrayEquals("(λ′,φ,h) → (λ,φ)", new Integer[] {0},
            CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray());

    targetCS = HardCodedCS.GEODETIC_φλ;
    assertArrayEquals("(λ′,φ,h) → (φ,λ)", new Integer[] {1},
            CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray());

    sourceCRS = HardCodedConversions.mercator((GeographicCRS) sourceCRS);
    assertArrayEquals("(λ′,φ,h) → (φ,λ)", new Integer[] {1},
            CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray());

}
 
Example #4
Source File: PropertyAccessorTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: StandardDefinitions.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Universal Transverse Mercator (UTM) or a Universal Polar Stereographic (UPS) projected CRS
 * using the Apache SIS factory implementation. This method restricts the factory to SIS implementation
 * instead than arbitrary factory in order to met the contract saying that {@link CommonCRS} methods
 * should never fail.
 *
 * @param code       the EPSG code, or 0 if none.
 * @param baseCRS    the geographic CRS on which the projected CRS is based.
 * @param isUTM      {@code true} for UTM or {@code false} for UPS. Note: redundant with the given latitude.
 * @param latitude   a latitude in the zone of the desired projection, to be snapped to 0°, 90°S or 90°N.
 * @param longitude  a longitude in the zone of the desired projection, to be snapped to UTM central meridian.
 * @param derivedCS  the projected coordinate system.
 */
static ProjectedCRS createUniversal(final int code, final GeographicCRS baseCRS, final boolean isUTM,
        final double latitude, final double longitude, final CartesianCS derivedCS)
{
    final OperationMethod method;
    try {
        method = DefaultFactories.forBuildin(MathTransformFactory.class, DefaultMathTransformFactory.class)
                        .getOperationMethod(isUTM ? TransverseMercator.NAME : PolarStereographicA.NAME);
    } catch (NoSuchIdentifierException e) {
        throw new IllegalStateException(e);                     // Should not happen with SIS implementation.
    }
    final ParameterValueGroup parameters = method.getParameters().createValue();
    String name = isUTM ? TransverseMercator.Zoner.UTM.setParameters(parameters, latitude, longitude)
                        : PolarStereographicA.setParameters(parameters, latitude >= 0);
    final DefaultConversion conversion = new DefaultConversion(properties(0, name, null, false), method, null, parameters);

    name = baseCRS.getName().getCode() + " / " + name;
    return new DefaultProjectedCRS(properties(code, name, null, false), baseCRS, conversion, derivedCS);
}
 
Example #6
Source File: StandardDefinitions.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a geodetic CRS from hard-coded values for the given code.
 *
 * @param  code   the EPSG code.
 * @param  datum  the geodetic datum.
 * @param  cs     the coordinate system.
 * @return the geographic CRS for the given code.
 */
static GeographicCRS createGeographicCRS(final short code, final GeodeticDatum datum, final EllipsoidalCS cs) {
    final String name;
    String  alias = null;
    String  scope = null;
    boolean world = false;
    switch (code) {
        case 4326: name = "WGS 84"; world = true;           scope = "Horizontal component of 3D system."; break;
        case 4322: name = "WGS 72"; world = true;           scope = "Horizontal component of 3D system."; break;
        case 4258: name = "ETRS89"; alias = "ETRS89-GRS80"; scope = "Horizontal component of 3D system."; break;
        case 4269: name = "NAD83";                          scope = "Geodetic survey.";                   break;
        case 4267: name = "NAD27";                          scope = "Geodetic survey.";                   break;
        case 4230: name = "ED50";                           scope = "Geodetic survey.";                   break;
        case 4019: name = "Unknown datum based upon the GRS 1980 ellipsoid";           world = true;      break;
        case 4047: name = "Unspecified datum based upon the GRS 1980 Authalic Sphere"; world = true;      break;
        default:   throw new AssertionError(code);
    }
    final Map<String, Object> properties = properties(code, name, alias, world);
    properties.put(SCOPE_KEY, scope);
    return new DefaultGeographicCRS(properties, datum, cs);
}
 
Example #7
Source File: AuthorityFactoriesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests creation of {@code EPSG:4326} from codes for various versions of the EPSG database.
 * This test verifies the logged messages.
 *
 * @throws FactoryException if an EPSG:4326 creation failed.
 */
@Test
public void testVersionedEPSG() throws FactoryException {
    final CRSAuthorityFactory factory = AuthorityFactories.ALL;
    final GeographicCRS crs = factory.createGeographicCRS("EPSG:4326");
    loggings.assertNoUnexpectedLog();

    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:6.11.2:4326"));
    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:6.11.2:4326"));
    loggings.assertNextLogContains("6.11.2");
    loggings.assertNoUnexpectedLog();

    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:7.04:4326"));
    loggings.assertNextLogContains("7.04");
    loggings.assertNoUnexpectedLog();

    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:7.10:4326"));
    loggings.assertNextLogContains("7.10");
    loggings.assertNoUnexpectedLog();

    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG::4326"));
    loggings.assertNoUnexpectedLog();
}
 
Example #8
Source File: AuthorityFactoriesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests creation of {@code CRS:84} from various codes.
 *
 * @throws FactoryException if a CRS:84 creation failed.
 */
@Test
public void testCRS84() throws FactoryException {
    final CRSAuthorityFactory factory = AuthorityFactories.ALL;
    final GeographicCRS crs = factory.createGeographicCRS("CRS:84");
    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:CRS::84"));
    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:CRS:1.3:84"));
    assertSame(crs, factory.createGeographicCRS("URN:OGC:DEF:CRS:CRS:1.3:84"));
    assertSame(crs, factory.createGeographicCRS("URN:OGC:DEF:CRS:CRS::84"));
    assertSame(crs, factory.createGeographicCRS("urn:x-ogc:def:crs:CRS:1.3:84"));
    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:OGC:1.3:CRS84"));

    // Following are just wrappers for above factory.
    assertSame(crs, CRS.forCode("urn:ogc:def:crs:CRS:1.3:84"));
    assertSame(crs, CRS.forCode("urn:ogc:def:crs:OGC:1.3:CRS84"));
    assertSame(crs, CRS.forCode("CRS:84"));
    assertSame(crs, CRS.forCode("OGC:CRS84"));

    assertNotDeepEquals(crs, CRS.forCode("CRS:83"));
}
 
Example #9
Source File: CommonCRSTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the {@link CommonCRS#geographic3D()} method.
 */
@Test
@DependsOnMethod("testGeographic")
public void testGeographic3D() {
    final GeographicCRS crs = CommonCRS.WGS72.geographic3D();
    Validators.validate(crs);
    assertEquals ("WGS 72", crs.getName().getCode());
    assertSame   (CommonCRS.WGS72.geographic().getDatum(), crs.getDatum());
    assertNotSame(CommonCRS.WGS84.geographic().getDatum(), crs.getDatum());

    final EllipsoidalCS cs = crs.getCoordinateSystem();
    final String name = cs.getName().getCode();
    assertTrue(name, name.startsWith("Ellipsoidal 3D"));
    assertEquals("dimension", 3, cs.getDimension());
    assertAxisDirectionsEqual(name, cs, AxisDirection.NORTH, AxisDirection.EAST, AxisDirection.UP);
    assertSame("Cached value", crs, CommonCRS.WGS72.geographic3D());
}
 
Example #10
Source File: MultiAuthoritiesFactoryTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #11
Source File: CommonAuthorityFactory.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Provides a complete set of the known codes provided by this factory.
 * The returned set contains a namespace followed by numeric identifiers
 * like {@code "CRS:84"}, {@code "CRS:27"}, {@code "AUTO2:42001"}, <i>etc</i>.
 *
 * @param  type  the spatial reference objects type.
 * @return the set of authority codes for spatial reference objects of the given type.
 * @throws FactoryException if this method failed to provide the set of codes.
 */
@Override
public Set<String> getAuthorityCodes(final Class<? extends IdentifiedObject> type) throws FactoryException {
    ArgumentChecks.ensureNonNull("type", type);
    if (!type.isAssignableFrom(SingleCRS.class) && !SingleCRS.class.isAssignableFrom(type)) {
        return Collections.emptySet();
    }
    synchronized (codes) {
        if (codes.isEmpty()) {
            add(Constants.CRS1,  EngineeringCRS.class);
            add(Constants.CRS27, GeographicCRS.class);
            add(Constants.CRS83, GeographicCRS.class);
            add(Constants.CRS84, GeographicCRS.class);
            add(Constants.CRS88, VerticalCRS.class);
            for (int code = FIRST_PROJECTION_CODE; code < FIRST_PROJECTION_CODE + PROJECTION_NAMES.length; code++) {
                add(code, ProjectedCRS.class);
            }
        }
    }
    return new FilteredCodes(codes, type).keySet();
}
 
Example #12
Source File: CoordinateOperationFinderTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a transformation with a three-dimensional geographic source CRS.
 * This method verifies with both a three-dimensional and a two-dimensional target CRS.
 *
 * @throws ParseException if a CRS used in this test can not be parsed.
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testGeocentricTranslationInGeographic2D")
public void testGeocentricTranslationInGeographic3D() throws ParseException, FactoryException, TransformException {
    final GeographicCRS sourceCRS = (GeographicCRS) parse(
            "GeodeticCRS[“NAD27”,\n" +
            "  Datum[“North American Datum 1927”,\n" +
            "    Ellipsoid[“Clarke 1866”, 6378206.4, 294.9786982138982],\n" +
            "    ToWGS84[-8, 160, 176]]," +                                     // See comment in above test.
            "  CS[ellipsoidal, 3],\n" +
            "    Axis[“Latitude (φ)”, NORTH, Unit[“degree”, 0.017453292519943295]],\n" +
            "    Axis[“Longitude (λ)”, EAST, Unit[“degree”, 0.017453292519943295]],\n" +
            "    Axis[“Height (h)”, UP, Unit[“m”, 1]]]");

    testGeocentricTranslationInGeographicDomain("Geocentric translations (geog3D domain)",
            sourceCRS, CommonCRS.WGS84.geographic3D());

    isInverseTransformSupported = false;                // Because lost of height values changes (φ,λ) results.
    testGeocentricTranslationInGeographicDomain("Geocentric translations (geog3D domain)",
            sourceCRS, CommonCRS.WGS84.geographic());
}
 
Example #13
Source File: ServicesForMetadata.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Sets a geographic bounding box from the specified envelope.
 * If the envelope has no CRS, then (<var>longitude</var>, <var>latitude</var>) axis order is assumed.
 * If the envelope CRS is not geographic, then the envelope will be transformed to a geographic CRS.
 * If {@code findOpCaller} is {@code true}, then some failures will cause this method to return {@code null}
 * instead than throwing an exception, and warning may be logged with assumption that caller is the named
 * method from {@link Envelopes} — typically {@link Envelopes#findOperation(Envelope, Envelope)}.
 *
 * @param  envelope      the source envelope.
 * @param  target        the target bounding box, or {@code null} for creating it automatically.
 * @param  findOpCaller  non-null for replacing some (not all) exceptions by {@code null} return value.
 * @return the bounding box or {@code null} on failure. Never {@code null} if {@code findOpCaller} argument is {@code null}.
 * @throws TransformException if the given envelope can not be transformed.
 */
@Override
public DefaultGeographicBoundingBox setBounds(final Envelope envelope, final DefaultGeographicBoundingBox target,
        final String findOpCaller) throws TransformException
{
    final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();
    GeographicCRS normalizedCRS = ReferencingUtilities.toNormalizedGeographicCRS(crs, false, false);
    if (normalizedCRS == null) {
        if (crs != null) {
            normalizedCRS = CommonCRS.defaultGeographic();
        } else if (envelope.getDimension() != 2) {
            if (findOpCaller != null) return null;
            throw new TransformException(dimensionNotFound(Resources.Keys.MissingHorizontalDimension_1, crs));
        }
    }
    return setGeographicExtent(envelope, target, crs, normalizedCRS, findOpCaller);
}
 
Example #14
Source File: EnvelopesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation of {@link #testAxisRangeChange3D()} and {@link #testAxisRangeChangeWithDatumShift()}.
 */
private void testAxisRangeChange3D(final GeographicCRS targetCRS) throws FactoryException, TransformException {
    final GeneralEnvelope envelope  = new GeneralEnvelope(new double[] { -0.5, -90, 1000},
                                                          new double[] {354.5, +90, 1002});
    envelope.setCoordinateReferenceSystem(CRS.compound(
            HardCodedCRS.WGS84.forConvention(AxesConvention.POSITIVE_RANGE), HardCodedCRS.TIME));
    final GeneralEnvelope expected = createFromExtremums(targetCRS, -0.5, -90, -5.5, 90);
    assertEnvelopeEquals(expected, Envelopes.transform(envelope, targetCRS), STRICT, STRICT);
    /*
     * When the envelope to transform span the full longitude range,
     * target envelope should unconditionally be [-180 … +180]°.
     */
    envelope.setRange(0, -0.5, 359.5);
    expected.setRange(0, -180, 180);
    assertEnvelopeEquals(expected, Envelopes.transform(envelope, targetCRS), STRICT, STRICT);
}
 
Example #15
Source File: CRSTable.java    From sis with Apache License 2.0 6 votes vote down vote up
static Image getIcon(IdentifiedObject obj) {
    Image icon = ICON_UNKNOWN;
    if (obj instanceof GeographicCRS) {
        icon = ICON_GEO;
    } else if (obj instanceof ProjectedCRS) {
        final ProjectedCRS pcrs = (ProjectedCRS) obj;
        final Projection proj = pcrs.getConversionFromBase();

        if (String.valueOf(proj.getName()).toLowerCase().contains("utm")) {
            icon = ICON_UTM;
        } else if (proj instanceof ConicProjection) {
            icon = ICON_CONIC;
        } else if (proj instanceof CylindricalProjection) {
            icon = ICON_SQUARE;
        } else if (proj instanceof PlanarProjection) {
            icon = ICON_STEREO;
        } else {
            icon = ICON_SQUARE;
        }
    } else {
        icon = ICON_SQUARE;
    }
    return icon;
}
 
Example #16
Source File: OperationMethodCrsProvider.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CoordinateReferenceSystem getCRS(final GeoPos referencePos, ParameterValueGroup parameters,
                                        GeodeticDatum datum) throws FactoryException {
    final CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null);
    // in some cases, depending on the parameters set, the effective transformation can be different
    // from the transformation given by the OperationMethod.
    // So we create a new one
    final MathTransformFactory mtFactory = ReferencingFactoryFinder.getMathTransformFactory(null);
    final MathTransform transform = mtFactory.createParameterizedTransform(parameters);
    final DefaultOperationMethod operationMethod = new DefaultOperationMethod(transform);

    final Conversion conversion = new DefiningConversion(AbstractIdentifiedObject.getProperties(operationMethod),
                                                         operationMethod, transform);

    final HashMap<String, Object> baseCrsProperties = new HashMap<String, Object>();
    baseCrsProperties.put("name", datum.getName().getCode());
    GeographicCRS baseCrs = crsFactory.createGeographicCRS(baseCrsProperties,
                                                           datum,
                                                           DefaultEllipsoidalCS.GEODETIC_2D);

    final HashMap<String, Object> projProperties = new HashMap<String, Object>();
    projProperties.put("name", conversion.getName().getCode() + " / " + datum.getName().getCode());
    return crsFactory.createProjectedCRS(projProperties, baseCrs, conversion, DefaultCartesianCS.PROJECTED);
}
 
Example #17
Source File: StoreTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link StoreProvider#probeContent(StorageConnector)} followed by {@link Store#getMetadata()}
 * reading from an {@link java.io.InputStream}. This method tests indirectly {@link StorageConnector}
 * capability to reset the {@code InputStream} to its original position after {@code probeContent(…)}.
 *
 * @throws DataStoreException if en error occurred while reading the WKT.
 */
@Test
public void testFromInputStream() throws DataStoreException {
    final Metadata metadata;
    final StoreProvider p = new StoreProvider();
    final StorageConnector c = new StorageConnector(new ByteArrayInputStream(StoreTest.WKT.getBytes(StandardCharsets.US_ASCII)));
    assertTrue("isSupported", p.probeContent(c).isSupported());
    try (Store store = new Store(null, c)) {
        metadata = store.getMetadata();
        assertSame("Expected cached value.", metadata, store.getMetadata());
    }
    validate((GeographicCRS) TestUtilities.getSingleton(metadata.getReferenceSystemInfo()));
}
 
Example #18
Source File: AuthorityFactoryMock.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the authority codes for the given type.
 */
@Override
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) {
    assertFalse("This factory has been closed.", isClosed());
    final Set<String> codes = new LinkedHashSet<>();
    if (type.isAssignableFrom(GeocentricCRS.class)) add(codes, 4979);
    if (type.isAssignableFrom(GeographicCRS.class)) add(codes, 84, 4326);
    if (type.isAssignableFrom(PrimeMeridian.class)) add(codes, 8901, 8903, 8914);
    if (type.isAssignableFrom(GeodeticDatum.class)) add(codes, 6326, 6322, 6807, 6301, 6612, 6047);
    if (type.isAssignableFrom(VerticalDatum.class)) add(codes, 5100);
    if (type.isAssignableFrom(VerticalCRS.class))   add(codes, 5714, 9905);
    if (type.isAssignableFrom(EllipsoidalCS.class)) add(codes, 6422, 6424);
    return codes;
}
 
Example #19
Source File: CRS.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the domain of validity of the specified coordinate reference system, or {@code null} if unknown.
 * If non-null, then the returned envelope will use the same coordinate reference system them the given CRS
 * argument.
 *
 * @param  crs  the coordinate reference system, or {@code null}.
 * @return the envelope with coordinates in the given CRS, or {@code null} if none.
 *
 * @see #getGeographicBoundingBox(CoordinateReferenceSystem)
 *
 * @category information
 * @since 0.8
 */
public static Envelope getDomainOfValidity(final CoordinateReferenceSystem crs) {
    Envelope envelope = null;
    GeneralEnvelope merged = null;
    /* if (envelope == null) */ {   // Condition needed on other branches but not on trunk.
        final GeographicBoundingBox bounds = getGeographicBoundingBox(crs);
        if (bounds != null && !Boolean.FALSE.equals(bounds.getInclusion())) {
            /*
             * We do not assign WGS84 unconditionally to the geographic bounding box, because
             * it is not defined to be on a particular datum; it is only approximated bounds.
             * We try to get the GeographicCRS from the user-supplied CRS in order to reduce
             * the amount of transformation needed.
             */
            final SingleCRS targetCRS = getHorizontalComponent(crs);
            final GeographicCRS sourceCRS = ReferencingUtilities.toNormalizedGeographicCRS(targetCRS, false, false);
            if (sourceCRS != null) {
                envelope = merged = new GeneralEnvelope(bounds);
                merged.translate(-getGreenwichLongitude(sourceCRS), 0);
                merged.setCoordinateReferenceSystem(sourceCRS);
                try {
                    envelope = Envelopes.transform(envelope, targetCRS);
                } catch (TransformException exception) {
                    /*
                     * The envelope is probably outside the range of validity for this CRS.
                     * It should not occurs, since the envelope is supposed to describe the
                     * CRS area of validity. Logs a warning and returns null, since it is a
                     * legal return value according this method contract.
                     */
                    unexpectedException("getEnvelope", exception);
                    envelope = null;
                }
            }
        }
    }
    return envelope;
}
 
Example #20
Source File: EllipsoidalHeightCombinerTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link EllipsoidalHeightCombiner#createCompoundCRS EllipsoidalHeightCombiner.createCompoundCRS(…)}
 * with a geographic CRS.
 *
 * @throws FactoryException if a CRS can not be created.
 */
@Test
public void testGeographicCRS() throws FactoryException {
    final EllipsoidalHeightCombiner services = create();
    final Map<String,String> properties = Collections.singletonMap(CoordinateReferenceSystem.NAME_KEY, "WGS 84 (4D)");
    final GeographicCRS horizontal = HardCodedCRS.WGS84;
    final GeographicCRS volumetric = HardCodedCRS.WGS84_3D;
    final VerticalCRS   vertical   = HardCodedCRS.ELLIPSOIDAL_HEIGHT;
    final TemporalCRS   temporal   = HardCodedCRS.TIME;
    final VerticalCRS   geoidal    = HardCodedCRS.GRAVITY_RELATED_HEIGHT;
    /*
     * createCompoundCRS(…) should not combine GeographicCRS with non-ellipsoidal height.
     */
    CoordinateReferenceSystem compound = services.createCompoundCRS(properties, horizontal, geoidal, temporal);
    assertArrayEqualsIgnoreMetadata(new SingleCRS[] {horizontal, geoidal, temporal}, CRS.getSingleComponents(compound).toArray());
    /*
     * createCompoundCRS(…) should combine GeographicCRS with ellipsoidal height.
     */
    compound = services.createCompoundCRS(properties, horizontal, vertical);
    assertArrayEqualsIgnoreMetadata(new SingleCRS[] {volumetric}, CRS.getSingleComponents(compound).toArray());
    /*
     * createCompoundCRS(…) should combine GeographicCRS with ellipsoidal height and keep time.
     */
    compound = services.createCompoundCRS(properties, horizontal, vertical, temporal);
    assertArrayEqualsIgnoreMetadata(new SingleCRS[] {volumetric, temporal}, CRS.getSingleComponents(compound).toArray());
    /*
     * Non-standard feature: accept (VerticalCRS + GeodeticCRS) order.
     * The test below use the reverse order for all axes compared to the previous test.
     */
    compound = services.createCompoundCRS(properties, temporal, vertical, HardCodedCRS.WGS84_φλ);
    final Object[] components = CRS.getSingleComponents(compound).toArray();
    assertEquals(2, components.length);
    assertEqualsIgnoreMetadata(temporal, components[0]);
    assertInstanceOf("Shall be a three-dimensional geographic CRS.", GeographicCRS.class, components[1]);
    assertAxisDirectionsEqual("Shall be a three-dimensional geographic CRS.",
            ((CoordinateReferenceSystem) components[1]).getCoordinateSystem(),
            AxisDirection.UP, AxisDirection.NORTH, AxisDirection.EAST);
}
 
Example #21
Source File: CoordinateOperationFinderTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests conversion from spatiotemporal CRS to a derived CRS.
 *
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testProjected4D_to_2D")
public void testSpatioTemporalToDerived() throws FactoryException, TransformException {
    final Map<String,Object> properties = new HashMap<>();
    properties.put(DerivedCRS.NAME_KEY, "Display");
    properties.put("conversion.name", "Display to WGS84");

    final GeographicCRS WGS84     = CommonCRS.WGS84.normalizedGeographic();
    final CompoundCRS   sourceCRS = compound("Test3D", WGS84, CommonCRS.Temporal.UNIX.crs());
    final DerivedCRS    targetCRS = DefaultDerivedCRS.create(properties,
            WGS84, null, factory.getOperationMethod("Affine"),
            MathTransforms.linear(Matrices.create(3, 3, new double[] {
                12,  0, 480,
                0, -12, 790,
                0,   0,   1
            })), HardCodedCS.DISPLAY);

    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
    assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
    assertSame("targetCRS", targetCRS, operation.getTargetCRS());

    transform = operation.getMathTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertEquals("sourceDimensions", 3, transform.getSourceDimensions());
    assertEquals("targetDimensions", 2, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 4, new double[] {
        12,  0,  0, 480,
        0, -12,  0, 790,
        0,   0,  0,   1
    }), ((LinearTransform) transform).getMatrix(), STRICT);
    validate();
}
 
Example #22
Source File: CoordinateOperationFinderTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the conversion from a two-dimensional geographic CRS to a three-dimensional geographic CRS.
 * Coordinate values of the vertical dimension should be set to zero.
 *
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testGeographic3D_to_2D")
public void testGeographic2D_to_3D() throws FactoryException, TransformException {
    final GeographicCRS sourceCRS = CommonCRS.WGS84.geographic();
    final GeographicCRS targetCRS = CommonCRS.WGS84.geographic3D();
    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
    assertSame      ("sourceCRS", sourceCRS,        operation.getSourceCRS());
    assertSame      ("targetCRS", targetCRS,        operation.getTargetCRS());
    assertEquals    ("name",      "Axis changes",   operation.getName().getCode());
    assertInstanceOf("operation", Conversion.class, operation);

    final ParameterValueGroup parameters = ((SingleOperation) operation).getParameterValues();
    assertEquals("parameters.descriptor", "Geographic2D to 3D conversion", parameters.getDescriptor().getName().getCode());
    assertEquals("parameters.height", 0, parameters.parameter("height").doubleValue(), STRICT);

    transform = operation.getMathTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertEquals("sourceDimensions", 2, transform.getSourceDimensions());
    assertEquals("targetDimensions", 3, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(4, 3, new double[] {
        1, 0, 0,
        0, 1, 0,
        0, 0, 0,
        0, 0, 1
    }), ((LinearTransform) transform).getMatrix(), STRICT);

    verifyTransform(new double[] {
        30, 10,
        20, 30
    }, new double[] {
        30, 10, 0,
        20, 30, 0
    });
    validate();
}
 
Example #23
Source File: CoordinateOperationFinderTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the conversion from a three-dimensional geographic CRS to a two-dimensional geographic CRS.
 * The vertical dimension is simply dropped.
 *
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testIdentityTransform")
public void testGeographic3D_to_2D() throws FactoryException, TransformException {
    final GeographicCRS sourceCRS = CommonCRS.WGS84.geographic3D();
    final GeographicCRS targetCRS = CommonCRS.WGS84.geographic();
    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
    assertSame      ("sourceCRS", sourceCRS,        operation.getSourceCRS());
    assertSame      ("targetCRS", targetCRS,        operation.getTargetCRS());
    assertEquals    ("name",      "Axis changes",   operation.getName().getCode());
    assertInstanceOf("operation", Conversion.class, operation);

    final ParameterValueGroup parameters = ((SingleOperation) operation).getParameterValues();
    assertEquals("parameters.descriptor", "Geographic3D to 2D conversion", parameters.getDescriptor().getName().getCode());
    assertTrue  ("parameters.isEmpty", parameters.values().isEmpty());

    transform = operation.getMathTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertEquals("sourceDimensions", 3, transform.getSourceDimensions());
    assertEquals("targetDimensions", 2, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 4, new double[] {
        1, 0, 0, 0,
        0, 1, 0, 0,
        0, 0, 0, 1
    }), ((LinearTransform) transform).getMatrix(), STRICT);

    isInverseTransformSupported = false;
    verifyTransform(new double[] {
        30, 10,  20,
        20, 30, -10
    }, new double[] {
        30, 10,
        20, 30
    });
    validate();
}
 
Example #24
Source File: SC_GeographicCRS.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by JAXB at marshalling time for getting the actual element to write
 * inside the {@code <gml:GeodeticCRS>} XML element.
 * This is the value or a copy of the value given in argument to the {@code wrap} method.
 *
 * @return the element to be marshalled.
 */
@XmlElement(name = "GeodeticCRS")
public DefaultGeodeticCRS getElement() {
    final GeographicCRS metadata = this.metadata;
    if (metadata == null || metadata instanceof DefaultGeodeticCRS) {
        return (DefaultGeodeticCRS) metadata;
    } else {
        return new DefaultGeodeticCRS(metadata);
    }
}
 
Example #25
Source File: SC_GeographicCRS.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by JAXB at unmarshalling time for storing the result temporarily.
 *
 * @param  cs  the unmarshalled element.
 */
public void setElement(final DefaultGeodeticCRS cs) {
    if (cs == null || cs instanceof GeographicCRS) {
        metadata = (GeographicCRS) cs;
    } else {
        metadata = new DefaultGeographicCRS(cs);
    }
}
 
Example #26
Source File: CodeTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link Code#forIdentifiedObject(Class, Iterable)}.
 */
@Test
@DependsOnMethod("testWithVersion")
public void testForIdentifiedObject() {
    final ReferenceIdentifier id = new ImmutableIdentifier(Citations.EPSG, "EPSG", "4326", "8.2", null);
    final Code value = Code.forIdentifiedObject(GeographicCRS.class, Collections.singleton(id));
    assertNotNull(value);
    assertEquals("codeSpace", Constants.IOGP, value.codeSpace);
    assertEquals("code", "urn:ogc:def:crs:EPSG:8.2:4326", value.code);
}
 
Example #27
Source File: CoordinateOperationFinderTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the conversion from a four-dimensional geographic CRS to a two-dimensional geographic CRS.
 * The vertical and temporal dimensions are simply dropped.
 *
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testGeographic3D_to_2D")
public void testGeographic4D_to_2D() throws FactoryException, TransformException {
    // NOTE: make sure that the 'sourceCRS' below is not equal to any other 'sourceCRS' created in this class.
    final CompoundCRS   sourceCRS = compound("Test4D", CommonCRS.WGS84.geographic3D(), CommonCRS.Temporal.UNIX.crs());
    final GeographicCRS targetCRS = CommonCRS.WGS84.geographic();
    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
    assertSame      ("sourceCRS", sourceCRS,        operation.getSourceCRS());
    assertSame      ("targetCRS", targetCRS,        operation.getTargetCRS());

    transform = operation.getMathTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertEquals("sourceDimensions", 4, transform.getSourceDimensions());
    assertEquals("targetDimensions", 2, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 5, new double[] {
        1, 0, 0, 0, 0,
        0, 1, 0, 0, 0,
        0, 0, 0, 0, 1
    }), ((LinearTransform) transform).getMatrix(), STRICT);

    isInverseTransformSupported = false;
    verifyTransform(new double[] {
        30, 10,  20, 1000,
        20, 30, -10, 3000
    }, new double[] {
        30, 10,
        20, 30
    });
    validate();
}
 
Example #28
Source File: CoordinateOperationFinderTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests a transformation using the <cite>"Geocentric translations (geog2D domain)"</cite> method
 * together with a longitude rotation and unit conversion. The CRS and sample point are taken from
 * the GR3DF97A – <cite>Grille de paramètres de transformation de coordonnées</cite> document.
 *
 * @throws ParseException if a CRS used in this test can not be parsed.
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testGeocentricTranslationInGeographic2D")
public void testLongitudeRotation() throws ParseException, FactoryException, TransformException {
    final CoordinateReferenceSystem sourceCRS = parse(
            "GeodeticCRS[“NTF (Paris)”, $NTF,\n" +
            "  PrimeMeridian[“Paris”, 2.5969213],\n" +          // in grads, not degrees.
            "  CS[ellipsoidal, 2],\n" +
            "    Axis[“Latitude (φ)”, NORTH],\n" +
            "    Axis[“Longitude (λ)”, EAST],\n" +
            "    Unit[“grad”, 0.015707963267949],\n" +
            "  Id[“EPSG”, “4807”]]");

    final GeographicCRS       targetCRS = CommonCRS.WGS84.geographic();
    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);

    assertSame      ("sourceCRS",  sourceCRS,            operation.getSourceCRS());
    assertSame      ("targetCRS",  targetCRS,            operation.getTargetCRS());
    assertFalse     ("isIdentity",                       operation.getMathTransform().isIdentity());
    assertEquals    ("name",       "Datum shift",        operation.getName().getCode());
    assertSetEquals (Arrays.asList(DATUM_SHIFT_APPLIED), operation.getCoordinateOperationAccuracy());
    assertInstanceOf("operation",  Transformation.class, operation);
    assertEquals("method", "Geocentric translations (geog2D domain)",
            ((SingleOperation) operation).getMethod().getName().getCode());
    /*
     * Same test point than the one used in FranceGeocentricInterpolationTest:
     *
     * NTF: 48°50′40.2441″N  2°25′32.4187″E
     * RGF: 48°50′39.9967″N  2°25′29.8273″E     (close to WGS84)
     */
    transform  = operation.getMathTransform();
    tolerance  = ANGULAR_TOLERANCE;
    λDimension = new int[] {1};
    verifyTransform(new double[] {54.271680278,  0.098269657},      // in grads east of Paris
                    new double[] {48.844443528,  2.424952028});     // in degrees east of Greenwich
    validate();
}
 
Example #29
Source File: CommonCRSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the {@link CommonCRS#geographic()} method.
 */
@Test
public void testGeographic() {
    final GeographicCRS geographic = CommonCRS.WGS84.geographic();
    Validators.validate(geographic);
    GeodeticObjectVerifier.assertIsWGS84(geographic, true, true);
    assertSame("Cached value", geographic, CommonCRS.WGS84.geographic());
}
 
Example #30
Source File: GeodeticObjectBuilder.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a projected CRS with base CRS on the specified datum and with default axes.
 * The base CRS uses the ellipsoid specified by {@link #setFlattenedSphere(String, double, double, Unit)}.
 *
 * @return the projected CRS.
 * @throws FactoryException if an error occurred while building the projected CRS.
 */
public ProjectedCRS createProjectedCRS() throws FactoryException {
    GeographicCRS crs = CommonCRS.WGS84.geographic();
    if (datum != null) {
        crs = factories.getCRSFactory().createGeographicCRS(name(datum), datum, crs.getCoordinateSystem());
    }
    return createProjectedCRS(crs, factories.getStandardProjectedCS());
}