org.opengis.referencing.datum.GeodeticDatum Java Examples

The following examples show how to use org.opengis.referencing.datum.GeodeticDatum. 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: AuthorityFactoryProxyTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link AuthorityFactoryProxy#getInstance(Class)}.
 */
@Test
public void testGetInstance() {
    assertEquals(ProjectedCRS.class,              AuthorityFactoryProxy.getInstance(ProjectedCRS.class)        .type);
    assertEquals(ProjectedCRS.class,              AuthorityFactoryProxy.getInstance(DefaultProjectedCRS.class) .type);
    assertEquals(GeographicCRS.class,             AuthorityFactoryProxy.getInstance(GeographicCRS.class)       .type);
    assertEquals(GeographicCRS.class,             AuthorityFactoryProxy.getInstance(DefaultGeographicCRS.class).type);
    assertEquals(DerivedCRS.class,                AuthorityFactoryProxy.getInstance(DefaultDerivedCRS.class)   .type);
    assertEquals(GeodeticDatum.class,             AuthorityFactoryProxy.getInstance(DefaultGeodeticDatum.class).type);
    assertEquals(CoordinateReferenceSystem.class, AuthorityFactoryProxy.getInstance(AbstractCRS.class)         .type);
    assertEquals(CoordinateSystem.class,          AuthorityFactoryProxy.getInstance(CoordinateSystem.class)    .type);
    assertEquals(CoordinateSystemAxis.class,      AuthorityFactoryProxy.getInstance(CoordinateSystemAxis.class).type);
    assertEquals(PrimeMeridian.class,             AuthorityFactoryProxy.getInstance(PrimeMeridian.class)       .type);
    assertEquals(Ellipsoid.class,                 AuthorityFactoryProxy.getInstance(Ellipsoid.class)           .type);
    assertEquals(Datum.class,                     AuthorityFactoryProxy.getInstance(Datum.class)               .type);
}
 
Example #2
Source File: CustomCrsPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public static Set<GeodeticDatum> createDatumSet() {
    DatumAuthorityFactory factory = ReferencingFactoryFinder.getDatumAuthorityFactory("EPSG", null);
    List<String> datumCodes = retrieveCodes(GeodeticDatum.class, factory);
    Set<GeodeticDatum> datumSet = new TreeSet<>(AbstractIdentifiedObject.NAME_COMPARATOR);
    for (String datumCode : datumCodes) {
        try {
            DefaultGeodeticDatum geodeticDatum = (DefaultGeodeticDatum) factory.createGeodeticDatum(datumCode);
            if (geodeticDatum.getBursaWolfParameters().length != 0 ||
                    DefaultGeodeticDatum.isWGS84(geodeticDatum)) {
                datumSet.add(geodeticDatum);
            }
        } catch (FactoryException ignored) {
        }
    }
    return datumSet;
}
 
Example #3
Source File: CustomCrsPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public void setCustom(GeodeticDatum geodeticDatum, OperationMethod operationMethod, ParameterValueGroup parameterValues) {
    String geodeticDatumName = geodeticDatum.getName().getCode();
    for (GeodeticDatum datum : datumSet) {
        if (datum.getName().getCode().equals(geodeticDatumName)) {
            vc.setValue(DATUM, datum);
            break;
        }
    }
    for (AbstractCrsProvider abstractCrsProvider : crsProviderSet) {
        if (abstractCrsProvider instanceof OperationMethodCrsProvider) {
            OperationMethodCrsProvider operationMethodCrsProvider = (OperationMethodCrsProvider) abstractCrsProvider;
            String operationMethodName = operationMethod.getName().getCode();
            if (operationMethodCrsProvider.delegate.getName().getCode().equals(operationMethodName)) {
                vc.setValue(OPERATION_WRAPPER, abstractCrsProvider);
                break;
            }
        }
    }
    vc.setValue(PARAMETERS, parameterValues);
}
 
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 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 #6
Source File: StandardDefinitions.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a geodetic datum from hard-coded values for the given code.
 *
 * @param  code       the EPSG code.
 * @param  ellipsoid  the datum ellipsoid.
 * @param  meridian   the datum prime meridian.
 * @return the geodetic datum for the given code.
 */
