org.opengis.referencing.datum.Datum Java Examples

The following examples show how to use org.opengis.referencing.datum.Datum. 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: 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 #2
Source File: DefaultCoordinateOperationFactory.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
     * Returns {@code true} if the given CRS are using equivalent (ignoring metadata) datum.
     * If the CRS are {@link org.opengis.referencing.crs.CompoundCRS}, then this method verifies that
     * all datum in the target CRS exists in the source CRS, but not necessarily in the same order.
     * The target CRS may have less datum than the source CRS.
     *
     * @param  sourceCRS  the target CRS.
     * @param  targetCRS  the source CRS.
     * @return {@code true} if all datum in the {@code targetCRS} exists in the {@code sourceCRS}.
     */
    private static boolean isConversion(final CoordinateReferenceSystem sourceCRS,
                                        final CoordinateReferenceSystem targetCRS)
    {
        List<SingleCRS> components = CRS.getSingleComponents(sourceCRS);
        int n = components.size();                      // Number of remaining datum from sourceCRS to verify.
        final Datum[] datum = new Datum[n];
        for (int i=0; i<n; i++) {
            datum[i] = components.get(i).getDatum();
        }
        components = CRS.getSingleComponents(targetCRS);
next:   for (int i=components.size(); --i >= 0;) {
            final Datum d = components.get(i).getDatum();
            for (int j=n; --j >= 0;) {
                if (Utilities.equalsIgnoreMetadata(d, datum[j])) {
                    System.arraycopy(datum, j+1, datum, j, --n - j);    // Remove the datum from the list.
                    continue next;
                }
            }
            return false;                               // Datum from 'targetCRS' not found in 'sourceCRS'.
        }
        return true;
    }
 
