org.opengis.referencing.crs.CRSAuthorityFactory Java Examples

The following examples show how to use org.opengis.referencing.crs.CRSAuthorityFactory. 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: AuthorityFactoriesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests creation of {@code EPSG:4326} from codes for various versions of the EPSG database.
 * This test verifies the logged messages.
 *
 * @throws FactoryException if an EPSG:4326 creation failed.
 */
@Test
public void testVersionedEPSG() throws FactoryException {
    final CRSAuthorityFactory factory = AuthorityFactories.ALL;
    final GeographicCRS crs = factory.createGeographicCRS("EPSG:4326");
    loggings.assertNoUnexpectedLog();

    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:6.11.2:4326"));
    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:6.11.2:4326"));
    loggings.assertNextLogContains("6.11.2");
    loggings.assertNoUnexpectedLog();

    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:7.04:4326"));
    loggings.assertNextLogContains("7.04");
    loggings.assertNoUnexpectedLog();

    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG:7.10:4326"));
    loggings.assertNextLogContains("7.10");
    loggings.assertNoUnexpectedLog();

    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:EPSG::4326"));
    loggings.assertNoUnexpectedLog();
}
 
Example #2
Source File: AuthorityFactoriesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests creation of {@code CRS:84} from various codes.
 *
 * @throws FactoryException if a CRS:84 creation failed.
 */
@Test
public void testCRS84() throws FactoryException {
    final CRSAuthorityFactory factory = AuthorityFactories.ALL;
    final GeographicCRS crs = factory.createGeographicCRS("CRS:84");
    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:CRS::84"));
    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:CRS:1.3:84"));
    assertSame(crs, factory.createGeographicCRS("URN:OGC:DEF:CRS:CRS:1.3:84"));
    assertSame(crs, factory.createGeographicCRS("URN:OGC:DEF:CRS:CRS::84"));
    assertSame(crs, factory.createGeographicCRS("urn:x-ogc:def:crs:CRS:1.3:84"));
    assertSame(crs, factory.createGeographicCRS("urn:ogc:def:crs:OGC:1.3:CRS84"));

    // Following are just wrappers for above factory.
    assertSame(crs, CRS.forCode("urn:ogc:def:crs:CRS:1.3:84"));
    assertSame(crs, CRS.forCode("urn:ogc:def:crs:OGC:1.3:CRS84"));
    assertSame(crs, CRS.forCode("CRS:84"));
    assertSame(crs, CRS.forCode("OGC:CRS84"));

    assertNotDeepEquals(crs, CRS.forCode("CRS:83"));
}
 
Example #3
Source File: MTFactory.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the given Well Known Text (version 1) into a math transform.
 */
@Override
public synchronized MathTransform createFromWKT(final String wkt) throws FactoryException {
    ArgumentChecks.ensureNonEmpty("wkt", wkt);
    if (parser == null) {
        parser = new WKTFormat(null, null);
        parser.setFactory(CRSAuthorityFactory.class, this);
        parser.setFactory(MathTransformFactory.class, this);
        parser.setFactory(CoordinateOperationFactory.class, this);
    }
    try {
        return (MathTransform) parser.parseObject(wkt);
    } catch (ParseException | ClassCastException e) {
        throw new FactoryException(e);
    }
}
 
Example #4
Source File: AuthorityFactoriesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures that {@link EPSGFactoryProxy} is declared before {@link CommonAuthorityFactory}.
 * This is preferable (but not mandatory) because of the way we implemented {@link AuthorityFactories}.
 */
@Test
public void testFactoryOrder() {
    boolean foundProxy  = false;
    boolean foundCommon = false;
    for (CRSAuthorityFactory factory : ServiceLoader.load(CRSAuthorityFactory.class, AuthorityFactories.class.getClassLoader())) {
        if (factory instanceof CommonAuthorityFactory) {
            foundCommon = true;
            assertTrue("Should not have found EPSGFactoryProxy after CommonAuthorityFactory.", foundProxy);
        }
        if (factory instanceof EPSGFactoryProxy) {
            foundProxy = true;
            assertFalse("Should not have found EPSGFactoryProxy after CommonAuthorityFactory.", foundCommon);
        }
    }
    assertTrue("Factory not found.", foundCommon);
    assertTrue("Factory not found.", foundProxy);
}
 
