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);
}
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());
}
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()));
}
}
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);
}
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;
}
Aggregations