Example #3
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 #4
Source File: AbstractCRS.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Compares this coordinate reference system with the specified object for equality.
 * If the {@code mode} argument value is {@link ComparisonMode#STRICT STRICT} or
 * {@link ComparisonMode#BY_CONTRACT BY_CONTRACT}, then all available properties are
 * compared including the {@linkplain #getDomainOfValidity() domain of validity} and
 * the {@linkplain #getScope() scope}.
 *
 * @param  object  the object to compare to {@code this}.
 * @param  mode    {@link ComparisonMode#STRICT STRICT} for performing a strict comparison, or
 *                 {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} for comparing only
 *                 properties relevant to coordinate transformations.
 * @return {@code true} if both objects are equal.
 */
@Override
public boolean equals(final Object object, final ComparisonMode mode) {
    if (super.equals(object, mode)) {
        final Datum datum = getDatum();
        switch (mode) {
            case STRICT: {
                final AbstractCRS that = (AbstractCRS) object;
                return Objects.equals(datum, that.getDatum()) &&
                       Objects.equals(coordinateSystem, that.coordinateSystem);
            }
            default: {
                return deepEquals(datum, (object instanceof SingleCRS) ? ((SingleCRS) object).getDatum() : null, mode) &&
                       deepEquals(getCoordinateSystem(), ((CoordinateReferenceSystem) object).getCoordinateSystem(), mode);
            }
        }
    }
    return false;
}
 
Example #5
Source File: Decoder.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new decoder.
 *
 * @param  geomlib    the library for geometric objects, or {@code null} for the default.
 * @param  listeners  where to send the warnings.
 */
protected Decoder(final GeometryLibrary geomlib, final StoreListeners listeners) {
    Objects.requireNonNull(listeners);
    this.geomlib      = geomlib;
    this.listeners    = listeners;
    this.nameFactory  = DefaultFactories.forBuildin(NameFactory.class, DefaultNameFactory.class);
    this.datumCache   = new Datum[CRSBuilder.DATUM_CACHE_SIZE];
    this.gridMapping  = new HashMap<>();
    localizationGrids = new HashMap<>();
}
 
Example #6
Source File: EPSGFactoryFallbackTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link EPSGFactoryFallback#getAuthorityCodes(Class)}.
 *
 * @throws FactoryException if the set of authority codes can not be fetched.
 */
@Test
public void testGetAuthorityCodes() throws FactoryException {
    assertSetEquals(Arrays.asList(StandardDefinitions.GREENWICH),
            EPSGFactoryFallback.INSTANCE.getAuthorityCodes(PrimeMeridian.class));
    assertSetEquals(Arrays.asList("7030", "7043", "7019", "7008", "7022", "7048"),
            EPSGFactoryFallback.INSTANCE.getAuthorityCodes(Ellipsoid.class));
    assertSetEquals(Arrays.asList("6326", "6322", "6269", "6267", "6258", "6230", "6019", "6047", "5100", "5103"),
            EPSGFactoryFallback.INSTANCE.getAuthorityCodes(Datum.class));
    assertSetEquals(Arrays.asList("6422", "6423"),
            EPSGFactoryFallback.INSTANCE.getAuthorityCodes(EllipsoidalCS.class));
    assertSetEquals(Arrays.asList("6404"),
            EPSGFactoryFallback.INSTANCE.getAuthorityCodes(SphericalCS.class));
    assertSetEquals(Arrays.asList("6500", "4400", "1026", "1027"),
            EPSGFactoryFallback.INSTANCE.getAuthorityCodes(CartesianCS.class));
    assertSetEquals(Arrays.asList("4978", "4984", "4936"),
            EPSGFactoryFallback.INSTANCE.getAuthorityCodes(GeocentricCRS.class));
    assertSetEquals(Arrays.asList("4326", "4322", "4019", "4047", "4269", "4267", "4258", "4230", "4979", "4985", "4937"),
            EPSGFactoryFallback.INSTANCE.getAuthorityCodes(GeographicCRS.class));
    assertSetEquals(Arrays.asList("5714", "5715", "5703"),
            EPSGFactoryFallback.INSTANCE.getAuthorityCodes(VerticalCRS.class));
    /*
     * There is too many ProjectedCRS codes for enumerating all of them, so test only a sampling.
     */
    final Set<String> codes = EPSGFactoryFallback.INSTANCE.getAuthorityCodes(ProjectedCRS.class);
    assertTrue(codes.containsAll(Arrays.asList("5041", "5042", "32601", "32660", "32701", "32760")));
    assertTrue(Collections.disjoint(codes, Arrays.asList("7030", "6326", "4326", "4978", "32600", "32700", "5714")));
}
 
Example #7
Source File: CommonAuthorityFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link CommonAuthorityFactory#getAuthorityCodes(Class)}.
 *
 * @throws FactoryException if an error occurred while fetching the set of codes.
 */
@Test
public void testGetAuthorityCodes() throws FactoryException {
    assertTrue("getAuthorityCodes(Datum.class)",
            factory.getAuthorityCodes(Datum.class).isEmpty());
    assertSetEquals(Arrays.asList("CRS:1", "CRS:27", "CRS:83", "CRS:84", "CRS:88",
                                  "AUTO2:42001", "AUTO2:42002", "AUTO2:42003", "AUTO2:42004", "AUTO2:42005"),
            factory.getAuthorityCodes(CoordinateReferenceSystem.class));
    assertSetEquals(Arrays.asList("AUTO2:42001", "AUTO2:42002", "AUTO2:42003", "AUTO2:42004", "AUTO2:42005"),
            factory.getAuthorityCodes(ProjectedCRS.class));
    assertSetEquals(Arrays.asList("CRS:27", "CRS:83", "CRS:84"),
            factory.getAuthorityCodes(GeographicCRS.class));
    assertSetEquals(Arrays.asList("CRS:88"),
            factory.getAuthorityCodes(VerticalCRS.class));
    assertSetEquals(Arrays.asList("CRS:1"),
            factory.getAuthorityCodes(EngineeringCRS.class));

    final Set<String> codes = factory.getAuthorityCodes(GeographicCRS.class);
    assertFalse("CRS:1",      codes.contains("CRS:1"));
    assertTrue ("CRS:27",     codes.contains("CRS:27"));
    assertTrue ("CRS:83",     codes.contains("CRS:83"));
    assertTrue ("CRS:84",     codes.contains("CRS:84"));
    assertFalse("CRS:88",     codes.contains("CRS:88"));
    assertTrue ("0084",       codes.contains("0084"));
    assertFalse("0088",       codes.contains("0088"));
    assertTrue ("OGC:CRS084", codes.contains("OGC:CRS084"));
}
 
Example #8
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 #9
Source File: Formatter.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Appends the anchor, scope and domain of validity of the given object. Those information are available
 * only for {@link ReferenceSystem}, {@link Datum} and {@link CoordinateOperation} objects.
 */
private void appendForSubtypes(final IdentifiedObject object) {
    final InternationalString anchor, scope;
    final Extent area;
    if (object instanceof ReferenceSystem) {
        anchor = null;
        scope  = ((ReferenceSystem) object).getScope();
        area   = ((ReferenceSystem) object).getDomainOfValidity();
    } else if (object instanceof Datum) {
        anchor = ((Datum) object).getAnchorPoint();
        scope  = ((Datum) object).getScope();
        area   = ((Datum) object).getDomainOfValidity();
    } else if (object instanceof CoordinateOperation) {
        anchor = null;
        scope  = ((CoordinateOperation) object).getScope();
        area   = ((CoordinateOperation) object).getDomainOfValidity();
    } else {
        return;
    }
    appendOnNewLine(WKTKeywords.Anchor, anchor, null);
    appendOnNewLine(WKTKeywords.Scope, scope, ElementKind.SCOPE);
    if (area != null) {
        appendOnNewLine(WKTKeywords.Area, area.getDescription(), ElementKind.EXTENT);
        append(Extents.getGeographicBoundingBox(area), BBOX_ACCURACY);
        appendVerticalExtent(Extents.getVerticalRange(area));
        appendTemporalExtent(Extents.getTimeRange(area));
    }
}
 
Example #10
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 #11
Source File: WKTUtilities.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the given 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 Datum object) {
    if (object instanceof FormattableObject) {
        return (FormattableObject) object;
    } else {
        return AbstractDatum.castOrCopy(object);
    }
}
 
Example #12
Source File: EPSGFactoryFallback.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the interface for the given {@code *_MASK} constant.
 * This is used for formatting error message only.
 */
private static Class<?> toClass(final int kind) {
    switch (kind) {
        case CRS:            return CoordinateReferenceSystem.class;
        case DATUM:          return Datum.class;
        case ELLIPSOID:      return Ellipsoid.class;
        case PRIME_MERIDIAN: return PrimeMeridian.class;
        case UNIT:           return Unit.class;
        case AXIS:           return CoordinateSystemAxis.class;
        case CS:             return CoordinateSystem.class;
        default:             return IdentifiedObject.class;
    }
}
 
Example #13
Source File: CrsUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if a crs is valid, i.e. if it is not a wildcard default one.
 * 
 * @param crs the crs to check.
 */
public static boolean isCrsValid( CoordinateReferenceSystem crs ) {
    if (crs instanceof AbstractSingleCRS) {
        AbstractSingleCRS aCrs = (AbstractSingleCRS) crs;
        Datum datum = aCrs.getDatum();
        ReferenceIdentifier name = datum.getName();
        String code = name.getCode();
        if (code.equalsIgnoreCase("Unknown")) {
            return false;
        }
    }
    return true;
}
 
Example #14
Source File: TypesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the {@link Types#getStandardName(Class)} method.
 */
@Test
public void testGetStandardName() {
    assertEquals("CI_Citation",      Types.getStandardName(Citation     .class));
    assertEquals("CD_Datum",         Types.getStandardName(Datum        .class));
    assertEquals("CS_AxisDirection", Types.getStandardName(AxisDirection.class));
}
 
Example #15
Source File: TypesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the {@link Types#forStandardName(String)} method.
 */
@Test
public void testForStandardName() {
    assertEquals(Citation     .class, Types.forStandardName("CI_Citation"));
    assertEquals(Datum        .class, Types.forStandardName("CD_Datum"));
    assertEquals(Citation     .class, Types.forStandardName("CI_Citation"));            // Value should be cached.
    assertEquals(Citation     .class, Types.forStandardName("Citation"));
    assertEquals(AxisDirection.class, Types.forStandardName("CS_AxisDirection"));
    assertNull  (                     Types.forStandardName("MD_Dummy"));
}
 
Example #16
Source File: DefaultConversion.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that the {@code actual} CRS uses a datum which is equals, ignoring metadata,
 * to the datum of the {@code expected} CRS.
 *
 * @param  param     the parameter name, used only in case of error.
 * @param  expected  the CRS containing the expected datum, or {@code null}.
 * @param  actual    the CRS for which to check the datum, or {@code null}.
 * @throws MismatchedDatumException if the two CRS use different datum.
 */
private static void ensureCompatibleDatum(final String param,
        final CoordinateReferenceSystem expected,
        final CoordinateReferenceSystem actual)
{
    if ((expected instanceof SingleCRS) && (actual instanceof SingleCRS)) {
        final Datum datum = ((SingleCRS) expected).getDatum();
        if (datum != null && !Utilities.equalsIgnoreMetadata(datum, ((SingleCRS) actual).getDatum())) {
            throw new MismatchedDatumException(Resources.format(
                    Resources.Keys.IncompatibleDatum_2, datum.getName(), param));
        }
    }
}
 
Example #17
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 #18
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 #19
Source File: SingleCrsImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
public Datum getDatum() {
	return base.getDatum();
}
 
Example #20
Source File: GeneralDerivedCrsImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
public Datum getDatum() {
	return base.getDatum();
}
 
Example #21
Source File: EPSGFactoryFallbackTest.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Asserts that the result of {@link EPSGFactoryFallback#createObject(String)} is the given datum.
 */
private static void verifyCreateDatum(final Datum expected, final String code) throws FactoryException {
    assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createDatum(code));
    assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createObject(code));
}
 
Example #22
Source File: SubTypes.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a SIS implementation for the given object.
 *
 * @see AbstractIdentifiedObject#castOrCopy(IdentifiedObject)
 */
static AbstractIdentifiedObject castOrCopy(final IdentifiedObject object) {
    if (object instanceof CoordinateReferenceSystem) {
        return AbstractCRS.castOrCopy((CoordinateReferenceSystem) object);
    }
    if (object instanceof CoordinateSystem) {
        return AbstractCS.castOrCopy((CoordinateSystem) object);
    }
    if (object instanceof CoordinateSystemAxis) {
        return DefaultCoordinateSystemAxis.castOrCopy((CoordinateSystemAxis) object);
    }
    if (object instanceof Datum) {
        return AbstractDatum.castOrCopy((Datum) object);
    }
    if (object instanceof Ellipsoid) {
        return DefaultEllipsoid.castOrCopy((Ellipsoid) object);
    }
    if (object instanceof PrimeMeridian) {
        return DefaultPrimeMeridian.castOrCopy((PrimeMeridian) object);
    }
    if (object instanceof CoordinateOperation) {
        return AbstractCoordinateOperation.castOrCopy((CoordinateOperation) object);
    }
    if (object instanceof OperationMethod) {
        return DefaultOperationMethod.castOrCopy((OperationMethod) object);
    }
    if (object instanceof ParameterDescriptor<?>) {
        return DefaultParameterDescriptor.castOrCopy((ParameterDescriptor<?>) object);
    }
    if (object instanceof ParameterDescriptorGroup) {
        return DefaultParameterDescriptorGroup.castOrCopy((ParameterDescriptorGroup) object);
    }
    /*
     * Intentionally check for AbstractIdentifiedObject after the interfaces because user may have defined his own
     * subclass implementing the interface. If we were checking for AbstractIdentifiedObject 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 AbstractIdentifiedObject) {
        return (AbstractIdentifiedObject) object;
    }
    return new AbstractIdentifiedObject(object);
}
 
Example #23
Source File: EPSGFactoryFallback.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a datum for the given EPSG code.
 */
@Override
public Datum createDatum(final String code) throws NoSuchAuthorityCodeException {
    return (Datum) predefined(code, DATUM);
}
 
Example #24
Source File: DefaultCompoundCRS.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Compound CRS do not have datum.
 */
@Override
final Datum getDatum() {
    return null;
}
 
Example #25
Source File: AbstractDatum.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new datum 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  datum  the datum to copy.
 */
protected AbstractDatum(final Datum datum) {
    super(datum);
    realizationEpoch = MetadataUtilities.toMilliseconds(datum.getRealizationEpoch());
    domainOfValidity = datum.getDomainOfValidity();
    scope            = datum.getScope();
    anchorDefinition = datum.getAnchorPoint();
}
 
Example #26
Source File: ServicesForMetadata.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a parametric CRS. This method requires the SIS factory
 * since parametric CRS were not available in GeoAPI 3.0.
 *
 * <p>This method is actually not needed anymore for {@code sis-metadata} module,
 * but is still defined here for historical reason. This method is removed on SIS
 * branches using a GeoAPI versions more recent than 3.0.</p>
 *
 * @param  properties  the coordinate reference system name, and optionally other properties.
 * @param  datum       the parametric datum.
 * @param  cs          the parametric coordinate system.
 * @param  factory     the factory to use for creating the coordinate reference system.
 * @return a parametric coordinate system using the given axes.
 * @throws FactoryException if the parametric object creation failed.
 *
 * @since 0.7
 */
public static SingleCRS createParametricCRS(final Map<String,?> properties, final Datum datum,
        final CoordinateSystem cs, CRSFactory factory) throws FactoryException
{
    if (!(factory instanceof GeodeticObjectFactory)) {
        factory = DefaultFactories.forBuildin(CRSFactory.class, GeodeticObjectFactory.class);
    }
    try {
        return ((GeodeticObjectFactory) factory).createParametricCRS(properties,
                (DefaultParametricDatum) datum, (DefaultParametricCS) cs);
    } catch (ClassCastException e) {
        throw new InvalidGeodeticParameterException(e.toString(), e);
    }
}
 
Example #27
Source File: ServicesForMetadata.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a parametric datum. This method requires the SIS factory
 * since parametric CRS were not available in GeoAPI 3.0.
 *
 * <p>This method is actually not needed anymore for {@code sis-metadata} module,
 * but is still defined here for historical reason. This method is removed on SIS
 * branches using a GeoAPI versions more recent than 3.0.</p>
 *
 * @param  properties  the datum name, and optionally other properties.
 * @param  factory     the factory to use for creating the datum.
 * @return a parametric datum using the given name.
 * @throws FactoryException if the parametric object creation failed.
 *
 * @since 0.7
 */
public static Datum createParametricDatum(final Map<String,?> properties, DatumFactory factory)
        throws FactoryException
{
    if (!(factory instanceof GeodeticObjectFactory)) {
        factory = DefaultFactories.forBuildin(DatumFactory.class, GeodeticObjectFactory.class);
    }
    return ((GeodeticObjectFactory) factory).createParametricDatum(properties);
}
 
Example #28
Source File: AbstractCRS.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the datum, or {@code null} if none.
 *
 * This property does not exist in {@code CoordinateReferenceSystem} interface — it is defined in the
 * {@link SingleCRS} sub-interface instead. But Apache SIS does not define an {@code AbstractSingleCRS} class
 * in order to simplify our class hierarchy, so we provide a datum getter in this class has a hidden property.
 * Subclasses implementing {@code SingleCRS} (basically all SIS subclasses except {@link DefaultCompoundCRS})
 * will override this method with public access and more specific return type.
 *
 * @return the datum, or {@code null} if none.
 */
Datum getDatum() {
    /*
     * User could provide his own CRS implementation outside this SIS package, so we have
     * to check for SingleCRS interface. But all SIS classes override this implementation.
     */
    return (this instanceof SingleCRS) ? ((SingleCRS) this).getDatum() : null;
}
 
Example #29
Source File: AbstractDatum.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a SIS datum implementation with the values of the given arbitrary implementation.
 * This method performs the first applicable action in the following choices:
 *
 * <ul>
 *   <li>If the given object is {@code null}, then this method returns {@code null}.</li>
 *   <li>Otherwise if the given object is an instance of
 *       {@link org.opengis.referencing.datum.GeodeticDatum},
 *       {@link org.opengis.referencing.datum.VerticalDatum},
 *       {@link org.opengis.referencing.datum.TemporalDatum},
 *       {@link org.opengis.referencing.datum.EngineeringDatum} or
 *       {@link org.opengis.referencing.datum.ImageDatum},
 *       then this method delegates to the {@code castOrCopy(…)} method of the corresponding SIS subclass.
 *       Note that if the given object implements more than one of the above-cited interfaces,
 *       then the {@code castOrCopy(…)} method to be used is unspecified.</li>
 *   <li>Otherwise if the given object is already an instance of
 *       {@code AbstractDatum}, then it is returned unchanged.</li>
 *   <li>Otherwise a new {@code AbstractDatum} instance is created using the
 *       {@linkplain #AbstractDatum(Datum) copy constructor}
 *       and returned. Note that this is a <cite>shallow</cite> copy operation, since the other
 *       properties contained in the given object are not recursively copied.</li>
 * </ul>
 *
 * @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 AbstractDatum castOrCopy(final Datum object) {
    return SubTypes.castOrCopy(object);
}
 
Example #30
Source File: AbstractDatum.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the GeoAPI interface implemented by this class.
 * The default implementation returns {@code Datum.class}.
 * Subclasses implementing a more specific GeoAPI interface shall override this method.
 *
 * @return the datum interface implemented by this class.
 */
@Override
public Class<? extends Datum> getInterface() {
    return Datum.class;
}