Example #5
Source File: ReferencingFactoryContainer.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the factory for creating datum from authority codes.
 * Currently only EPSG codes are supported.
 *
 * @return the Datum authority factory (never {@code null}).
 * @throws FactoryException if the authority factory can not be obtained.
 */
public final DatumAuthorityFactory getDatumAuthorityFactory() throws FactoryException {
    final CRSAuthorityFactory factory = getCRSAuthorityFactory();
    if (factory instanceof DatumAuthorityFactory) {                 // This is the case for SIS implementation.
        return (DatumAuthorityFactory) factory;
    }
    throw new NoSuchAuthorityFactoryException(null, Constants.EPSG);
}
 
Example #6
Source File: CoordinateOperationMethods.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * For each {@link OperationMethod} (identified by their name), computes the union of the domain of validity
 * of all CRS using that operation method. The result is a map where keys are {@link OperationMethod} names,
 * and values are the union of the domain of validity of all CRS using that {@code OperationMethod}.
 *
 * <p>This is a costly operation.</p>
 *
 * @todo This method is not yet used. This is pending the implementation of {@code CRSAuthorityFactory} is SIS.
 *
 * @param  factory  the factory to use for getting CRS.
 * @return the union of domain of validity of all map projections using a method of the given name.
 * @throws FactoryException if an error occurred while fetching the list of CRS.
 */
public static Map<String, DefaultGeographicBoundingBox> computeUnionOfAllDomainOfValidity(
        final CRSAuthorityFactory factory) throws FactoryException
{
    final Map<String, DefaultGeographicBoundingBox> domainOfValidity = new HashMap<>();
    for (final String code : factory.getAuthorityCodes(GeneralDerivedCRS.class)) {
        final CoordinateReferenceSystem crs;
        try {
            crs = factory.createCoordinateReferenceSystem(code);
        } catch (FactoryException e) {
            continue;                                                   // Ignore and inspect the next element.
        }
        if (crs instanceof GeneralDerivedCRS) {
            final GeographicBoundingBox candidate = CRS.getGeographicBoundingBox(crs);
            if (candidate != null) {
                final String name = ((GeneralDerivedCRS) crs).getConversionFromBase().getMethod().getName().getCode();
                DefaultGeographicBoundingBox validity = domainOfValidity.get(name);
                if (validity == null) {
                    validity = new DefaultGeographicBoundingBox(candidate);
                    domainOfValidity.put(name, validity);
                } else {
                    validity.add(candidate);
                }
            }
        }
    }
    return domainOfValidity;
}
 
Example #7
Source File: AuthorityFactoriesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the {@code IdentifiedObjectFinder.find(…)} method.
 *
 * @throws FactoryException if the operation failed creation failed.
 */
@Test
public void testFind() throws FactoryException {
    final CRSAuthorityFactory factory = AuthorityFactories.ALL;
    final IdentifiedObjectFinder finder = AuthorityFactories.ALL.newIdentifiedObjectFinder();
    final IdentifiedObject find = finder.findSingleton(HardCodedCRS.WGS84);
    assertNotNull("With scan allowed, should find the CRS.", find);
    assertTrue(HardCodedCRS.WGS84.equals(find, ComparisonMode.DEBUG));
    assertSame(factory.createCoordinateReferenceSystem("CRS:84"), find);
}
 
Example #8
Source File: AuthorityFactoriesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the {@code getAuthorityCodes(…)} method.
 *
 * @throws FactoryException if an error occurred while fetching the codes.
 */
@Test
public void testGetAuthorityCodes() throws FactoryException {
    final CRSAuthorityFactory factory = AuthorityFactories.ALL;
    final Collection<String> codes = factory.getAuthorityCodes(CoordinateReferenceSystem.class);
    assertFalse(codes.isEmpty());
    assertTrue(codes.contains("CRS:84"));
    assertTrue(codes.contains("AUTO:42001") || codes.contains("AUTO2:42001"));
}
 