static GeodeticDatum createGeodeticDatum(final short code, final Ellipsoid ellipsoid, final PrimeMeridian meridian) {
    final String name;
    final String alias;
    boolean world = false;
    switch (code) {
        case 6326: name = "World Geodetic System 1984";                        alias = "WGS 84"; world = true; break;
        case 6322: name = "World Geodetic System 1972";                        alias = "WGS 72"; world = true; break;
        case 6258: name = "European Terrestrial Reference System 1989";        alias = "ETRS89";               break;
        case 6269: name = "North American Datum 1983";                         alias = "NAD83";                break;
        case 6267: name = "North American Datum 1927";                         alias = "NAD27";                break;
        case 6230: name = "European Datum 1950";                               alias = "ED50";                 break;
        case 6019: name = "Not specified (based on GRS 1980 ellipsoid)";       alias = null;     world = true; break;
        case 6047: name = "Not specified (based on GRS 1980 Authalic Sphere)"; alias = null;     world = true; break;
        default:   throw new AssertionError(code);
    }
    return new DefaultGeodeticDatum(properties(code, name, alias, world), ellipsoid, meridian);
}
 
Example #7
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 #8
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 #9
Source File: AbstractUTMCrsProvider.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
CoordinateReferenceSystem createCrs(String crsName, OperationMethod method,
                                              ParameterValueGroup parameters,
                                              GeodeticDatum datum) throws FactoryException {
    final CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null);
    final CoordinateOperationFactory coFactory = ReferencingFactoryFinder.getCoordinateOperationFactory(null);
    final HashMap<String, Object> projProperties = new HashMap<String, Object>();
    projProperties.put("name", crsName + " / " + datum.getName().getCode());
    final Conversion conversion = coFactory.createDefiningConversion(projProperties,
                                                                     method,
                                                                     parameters);
    final HashMap<String, Object> baseCrsProperties = new HashMap<String, Object>();
    baseCrsProperties.put("name", datum.getName().getCode());
    final GeographicCRS baseCrs = crsFactory.createGeographicCRS(baseCrsProperties, datum,
                                                                 DefaultEllipsoidalCS.GEODETIC_2D);
    return crsFactory.createProjectedCRS(projProperties, baseCrs, conversion, DefaultCartesianCS.PROJECTED);
}
 
Example #10
Source File: CustomCrsPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static List<String> retrieveCodes(Class<? extends GeodeticDatum> crsType, AuthorityFactory factory) {
    try {
        Set<String> localCodes = factory.getAuthorityCodes(crsType);
        return new ArrayList<>(localCodes);
    } catch (FactoryException ignore) {
        return Collections.emptyList();
    }
}
 
Example #11
Source File: CRSBuilder.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies if the user-defined CRS created from GeoTIFF values
 * matches the given CRS created from the EPSG geodetic dataset.
 * This method does not verify the EPSG code of the given CRS.
 *
 * @param  crs          the CRS created from the EPSG geodetic dataset.
 * @param  angularUnit  the angular unit of the latitude and longitude values.
 */
private void verify(final GeographicCRS crs, final Unit<Angle> angularUnit) throws FactoryException {
    /*
     * Note: current createUnit(…) implementation does not allow us to distinguish whether METRE ou DEGREE units
     * were specified in the GeoTIFF file or if we got the default values. We do not compare units of that reason.
     */
    final Unit<Length> linearUnit = createUnit(GeoKeys.GeogLinearUnits, GeoKeys.GeogLinearUnitSize, Length.class, Units.METRE);
    final GeodeticDatum datum = crs.getDatum();
    verifyIdentifier(crs, datum, GeoKeys.GeodeticDatum);
    verify(datum, angularUnit, linearUnit);
}
 
Example #12
Source File: CustomCrsPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public CustomCrsPanel(Window parent, Set<GeodeticDatum> datumSet, Set<AbstractCrsProvider> crsProviderSet) {
    this.parent = parent;

    this.datumSet = datumSet;
    this.crsProviderSet = crsProviderSet;

    GeodeticDatum wgs84Datum = null;
    // This is necessary because DefaultGeodeticDatum.WGS84 is
    // not equal to the geodetic WGS84 datum from the database
    for (GeodeticDatum geodeticDatum : datumSet) {
        if (DefaultGeodeticDatum.isWGS84(geodeticDatum)) {
            wgs84Datum = geodeticDatum;
            break;
        }
    }
    AbstractCrsProvider defaultMethod = new WGS84CrsProvider(wgs84Datum);
    crsProviderSet.add(defaultMethod);
    crsProviderSet.add(new UTMZonesCrsProvider(wgs84Datum));
    crsProviderSet.add(new UTMAutomaticCrsProvider(wgs84Datum));

    model = new Model();
    model.operationWrapper = defaultMethod;
    model.datum = wgs84Datum;

    vc = PropertyContainer.createObjectBacked(model);
    vc.addPropertyChangeListener(new UpdateListener());

    createUI();
    updateModel(OPERATION_WRAPPER);
}
 
