/** * Quickly review provided crs checking for an "EPSG:SRID" reference identifier. * * <p> * * @see CRS#lookupEpsgCode(CoordinateReferenceSystem, boolean) for full search * @param crs * @return srid or -1 if not found */ private static int toSRID(CoordinateReferenceSystem crs) { if (crs == null || crs.getIdentifiers() == null) { return -1; // not found } for (Iterator<ReferenceIdentifier> it = crs.getIdentifiers().iterator(); it.hasNext(); ) { ReferenceIdentifier id = it.next(); Citation authority = id.getAuthority(); if (authority != null && authority.getTitle().equals(Citations.EPSG.getTitle())) { try { return Integer.parseInt(id.getCode()); } catch (NumberFormatException nanException) { continue; } } } return -1; }
ReferenceIdentifier id = it.next(); if ((id.getAuthority() != null) && id.getAuthority().getTitle().equals(Citations.EPSG.getTitle())) { buf.append(":srid=" + id.getCode()); break;
/** Implementation of {@link #getIdentifier(Citation)}. */ private static ReferenceIdentifier getIdentifier0( final IdentifiedObject info, final Citation authority) { if (info == null) { return null; } for (final Identifier candidate : info.getIdentifiers()) { if (candidate instanceof ReferenceIdentifier) { final ReferenceIdentifier identifier = (ReferenceIdentifier) candidate; if (authority == null) { return identifier; } final Citation infoAuthority = identifier.getAuthority(); if (infoAuthority != null) { if (Citations.identifierMatches(authority, infoAuthority)) { return identifier; } } } } return (authority == null) ? info.getName() : null; }
/** * Returns the properties to be given to an object replacing an original one. If the new object * keep the same authority, then all metadata are preserved. Otherwise (i.e. if a new authority * is given to the new object), then the old identifiers will be removed from the new object * metadata. * * @param object The original object. * @return The properties to be given to the object created as a substitute of {@code object}. */ private Map<String, ?> getProperties(final IdentifiedObject object) { final Citation authority = getAuthority(); if (!Utilities.equals(authority, object.getName().getAuthority())) { return AbstractIdentifiedObject.getProperties(object, authority); } else { return AbstractIdentifiedObject.getProperties(object); } }
@Test public void testIdentifier() throws NoSuchAuthorityCodeException, FactoryException { Set<ReferenceIdentifier> identifiers = CartesianAuthorityFactory.GENERIC_2D.getIdentifiers(); assertEquals(1, identifiers.size()); final ReferenceIdentifier id = identifiers.iterator().next(); assertEquals(Citations.EPSG, id.getAuthority()); assertEquals(CODE, id.getCode()); }
String name = getName(param, group.getDescriptor().getName().getAuthority()); if (name == null) { name = param.getName().getCode();
/** * Ensures that the given identifier has a {@linkplain ReferenceIdentifier#getCode code}. * * @param object The object to validate, or {@code null}. */ public void validate(final ReferenceIdentifier object) { if (object == null) { return; } mandatory("ReferenceIdentifier: must have a code.", object.getCode()); container.citation.validate(object.getAuthority()); }
/** * Quickly review provided crs checking for an "EPSG:SRID" reference identifier. * <p> * @see CRS#lookupEpsgCode(CoordinateReferenceSystem, boolean) for full search * @param crs * @return srid or -1 if not found */ private static int toSRID( CoordinateReferenceSystem crs ){ if (crs == null || crs.getIdentifiers() == null) { return -1; // not found } for (Iterator<ReferenceIdentifier> it = crs.getIdentifiers().iterator(); it .hasNext();) { ReferenceIdentifier id = it.next(); Citation authority = id.getAuthority(); if (authority != null && authority.getTitle().equals(Citations.EPSG.getTitle())) { try { return Integer.parseInt( id.getCode() ); } catch (NumberFormatException nanException ){ continue; } } } return -1; }
/** * Returns a pseudo-WKT representation. */ @Override public String toString() { final String code, codespace; final Citation authority; final ReferenceIdentifier id = referenceSystemIdentifier; if (id != null) { code = id.getCode(); codespace = id.getCodeSpace(); authority = id.getAuthority(); } else { code = null; codespace = null; authority = null; } return toString("RS", authority, codespace, code, false); }
/** * Formats the given object. */ @Override public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos) { final ReferenceIdentifier identifier = ((IdentifiedObject) obj).getName(); if (identifier == null) { return toAppendTo.append(Vocabulary.getResources(locale).getString(Vocabulary.Keys.Unnamed)); } if (identifier instanceof GenericName) { // The toString() behavior is specified by the GenericName javadoc. return toAppendTo.append(((GenericName) identifier).toInternationalString().toString(locale)); } final String code = identifier.getCode(); String cs = identifier.getCodeSpace(); if (cs == null || cs.isEmpty()) { cs = Citations.getIdentifier(identifier.getAuthority(), true); } if (cs != null) { toAppendTo.append(cs).append(DefaultNameSpace.DEFAULT_SEPARATOR); } return toAppendTo.append(code); }
/** * Formats the given object. */ @Override public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos) { final ReferenceIdentifier identifier = ((IdentifiedObject) obj).getName(); if (identifier == null) { return toAppendTo.append(Vocabulary.getResources(locale).getString(Vocabulary.Keys.Unnamed)); } if (identifier instanceof GenericName) { // The toString() behavior is specified by the GenericName javadoc. return toAppendTo.append(((GenericName) identifier).toInternationalString().toString(locale)); } final String code = identifier.getCode(); String cs = identifier.getCodeSpace(); if (cs == null || cs.isEmpty()) { cs = Citations.getIdentifier(identifier.getAuthority(), true); } if (cs != null) { toAppendTo.append(cs).append(Citations.DEFAULT_SEPARATOR); } return toAppendTo.append(code); }
"Authority", author, parameters.getName().getAuthority().getTitle().toString()); assertEquals("Vendor", vendor, alias.scope().name().toString()); assertNotNull("Version", parameters.getName().getVersion());
/** * Creates a new identifier from the specified one. This is a copy constructor * which will get the code, codespace, authority, version and (if available) * the remarks from the given identifier. * * @param identifier The identifier to copy. */ public DefaultReferenceIdentifier(final ReferenceIdentifier identifier) { ensureNonNull("identifier", identifier); code = identifier.getCode(); codeSpace = identifier.getCodeSpace(); authority = identifier.getAuthority(); version = identifier.getVersion(); if (identifier instanceof DefaultReferenceIdentifier) { remarks = ((DefaultReferenceIdentifier) identifier).getRemarks(); } else { remarks = null; } }
/** * Creates a new identifier from the specified one. This is a copy constructor which * get the code, codespace, authority and version from the given identifier. * * @param identifier the identifier to copy. */ public ImmutableIdentifier(final ReferenceIdentifier identifier) { ensureNonNull("identifier", identifier); code = identifier.getCode(); codeSpace = identifier.getCodeSpace(); authority = identifier.getAuthority(); version = identifier.getVersion(); if (identifier instanceof DefaultIdentifier) { description = ((DefaultIdentifier) identifier).getDescription(); } else { description = null; } validate(null); }
/** * Creates a new identifier from the specified one. This is a copy constructor which * get the code, codespace, authority and version from the given identifier. * * @param identifier the identifier to copy. * * @see #castOrCopy(ReferenceIdentifier) */ public ImmutableIdentifier(final ReferenceIdentifier identifier) { ensureNonNull("identifier", identifier); code = identifier.getCode(); codeSpace = identifier.getCodeSpace(); authority = identifier.getAuthority(); version = identifier.getVersion(); if (identifier instanceof DefaultIdentifier) { description = ((DefaultIdentifier) identifier).getDescription(); } else { description = null; } validate(null); }
/** * Asserts that the given identifier has the expected code and the {@code "OGC"} code space. * The authority is expected to be {@link Citations#OGC}. We expect the exact same authority * instance because identifiers in OGC namespace are often hard-coded in SIS. * * @param expected the expected identifier code. * @param actual the identifier to verify. * * @since 0.6 */ public static void assertOgcIdentifierEquals(final String expected, final ReferenceIdentifier actual) { assertNotNull(actual); assertEquals("code", expected, actual.getCode()); assertEquals("codeSpace", Constants.OGC, actual.getCodeSpace()); assertSame ("authority", Citations.OGC, actual.getAuthority()); assertEquals("identifier", Constants.OGC + DefaultNameSpace.DEFAULT_SEPARATOR + expected, IdentifiedObjects.toString(actual)); }
/** * Asserts that the primary name of the given parameter is the given name in the EPSG namespace. * Then asserts that the first alias (ignoring other EPSG alias) of the given parameter is the * given name in the OGC namespace. */ private static void assertParamEquals(final String epsgName, final String ogcName, final boolean isMandatory, final GeneralParameterDescriptor actual) { if (epsgName != null) { assertEpsgIdentifierEquals(epsgName, actual.getName()); } else { assertOgcIdentifierEquals(ogcName, actual.getName()); } assertEquals("minimumOccurs", isMandatory ? 1 : 0, actual.getMinimumOccurs()); if (epsgName != null) { for (final GenericName alias : actual.getAlias()) { if (alias instanceof ReferenceIdentifier && ((ReferenceIdentifier) alias).getAuthority() != Citations.EPSG) { assertOgcIdentifierEquals(ogcName, (ReferenceIdentifier) alias); return; } } fail("OGC alias not found."); } }
/** * 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()); } }
/** * Tests the {@link Code#Code(ReferenceIdentifier)} constructor with {@code "EPSG:4326"} identifier. * This test intentionally uses an identifier with the {@code IOGP} authority instead than * EPSG in order to make sure that the {@code codeSpace} attribute is set from * {@code Identifier.getCodeSpace()}, not from {@code Identifier.getAuthority()}. */ @Test public void testSimple() { final SimpleCitation IOGP = new SimpleCitation("IOGP"); final ReferenceIdentifier id = new ImmutableIdentifier(IOGP, "EPSG", "4326"); // See above javadoc. final Code value = new Code(id); assertEquals("codeSpace", "EPSG", value.codeSpace); assertEquals("code", "4326", value.code); /* * Reverse operation. Note that the authority is lost since there is no room for that in a * <gml:identifier> element. Current implementation sets the authority to the code space. */ final ReferenceIdentifier actual = value.getIdentifier(); assertSame ("authority", Citations.EPSG, actual.getAuthority()); assertEquals("codeSpace", "EPSG", actual.getCodeSpace()); assertNull ("version", actual.getVersion()); assertEquals("code", "4326", actual.getCode()); }
/** * Tests the {@link Code#Code(ReferenceIdentifier)} constructor with {@code "EPSG:8.3:4326"} identifier. * This test intentionally uses an identifier with the {@code IOGP} authority instead than EPSG * for the same reason than {@link #testSimple()}. */ @Test @DependsOnMethod("testSimple") public void testWithVersion() { final SimpleCitation IOGP = new SimpleCitation("IOGP"); final ReferenceIdentifier id = new ImmutableIdentifier(IOGP, "EPSG", "4326", "8.2", null); // See above javadoc. final Code value = new Code(id); assertEquals("codeSpace", "EPSG:8.2", value.codeSpace); assertEquals("code", "4326", value.code); /* * Reverse operation. Note that the authority is lost since there is no room for that in a * <gml:identifier> element. Current implementation sets the authority to the code space. */ 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()); }