Example #9
Source File: TestFactorySource.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the system-wide EPSG factory, or interrupts the tests with {@link org.junit.Assume}
 * if the EPSG factory is not available. Note that this method breaks isolation between tests.
 * For more isolated tests, use {@link #createFactory()} and {@link #close()} instead.
 *
 * @return the system-wide EPSG factory.
 * @throws FactoryException if an error occurred while fetching the factory.
 */
public static synchronized EPSGFactory getSharedFactory() throws FactoryException {
    assumeFalse("No connection to EPSG dataset.", isUnavailable);
    final CRSAuthorityFactory factory = CRS.getAuthorityFactory(Constants.EPSG);
    assumeTrue("No connection to EPSG dataset.", factory instanceof EPSGFactory);
    try {
        assertNotNull(factory.createGeographicCRS("4326"));
    } catch (UnavailableFactoryException e) {
        isUnavailable = true;
        Logging.getLogger(Loggers.CRS_FACTORY).warning(e.toString());
        assumeNoException("No connection to EPSG dataset.", e);
    }
    return (EPSGFactory) factory;
}
 
Example #10
Source File: MultiAuthoritiesFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link MultiAuthoritiesFactory#getAuthorityFactory(Class, String, String)}
 * with a conflict in the factory namespace.
 *
 * @throws NoSuchAuthorityFactoryException if an authority is not recognized.
 */
@Test
@DependsOnMethod("testGetAuthorityFactory")
public void testConflict() throws NoSuchAuthorityFactoryException {
    final AuthorityFactoryMock mock1 = new AuthorityFactoryMock("MOCK1", "2.3");
    final AuthorityFactoryMock mock2 = new AuthorityFactoryMock("MOCK1", "2.3");
    final AuthorityFactoryMock mock3 = new AuthorityFactoryMock("MOCK3", "1.2");
    final AuthorityFactoryMock mock4 = new AuthorityFactoryMock("MOCK3", null);
    final AuthorityFactoryMock mock5 = new AuthorityFactoryMock("MOCK5", null);
    final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(
            Arrays.asList(mock1, mock2, mock3, mock4, mock5), null, null, null);

    assertSame("MOCK1", mock1, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock1", null));
    assertSame("MOCK1", mock1, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock1", "2.3"));
    loggings.assertNoUnexpectedLog();

    assertSame("MOCK3", mock3, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock3", null));
    loggings.assertNextLogContains("CRSAuthorityFactory", "AuthorityFactoryMock", "MOCK1", "2.3");
    loggings.assertNoUnexpectedLog();

    assertSame("MOCK5", mock5, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock5", null));
    loggings.assertNextLogContains("CRSAuthorityFactory", "AuthorityFactoryMock", "MOCK3");
    loggings.assertNoUnexpectedLog();

    // Ask again the same factories. No logging should be emitted now, because we already logged.
    assertSame("MOCK3", mock3, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock3", null));
    assertSame("MOCK5", mock5, factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock5", null));
    loggings.assertNoUnexpectedLog();
}
 
Example #11
Source File: EPSGFactoryProxy.java    From sis with Apache License 2.0 5 votes vote down vote up
private CRSAuthorityFactory factory() throws FactoryException {
    CRSAuthorityFactory f = factory;
    if (f == null) {
        factory = f = CRS.getAuthorityFactory("EPSG");
    }
    return f;
}
 
Example #12
Source File: ReferencingFactoryContainer.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the factory for creating coordinate operations from authority codes.
 * Currently only EPSG codes are supported.
 *
 * @return the Coordinate Operation authority factory (never {@code null}).
 * @throws FactoryException if the authority factory can not be obtained.
 */
public final CoordinateOperationAuthorityFactory getCoordinateOperationAuthorityFactory() throws FactoryException {
    final CRSAuthorityFactory factory = getCRSAuthorityFactory();
    if (factory instanceof CoordinateOperationAuthorityFactory) {       // This is the case for SIS implementation.
        return (CoordinateOperationAuthorityFactory) factory;
    }
    throw new NoSuchAuthorityFactoryException(null, Constants.EPSG);
}
 
Example #13
Source File: GeoHashGridProcessTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testInvertQueryNorthEastAxisOrder() throws Exception {
    Filter filter = ff.bbox("geom", 0, 0, 0, 0, "EPSG:4326");
    CRSAuthorityFactory   factory = CRS.getAuthorityFactory(false);
    CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem("EPSG:4326");
    ReferencedEnvelope env = new ReferencedEnvelope(2,3,0,1,crs);
    Query query = new Query();
    query.setFilter(filter);
    Query queryOut = process.invertQuery(env, query, null);
    assertEquals(ff.bbox("geom", 0, 2, 1, 3, "EPSG:4326"), queryOut.getFilter());
}
 
Example #14
Source File: ReferencingFactoryContainer.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the factory for creating coordinate systems from authority codes.
 * Currently only EPSG codes are supported.
 *
 * @return the Coordinate System authority factory (never {@code null}).
 * @throws FactoryException if the authority factory can not be obtained.
 */
public final CSAuthorityFactory getCSAuthorityFactory() throws FactoryException {
    final CRSAuthorityFactory factory = getCRSAuthorityFactory();
    if (factory instanceof CSAuthorityFactory) {                    // This is the case for SIS implementation.
        return (CSAuthorityFactory) factory;
    }
    throw new NoSuchAuthorityFactoryException(null, Constants.EPSG);
}
 
Example #15
Source File: CoordinateOperationSet.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a coordinate operation for the specified EPSG code.
 */
@Override
protected CoordinateOperation createObject(final String code) throws FactoryException {
    final Integer base = projections.get(code);
    if (base != null) {
        /*
         * First case documented in class Javadoc:
         *
         *     SELECT PROJECTION_CONV_CODE FROM "Coordinate Reference System" …
         *
         * The result is usually a ProjectedCRS, but not always.
         */
        CoordinateReferenceSystem crs;
        crs = ((CRSAuthorityFactory) factory).createCoordinateReferenceSystem(String.valueOf(base));
        if (crs instanceof GeneralDerivedCRS) {
            return ((GeneralDerivedCRS) crs).getConversionFromBase();
        }
    }
    /*
     * Following line is either for the second case documented in class Javadoc, or the first case
     * when the result is not a derived CRS. Note that we could create a derived CRS here as below:
     *
     *     CoordinateOperation op = …,
     *     if (crs != null && op instanceof Conversion) {
     *         return DefaultDerivedCRS.create(IdentifiedObjects.getProperties(crs), baseCRS,
     *                 (Conversion) op, crs.getCoordinateSystem()).getConversionFromBase();
     *     }
     *
     * We don't do that for now because because EPSGDataAccess.createCoordinateReferenceSystem(String)
     * would be a better place, by generalizing the work done for ProjectedCRS.
     *
     * https://issues.apache.org/jira/browse/SIS-357
     */
    return ((CoordinateOperationAuthorityFactory) factory).createCoordinateOperation(code);
}
 
Example #16
Source File: CRSTable.java    From sis with Apache License 2.0 5 votes vote down vote up
private List<Code> getCodes() throws FactoryException{
    final CRSAuthorityFactory factory = org.apache.sis.referencing.CRS.getAuthorityFactory(null);
    final Set<String> strs = factory.getAuthorityCodes(CoordinateReferenceSystem.class);
    final List<Code> codes = new ArrayList<>();
    for (String str : strs) {
        codes.add(new Code(factory, str));
    }
    return codes;
}
 
Example #17
Source File: CRSTable.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a collection containing only the factories of the specified authority.
 */
private static Collection<CRSAuthorityFactory> filter(
        final Collection<? extends CRSAuthorityFactory> factories, final String authority){
    final List<CRSAuthorityFactory> filtered = new ArrayList<>();
    for (final CRSAuthorityFactory factory : factories) {
        if (Citations.identifierMatches(factory.getAuthority(), authority)) {
            filtered.add(factory);
        }
    }
    return filtered;
}
 
Example #18
Source File: CrsInfo.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static void retrieveCodes(Set<String> codes, Class<? extends CoordinateReferenceSystem> crsType,
                                  CRSAuthorityFactory factory) {
    Set<String> localCodes;
    try {
        localCodes = factory.getAuthorityCodes(crsType);
    } catch (FactoryException ignore) {
        return;
    }
    codes.addAll(localCodes);
}
 
Example #19
Source File: CRS.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the given coordinate reference system by an authoritative description, if one can be found.
 * This method can be invoked after constructing a CRS in a context where the EPSG (or other authority)
 * code is suspected more reliable than the rest of the description. A common case is a <cite>Well Known
 * Text</cite> (WKT) string declaring wrong projection method or parameter values for the EPSG code that
 * it pretends to describe. For example:
 *
 * <blockquote>
 *   {@code PROJCS["WGS 84 / Pseudo-Mercator",}<br>
 *   {@code   }(…base CRS omitted for brevity…)<br>
 *   {@code   PROJECTION["Mercator (variant A)"],} — <em><b>wrong:</b> shall be "Popular Visualisation Pseudo Mercator"</em><br>
 *   {@code   }(…parameters and axes omitted for brevity…)<br>
 *   {@code   AUTHORITY["EPSG", "3857"]]}
 * </blockquote>
 *
 * In such cases, Apache SIS behavior in {@link #fromWKT(String)}, {@link #fromXML(String)} and other methods is
 * conform to the <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html">ISO 19162 specification</a>:
 *
 * <blockquote><cite>"Should any attributes or values given in the cited identifier be in conflict with attributes
 * or values given explicitly in the WKT description, the WKT values shall prevail."</cite></blockquote>
 *
 * In situations where the opposite behavior is desired (i.e. to make the authority identifier prevails),
 * this method can be invoked. This method performs the following actions:
 *
 * <ul>
 *   <li>If the given CRS has an {@linkplain AbstractIdentifiedObject#getIdentifiers() identifier} and if the authority factory can
 *     {@linkplain org.apache.sis.referencing.factory.GeodeticAuthorityFactory#createCoordinateReferenceSystem(String) create a CRS}
 *     for that identifier, then:
 *     <ul>
 *       <li>If the CRS defined by the authority is {@linkplain Utilities#equalsIgnoreMetadata equal, ignoring metadata},
 *         to the given CRS, then this method returns silently the <em>authoritative</em> CRS.</li>
 *       <li>Otherwise if the CRS defined by the authority is equal, ignoring axis order and units, to the given CRS,
 *         then this method returns a <em>new</em> CRS derived from the authoritative one but with same
 *         {@linkplain org.apache.sis.referencing.cs.AxesConvention axes convention} than the given CRS.
 *         A warning is emitted.</li>
 *       <li>Otherwise this method discards the given CRS and returns the <em>authoritative</em> CRS.
 *         A warning is emitted with a message indicating where a difference has been found.</li>
 *     </ul>
 *   </li>
 *   <li>Otherwise if the given CRS does not have identifier, then this method
 *       {@linkplain org.apache.sis.referencing.factory.IdentifiedObjectFinder searches for an equivalent CRS}
 *       defined by the authority factory. If such CRS is found, then:
 *     <ul>
 *       <li>If the CRS defined by the authority is {@linkplain Utilities#equalsIgnoreMetadata equal, ignoring metadata},
 *         to the given CRS, then this method returns silently the <em>authoritative</em> CRS.</li>
 *       <li>Otherwise if the CRS defined by the authority is equal, ignoring axis order and units, to the given CRS,
 *         then this method returns silently a <em>new</em> CRS derived from the authoritative one but with same
 *         {@linkplain org.apache.sis.referencing.cs.AxesConvention axes convention} than the given CRS.</li>
 *     </ul>
 *   </li>
 *   <li>Otherwise this method silently returns the given CRS as-is.</li>
 * </ul>
 *
 * <h4>Avoiding warning redundancies</h4>
 * The warnings logged by this method are redundant with warnings logged by other methods in this class,
 * in particular {@link #fromWKT(String)} and {@link #fromXML(String)} methods. For avoiding this annoyance,
 * a {@code null} value for the {@code warningFilter} argument means to shut off those redundant loggings.
 * A non-null {@code warningFilter} argument is more useful for CRS parsed by methods outside this class,
 * for example {@link org.apache.sis.io.wkt.WKTFormat} or {@link org.apache.sis.xml.XML#unmarshal(String)}.
 *
 * @param  crs            the CRS to replace by an authoritative CRS, or {@code null}.
 * @param  factory        the factory where to search for authoritative definitions, or {@code null} for the default.
 * @param  warningFilter  whether to log warnings, or {@code null} for the default behavior (which is to filter out
 *                        the warnings that are redundant with warnings emitted by other methods in this class).
 * @return the suggested CRS to use (may be the {@code crs} argument itself), or {@code null} if the given CRS was null.
 * @throws FactoryException if an error occurred while querying the authority factory.
 *
 * @since 1.0
 */
public static CoordinateReferenceSystem fromAuthority(CoordinateReferenceSystem crs,
        final CRSAuthorityFactory factory, final Filter warningFilter) throws FactoryException
{
    if (crs != null) {
        final DefinitionVerifier verification = DefinitionVerifier.withAuthority(crs, factory, true);
        if (verification != null) {
            crs = verification.authoritative;
            if (warningFilter != null) {
                final LogRecord record = verification.warning(false);
                if (record != null) {
                    record.setLoggerName(Modules.REFERENCING);
                    record.setSourceClassName(CRS.class.getName());
                    record.setSourceMethodName("fromAuthority");
                    if (warningFilter.isLoggable(record)) {
                        Logging.getLogger(Modules.REFERENCING).log(record);
                    }
                }
            }
        }
    }
    return crs;
}
 
Example #20
Source File: CrsInfo.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
AutoCrsInfo(String epsgCode, CRSAuthorityFactory factory) {
    super(epsgCode, factory);
}
 
Example #21
Source File: CrsInfo.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
CrsInfo(String crsCode, CRSAuthorityFactory factory) {
    this.crsCode = crsCode;
    this.factory = factory;
}
 
Example #22
Source File: ReferencingFactoryContainer.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the factory for creating coordinate reference systems from authority codes.
 * Currently only EPSG codes are supported.
 *
 * @return the Coordinate Reference System authority factory (never {@code null}).
 * @throws FactoryException if the authority factory can not be obtained.
 */
public final CRSAuthorityFactory getCRSAuthorityFactory() throws FactoryException {
    if (crsAuthorityFactory == null) {
        crsAuthorityFactory = CRS.getAuthorityFactory(Constants.EPSG);
    }
    return crsAuthorityFactory;
}
 
Example #23
Source File: CRS.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the system-wide authority factory used by {@link #forCode(String)} and other SIS methods.
 * If the given authority is non-null, then this method returns a factory specifically for that authority.
 * Otherwise, this method returns the {@link org.apache.sis.referencing.factory.MultiAuthoritiesFactory}
 * instance that manages all other factories.
 *
 * <p>The {@code authority} argument can be {@code "EPSG"}, {@code "OGC"} or any other authority found
 * on the classpath. In the {@code "EPSG"} case, whether the full set of EPSG codes is supported or not
 * depends on whether a {@linkplain org.apache.sis.referencing.factory.sql connection to the database}
 * can be established. If no connection can be established, then this method returns a small embedded
 * EPSG factory containing at least the CRS defined in the {@link #forCode(String)} method javadoc.</p>
 *
 * <p>User-defined authorities can be added to the SIS environment by creating a {@code CRSAuthorityFactory}
 * implementation with a public no-argument constructor, and declaring the fully-qualified name of that class
 * in a file at the following location:</p>
 *
 * {@preformat text
 *     META-INF/services/org.opengis.referencing.crs.CRSAuthorityFactory
 * }
 *
 * @param  authority  the authority of the desired factory (typically {@code "EPSG"} or {@code "OGC"}),
 *         or {@code null} for the {@link org.apache.sis.referencing.factory.MultiAuthoritiesFactory}
 *         instance that manage all factories.
 * @return the system-wide authority factory used by SIS for the given authority.
 * @throws FactoryException if no factory can be returned for the given authority.
 *
 * @see #forCode(String)
 * @see org.apache.sis.referencing.factory.MultiAuthoritiesFactory
 *
 * @since 0.7
 */
public static CRSAuthorityFactory getAuthorityFactory(final String authority) throws FactoryException {
    if (authority == null) {
        return AuthorityFactories.ALL;
    }
    return AuthorityFactories.ALL.getAuthorityFactory(CRSAuthorityFactory.class, authority, null);
}
 
Example #24
Source File: AuthorityFactoriesTest.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Tests {@link CRSAuthorityFactory#getDescriptionText(String)}.
 *
 * @throws FactoryException if the EPSG:4326 name can not be obtained.
 *
 * @since 0.8
 */
@Test
public void testGetDescriptionText() throws FactoryException {
    final CRSAuthorityFactory factory = AuthorityFactories.ALL;
    assertEquals("WGS 84", factory.getDescriptionText("EPSG:4326").toString());
    assertEquals("WGS 84", factory.getDescriptionText("urn:ogc:def:crs:epsg::4326").toString());
}