Search in sources :

Example 31 with ReferenceIdentifier

use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.

the class CodeTest method testLegacyCodeSpace.

/**
 * Tests {@link Code#forIdentifiedObject(Class, Iterable)} with the legacy "OGP" codespace
 * (instead of "IOGP").
 */
@Test
@DependsOnMethod("testForIdentifiedObject")
public void testLegacyCodeSpace() {
    final DefaultCitation authority = new DefaultCitation("EPSG");
    authority.getIdentifiers().add(new ImmutableIdentifier(null, "OGP", "EPSG"));
    final ReferenceIdentifier id = new ImmutableIdentifier(authority, "EPSG", "4326", "8.2", null);
    final Code value = Code.forIdentifiedObject(GeographicCRS.class, Collections.singleton(id));
    assertNotNull(value);
    assertEquals("codeSpace", "OGP", value.codeSpace);
    assertEquals("code", "urn:ogc:def:crs:EPSG:8.2:4326", value.code);
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 32 with ReferenceIdentifier

use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.

the class CodeTest method testGetIdentifier.

/**
 * Tests {@link Code#getIdentifier()} with {@code "urn:ogc:def:crs:EPSG:8.2:4326"}.
 * This test simulates the {@code Code} object state that we get after XML unmarshalling
 * of an object from the EPSG registry.
 */
@Test
@DependsOnMethod("testForIdentifiedObject")
public void testGetIdentifier() {
    final Code value = new Code();
    value.codeSpace = "OGP";
    value.code = "urn:ogc:def:crs:EPSG:8.2:4326";
    final ReferenceIdentifier actual = value.getIdentifier();
    assertSame("authority", Citations.EPSG, actual.getAuthority());
    assertEquals("codeSpace", "EPSG", actual.getCodeSpace());
    assertEquals("version", "8.2", actual.getVersion());
    assertEquals("code", "4326", actual.getCode());
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 33 with ReferenceIdentifier

use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.

the class CoordinateOperationRegistryTest method assertEpsgNameWithoutIdentifierEqual.

/**
 * Asserts that the given object has the expected name but no identifier. This method is used when the given object
 * has been modified compared to the object declared in the EPSG dataset, for example with a change of axis order
 * or the addition of height. In such case the modified object is not allowed to have the EPSG identifier of the
 * original object.
 *
 * @param  name    the expected EPSG name.
 * @param  object  the object to verify.
 */
private static void assertEpsgNameWithoutIdentifierEqual(final String name, final IdentifiedObject object) {
    assertNotNull(name, object);
    assertEquals("name", name, object.getName().getCode());
    for (final ReferenceIdentifier id : object.getIdentifiers()) {
        assertFalse("EPSG identifier not allowed for modified objects.", "EPSG".equalsIgnoreCase(id.getCodeSpace()));
    }
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier)

Example 34 with ReferenceIdentifier

use of org.opengis.referencing.ReferenceIdentifier in project hale by halestudio.

the class CRSDefinitionUtil method createDefinition.

/**
 * Create a {@link CRSDefinition} from an existing coordinate reference
 * system.
 *
 * @param crs the coordinate reference system
 * @param cache the cache for CRS resolving
 * @return the CRS definition
 */
public static CRSDefinition createDefinition(CoordinateReferenceSystem crs, @Nullable CRSResolveCache cache) {
    ReferenceIdentifier name = crs.getName();
    // try to find CRS in EPSG DB
    CRSDefinition def;
    if (cache != null) {
        def = cache.resolveCRS(crs);
    } else {
        def = lookupCrs(crs);
    }
    if (def != null) {
        return def;
    }
    // try by code
    if (name != null) {
        String code = name.getCode();
        if (code != null && !code.isEmpty()) {
            // try decoding
            try {
                boolean lonFirst = (CRS.getAxisOrder(crs) == AxisOrder.EAST_NORTH);
                crs = CRS.decode(code, lonFirst);
                return new CodeDefinition(code, crs);
            } catch (Exception e) {
            // ignore
            }
        }
    }
    // use WKT
    return new WKTDefinition(crs.toWKT(), crs);
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) CodeDefinition(eu.esdihumboldt.hale.common.instance.geometry.impl.CodeDefinition) WKTDefinition(eu.esdihumboldt.hale.common.instance.geometry.impl.WKTDefinition) FactoryException(org.opengis.referencing.FactoryException)

Example 35 with ReferenceIdentifier

use of org.opengis.referencing.ReferenceIdentifier in project sldeditor by robward-scisys.

the class CoordManager method getCRSCode.

/**
 * Gets the CRS code.
 *
 * @param coordinateReferenceSystem the coordinate reference system
 * @return the CRS code
 */
public String getCRSCode(CoordinateReferenceSystem coordinateReferenceSystem) {
    ReferenceIdentifier identifier = null;
    if (coordinateReferenceSystem != null) {
        Set<ReferenceIdentifier> indentifierList = coordinateReferenceSystem.getIdentifiers();
        if ((indentifierList != null) && indentifierList.iterator().hasNext()) {
            identifier = indentifierList.iterator().next();
        }
    }
    String code = NOT_SET_CRS;
    if (identifier != null) {
        ValueComboBoxData data = crsMap.get(identifier.toString());
        if (data != null) {
            code = data.getKey();
        }
    }
    return code;
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData)

Aggregations

ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)35 Test (org.junit.Test)12 DependsOnMethod (org.apache.sis.test.DependsOnMethod)8 Identifier (org.opengis.metadata.Identifier)8 GenericName (org.opengis.util.GenericName)8 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)6 InternationalString (org.opengis.util.InternationalString)5 Citation (org.opengis.metadata.citation.Citation)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 SimpleCitation (org.apache.sis.internal.simple.SimpleCitation)2 FactoryException (org.opengis.referencing.FactoryException)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)1 CodeDefinition (eu.esdihumboldt.hale.common.instance.geometry.impl.CodeDefinition)1 WKTDefinition (eu.esdihumboldt.hale.common.instance.geometry.impl.WKTDefinition)1 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Code (org.apache.sis.internal.jaxb.referencing.Code)1