Example #13
Source File: AbstractCrsProvider.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
AbstractCrsProvider(String name, boolean hasParameters,
            boolean datumChangable, GeodeticDatum defaultDatum) {
    this.name = name;
    this.hasParameters = hasParameters;
    isDatumChangable = datumChangable;
    this.defaultDatum = defaultDatum;
}
 
Example #14
Source File: StandardDefinitionsTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Compares the values created by {@code StandardDefinitions} against hard-coded constants.
 * This method tests the following methods:
 *
 * <ul>
 *   <li>{@link StandardDefinitions#createEllipsoid(short)}</li>
 *   <li>{@link StandardDefinitions#createGeodeticDatum(short, Ellipsoid, PrimeMeridian)}</li>
 *   <li>{@link StandardDefinitions#createGeographicCRS(short, GeodeticDatum, EllipsoidalCS)}</li>
 * </ul>
 *
 * The geodetic objects are compared against the {@link HardCodedCRS}, {@link HardCodedDatum} and
 * {@link GeodeticDatumMock} constants. Actually this is more a test of the above-cited constants
 * than a {@code StandardDefinitions} one - in case of test failure, any of those classes could be
 * at fault.
 */
@Test
@DependsOnMethod("testCreateAxis")
public void testCreateGeographicCRS() {
    final PrimeMeridian pm = StandardDefinitions.primeMeridian();
    final EllipsoidalCS cs = (EllipsoidalCS) StandardDefinitions.createCoordinateSystem((short) 6422, true);
    for (final CommonCRS e : CommonCRS.values()) {
        final Ellipsoid ellipsoid = StandardDefinitions.createEllipsoid(e.ellipsoid);
        switch (e) {
            case WGS84:  compare(GeodeticDatumMock.WGS84 .getEllipsoid(), ellipsoid); break;
            case WGS72:  compare(GeodeticDatumMock.WGS72 .getEllipsoid(), ellipsoid); break;
            case NAD83:  compare(GeodeticDatumMock.NAD83 .getEllipsoid(), ellipsoid); break;
            case NAD27:  compare(GeodeticDatumMock.NAD27 .getEllipsoid(), ellipsoid); break;
            case SPHERE: compare(GeodeticDatumMock.SPHERE.getEllipsoid(), ellipsoid); break;
        }
        final GeodeticDatum datum = StandardDefinitions.createGeodeticDatum(e.datum, ellipsoid, pm);
        switch (e) {
            case WGS84:  compare(HardCodedDatum.WGS84,  datum); break;
            case WGS72:  compare(HardCodedDatum.WGS72,  datum); break;
            case SPHERE: compare(HardCodedDatum.SPHERE, datum); break;
        }
        final GeographicCRS crs = StandardDefinitions.createGeographicCRS(e.geographic, datum, cs);
        Validators.validate(crs);
        switch (e) {
            case WGS84:  compare(HardCodedCRS.WGS84, crs); break;
        }
        Validators.validate(crs);
    }
}
 
Example #15
Source File: DefaultTransformationTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a geocentric CRS using the given datum.
 */
private static DefaultGeocentricCRS createCRS(final String name, final GeodeticDatum datum) {
    Map<String,?> properties = IdentifiedObjects.getProperties(datum, DefaultGeocentricCRS.IDENTIFIERS_KEY);
    if (name != null) {
        final Map<String,Object> copy = new HashMap<>(properties);
        copy.put(DefaultGeocentricCRS.NAME_KEY, name);
        properties = copy;
    }
    return new DefaultGeocentricCRS(properties, datum, HardCodedCS.GEOCENTRIC);
}
 
Example #16
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 #17
Source File: UTMAutomaticCrsProvider.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CoordinateReferenceSystem getCRS(final GeoPos referencePos, ParameterValueGroup parameters,
                                        GeodeticDatum datum) throws FactoryException {
    int zoneIndex = getZoneIndex(referencePos.getLon());
    final boolean south = referencePos.getLat() < 0.0;
    ParameterValueGroup tmParameters = createTransverseMercatorParameters(zoneIndex, south, datum);
    final String projName = getProjectionName(zoneIndex, south);

    return createCrs(projName, new TransverseMercator.Provider(), tmParameters, datum);
}
 
Example #18
Source File: AbstractUTMCrsProvider.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
ParameterValueGroup createTransverseMercatorParameters(int zoneIndex, boolean south,
                                                                 GeodeticDatum datum) {
    ParameterDescriptorGroup tmParameters = new TransverseMercator.Provider().getParameters();
    ParameterValueGroup tmValues = tmParameters.createValue();

    setValue(tmValues, MapProjection.AbstractProvider.SEMI_MAJOR, datum.getEllipsoid().getSemiMajorAxis());
    setValue(tmValues, MapProjection.AbstractProvider.SEMI_MINOR, datum.getEllipsoid().getSemiMinorAxis());
    setValue(tmValues, MapProjection.AbstractProvider.LATITUDE_OF_ORIGIN, 0.0);
    setValue(tmValues, MapProjection.AbstractProvider.CENTRAL_MERIDIAN, getCentralMeridian(zoneIndex));
    setValue(tmValues, MapProjection.AbstractProvider.SCALE_FACTOR, 0.9996);
    setValue(tmValues, MapProjection.AbstractProvider.FALSE_EASTING, 500000.0);
    setValue(tmValues, MapProjection.AbstractProvider.FALSE_NORTHING, south ? 10000000.0 : 0.0);
    return tmValues;
}
 
Example #19
Source File: AuthorityFactoryProxyTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link AuthorityFactoryProxy#specialize(String)}.
 */
@Test
public void testSpecialize() {
    final AuthorityFactoryProxy<IdentifiedObject> base = AuthorityFactoryProxy.OBJECT;
    assertEquals(CoordinateReferenceSystem.class, base.specialize("CRS")      .type);
    assertEquals(CoordinateSystem.class,          base.specialize("CS")       .type);
    assertEquals(CoordinateSystemAxis.class,      base.specialize("aXis")     .type);
    assertEquals(PrimeMeridian.class,             base.specialize("Meridian") .type);
    assertEquals(Ellipsoid.class,                 base.specialize("ellipsoid").type);
    assertEquals(Datum.class,                     base.specialize("datum")    .type);

    assertEquals(GeodeticDatum.class, AuthorityFactoryProxy.GEODETIC_DATUM.specialize("datum").type);
    assertNull(AuthorityFactoryProxy.COORDINATE_SYSTEM.specialize("datum"));
}
 
Example #20
Source File: Wgs84Projection.java    From occurrence with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the given datum or SRS code and constructs a full 2D geographic reference system.
 *
 * @return the parsed CRS or null if it can't be interpreted
 */
@VisibleForTesting
protected static CoordinateReferenceSystem parseCRS(String datum) {
  CoordinateReferenceSystem crs = null;
  ParseResult<Integer> epsgCode = PARSER.parse(datum);
  if (epsgCode.isSuccessful()) {
    final String code = "EPSG:" + epsgCode.getPayload();

    // first try to create a full fledged CRS from the given code
    try {
      crs = CRS.decode(code);

    } catch (FactoryException e) {
      // that didn't work, maybe it is *just* a datum
      try {
        GeodeticDatum dat = DATUM_FACTORY.createGeodeticDatum(code);
        crs = new DefaultGeographicCRS(dat, DefaultEllipsoidalCS.GEODETIC_2D);

      } catch (FactoryException e1) {
        // also not a datum, no further ideas, log error
        // swallow anything and return null instead
        LOG.info("No CRS or DATUM for given datum code >>{}<<: {}", datum, e1.getMessage());
      }
    }
  }
  return crs;
}
 
Example #21
Source File: CRSBuilder.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies if the user-defined CRS created from GeoTIFF values
 * matches the given CRS created from the EPSG geodetic dataset.
 * This method does not verify the EPSG code of the given CRS.
 *
 * @param  crs  the CRS created from the EPSG geodetic dataset.
 */
private void verify(final GeocentricCRS crs) throws FactoryException {
    /*
     * Note: current createUnit(…) implementation does not allow us to distinguish whether METRE ou DEGREE units
     * were specified in the GeoTIFF file or if we got the default values. We do not compare units of that reason.
     */
    final Unit<Length> linearUnit = createUnit(GeoKeys.GeogLinearUnits, GeoKeys.GeogLinearUnitSize, Length.class, Units.METRE);
    final Unit<Angle> angularUnit = createUnit(GeoKeys.AngularUnits, GeoKeys.AngularUnitSize, Angle.class, Units.DEGREE);
    final GeodeticDatum datum = crs.getDatum();
    verifyIdentifier(crs, datum, GeoKeys.GeodeticDatum);
    verify(datum, angularUnit, linearUnit);
}
 
Example #22
Source File: MathTransformContext.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new context which add some datum-related information in addition
 * to the information provided by the super-class.
 */
MathTransformContext(final GeodeticDatum source, final GeodeticDatum target) {
    final double rs = ReferencingUtilities.getGreenwichLongitude(source.getPrimeMeridian(), Units.DEGREE);
    final double rt = ReferencingUtilities.getGreenwichLongitude(target.getPrimeMeridian(), Units.DEGREE);
    if (rs != rt) {
        sourceMeridian = rs;
        targetMeridian = rt;
    }
}
 
Example #23
Source File: CRS.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the components of reduced CRS into the given list.
 * This method may invoke itself recursively for walking through compound CRS.
 *
 * @param  previous    number of dimensions of previous CRS.
 * @param  crs         the CRS for which to select components.
 * @param  dimension   number of dimensions of {@code crs}.
 * @param  selected    bitmask of dimensions to select.
 * @param  addTo       where to add CRS components.
 * @return new bitmask after removal of dimensions of the components added to {@code addTo}.
 */
private static long reduce(int previous, final CoordinateReferenceSystem crs, int dimension, long selected,
        final List<CoordinateReferenceSystem> addTo) throws FactoryException
{
    final long current = (Numerics.bitmask(dimension) - 1) << previous;
    final long intersect = selected & current;
    if (intersect != 0) {
        if (intersect == current) {
            addTo.add(crs);
            selected &= ~current;
        } else if (crs instanceof CompoundCRS) {
            for (final CoordinateReferenceSystem component : ((CompoundCRS) crs).getComponents()) {
                dimension = ReferencingUtilities.getDimension(component);
                selected = reduce(previous, component, dimension, selected, addTo);
                if ((selected & current) == 0) break;           // Stop if it would be useless to continue.
                previous += dimension;
            }
        } else if (dimension == 3 && crs instanceof SingleCRS) {
            final Datum datum = ((SingleCRS) crs).getDatum();
            if (datum instanceof GeodeticDatum) {
                final boolean isVertical = Long.bitCount(intersect) == 1;               // Presumed for now, verified later.
                final int verticalDimension = Long.numberOfTrailingZeros((isVertical ? intersect : ~intersect) >>> previous);
                final CoordinateSystemAxis verticalAxis = crs.getCoordinateSystem().getAxis(verticalDimension);
                if (AxisDirections.isVertical(verticalAxis.getDirection())) try {
                    addTo.add(new EllipsoidalHeightSeparator((GeodeticDatum) datum).separate((SingleCRS) crs, isVertical));
                    selected &= ~current;
                } catch (IllegalArgumentException | ClassCastException e) {
                    throw new FactoryException(Resources.format(Resources.Keys.CanNotSeparateCRS_1, crs.getName()));
                }
            }
        }
    }
    if ((selected & current) != 0) {
        throw new FactoryException(Resources.format(Resources.Keys.CanNotSeparateCRS_1, crs.getName()));
    }
    return selected;
}
 
Example #24
Source File: SubTypes.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a SIS implementation for the given datum.
 *
 * @see AbstractDatum#castOrCopy(Datum)
 */
static AbstractDatum castOrCopy(final Datum object) {
    if (object instanceof GeodeticDatum) {
        return DefaultGeodeticDatum.castOrCopy((GeodeticDatum) object);
    }
    if (object instanceof VerticalDatum) {
        return DefaultVerticalDatum.castOrCopy((VerticalDatum) object);
    }
    if (object instanceof TemporalDatum) {
        return DefaultTemporalDatum.castOrCopy((TemporalDatum) object);
    }
    if (object instanceof EngineeringDatum) {
        return DefaultEngineeringDatum.castOrCopy((EngineeringDatum) object);
    }
    if (object instanceof ImageDatum) {
        return DefaultImageDatum.castOrCopy((ImageDatum) object);
    }
    /*
     * Intentionally check for AbstractDatum after the interfaces because user may have defined his own
     * subclass implementing the interface. If we were checking for AbstractDatum 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 AbstractDatum) {
        return (AbstractDatum) object;
    }
    return new AbstractDatum(object);
}
 
Example #25
Source File: DefinitionVerifier.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a code indicating in which part the two given CRS differ. The given iterators usually iterate over
 * exactly one element, but may iterate over more elements if the CRS were instance of {@code CompoundCRS}.
 * The returned value is one of {@link #METHOD}, {@link #CONVERSION}, {@link #CS}, {@link #DATUM},
 * {@link #PRIME_MERIDIAN} or {@link #OTHER} constants.
 */
private static int diffCode(final Iterator<SingleCRS> authoritative, final Iterator<SingleCRS> given) {
    while (authoritative.hasNext() && given.hasNext()) {
        final SingleCRS crsA = authoritative.next();
        final SingleCRS crsG = given.next();
        if (!Utilities.equalsApproximately(crsA, crsG)) {
            if (crsA instanceof GeneralDerivedCRS && crsG instanceof GeneralDerivedCRS) {
                final Conversion cnvA = ((GeneralDerivedCRS) crsA).getConversionFromBase();
                final Conversion cnvG = ((GeneralDerivedCRS) crsG).getConversionFromBase();
                if (!Utilities.equalsApproximately(cnvA, cnvG)) {
                    return Utilities.equalsApproximately(cnvA.getMethod(), cnvG.getMethod()) ? CONVERSION : METHOD;
                }
            }
            if (!Utilities.equalsApproximately(crsA.getCoordinateSystem(), crsG.getCoordinateSystem())) {
                return CS;
            }
            final Datum datumA = crsA.getDatum();
            final Datum datumG = crsG.getDatum();
            if (!Utilities.equalsApproximately(datumA, datumG)) {
                if ((datumA instanceof GeodeticDatum) && (datumG instanceof GeodeticDatum) &&
                    !Utilities.equalsApproximately(((GeodeticDatum) datumA).getPrimeMeridian(),
                                                   ((GeodeticDatum) datumG).getPrimeMeridian()))
                {
                    return PRIME_MERIDIAN;
                }
                return DATUM;
            }
            break;
        }
    }
    return OTHER;
}
 
Example #26
Source File: WKTUtilities.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the given geodetic datum as a formattable object.
 *
 * @param  object  the datum, or {@code null}.
 * @return the given datum as a formattable object, or {@code null}.
 */
public static FormattableObject toFormattable(final GeodeticDatum object) {
    if (object instanceof FormattableObject) {
        return (FormattableObject) object;
    } else {
        return DefaultGeodeticDatum.castOrCopy(object);
    }
}
 
Example #27
Source File: DefaultGeocentricCRS.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * For {@link #createSameType(Map, CoordinateSystem)} usage only.
 * This constructor does not verify the coordinate system type.
 */
private DefaultGeocentricCRS(final Map<String,?>    properties,
                             final GeodeticDatum    datum,
                             final CoordinateSystem cs)
{
    super(properties, datum, cs);
}
 
Example #28
Source File: DefaultGeodeticCRS.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by JAXB at unmarshalling time.
 *
 * @see #getDatum()
 */
private void setDatum(final GeodeticDatum value) {
    if (datum == null) {
        datum = value;
    } else {
        MetadataUtilities.propertyAlreadySet(DefaultGeodeticCRS.class, "setDatum", "geodeticDatum");
    }
}
 
Example #29
Source File: DefaultGeodeticDatum.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the best parameters matching the given criteria, or {@code null} if none.
 */
private BursaWolfParameters select(final GeodeticDatum targetDatum, final ExtentSelector<BursaWolfParameters> selector) {
    if (bursaWolf == null) {
        return null;
    }
    for (final BursaWolfParameters candidate : bursaWolf) {
        if (deepEquals(targetDatum, candidate.getTargetDatum(), ComparisonMode.IGNORE_METADATA)) {
            selector.evaluate(candidate.getDomainOfValidity(), candidate);
        }
    }
    return selector.best();
}
 
Example #30
Source File: DefaultGeodeticDatum.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}