/** * Returns the {@linkplain CRSAuthorityFactory CRS authority factory} singleton. * * @throws FactoryNotFoundException if no factory was found for the requested type. * @throws FactoryRegistryException if the factory can't be obtained for an other reason. */ public CRSAuthorityFactory getCRSAuthorityFactory() throws FactoryRegistryException { return ReferencingFactoryFinder.getCRSAuthorityFactory(DEFAULT_AUTHORITY, hints); }
CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); CoordinateReferenceSystem worldCRS = factory
/** Returns a factory of the given type. */ private static final <T extends AbstractAuthorityFactory> T getFactory(final Class<T> type) { return type.cast( ReferencingFactoryFinder.getCRSAuthorityFactory( "EPSG", new Hints(Hints.CRS_AUTHORITY_FACTORY, type))); }
/** * Returns the version number of the specified authority database, or {@code null} if not * available. * * @param authority The authority name (typically {@code "EPSG"}). * @return The version number of the authority database, or {@code null} if unknown. * @throws FactoryRegistryException if no {@link CRSAuthorityFactory} implementation was found * for the specified authority. * @since 2.4 */ public static Version getVersion(final String authority) throws FactoryRegistryException { Object candidate = ReferencingFactoryFinder.getCRSAuthorityFactory(authority, null); final Set<Factory> guard = new HashSet<Factory>(); while (candidate instanceof Factory) { final Factory factory = (Factory) candidate; if (!guard.add(factory)) { break; // Safety against never-ending recursivity. } final Map hints = factory.getImplementationHints(); final Object version = hints.get(Hints.VERSION); if (version instanceof Version) { return (Version) version; } candidate = hints.get(Hints.CRS_AUTHORITY_FACTORY); } return null; }
/** Creates an instance of the specified authority. */ private Command(final String authority) { factory = (authority == null) ? CRS.getAuthorityFactory(false) : ReferencingFactoryFinder.getCRSAuthorityFactory(authority, HINTS); formatter = new Parser(); }
/** * Constructor. Populates the model with available reference systems for the specified * authority. If {@code authority} is {@code null} or empty, it defaults to {@link * JCRSChooser#DEFAULT_AUTHORITY}. * * @param authority the authority name * @param showDefaults show GeoTools default reference systems */ public CRSListModel(String authority) { try { CRSAuthorityFactory fac = ReferencingFactoryFinder.getCRSAuthorityFactory(authority, null); Set<String> codes = fac.getAuthorityCodes(CoordinateReferenceSystem.class); if (authority == null || authority.trim().length() == 0) { authority = JCRSChooser.DEFAULT_AUTHORITY; } for (String code : codes) { code = code.trim(); String desc = fac.getDescriptionText(authority + ":" + code).toString(); allItems.add(new Item(code, desc)); } filterItems.addAll(allItems); } catch (Exception ex) { throw new RuntimeException(ex); } }
/** Returns a factory for the specified authority and type. */ @Override final <T extends AuthorityFactory> T fromFactoryRegistry( final String authority, final Class<T> type) throws FactoryRegistryException { final AuthorityFactory f; if (CRSAuthorityFactory.class.equals(type)) { f = ReferencingFactoryFinder.getCRSAuthorityFactory(authority, getHints()); } else if (CSAuthorityFactory.class.equals(type)) { f = ReferencingFactoryFinder.getCSAuthorityFactory(authority, getHints()); } else if (DatumAuthorityFactory.class.equals(type)) { f = ReferencingFactoryFinder.getDatumAuthorityFactory(authority, getHints()); } else if (CoordinateOperationAuthorityFactory.class.equals(type)) { f = ReferencingFactoryFinder.getCoordinateOperationAuthorityFactory( authority, getHints()); } else { f = super.fromFactoryRegistry(authority, type); } return type.cast(f); }
/** Gets the authority factory for ESRI. */ @Before public void setUp() { factory = (FactoryUsingWKT) ReferencingFactoryFinder.getCRSAuthorityFactory( "EPSG", new Hints(Hints.CRS_AUTHORITY_FACTORY, FactoryUsingWKT.class)); }
/** Tests the registration in {@link ReferencingFactoryFinder}. */ @Test public void testFactoryFinder() { final Collection<String> authorities = ReferencingFactoryFinder.getAuthorityNames(); assertTrue(authorities.contains("AUTO")); assertTrue(authorities.contains("AUTO2")); factory = ReferencingFactoryFinder.getCRSAuthorityFactory("AUTO", null); assertTrue(factory instanceof AutoCRSFactory); assertSame(factory, ReferencingFactoryFinder.getCRSAuthorityFactory("AUTO2", null)); }
/** Make sure that a singleton instance is registered. */ @Test public void testRegistration() { String authority = "http://www.opengis.net/def"; AuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory(authority, null); assertSame(factory, ReferencingFactoryFinder.getCRSAuthorityFactory(authority, null)); assertSame(factory, ReferencingFactoryFinder.getCSAuthorityFactory(authority, null)); assertSame(factory, ReferencingFactoryFinder.getDatumAuthorityFactory(authority, null)); }
/** Tests the registration in {@link ReferencingFactoryFinder}. */ @Test public void testFactoryFinder() { final Collection authorities = ReferencingFactoryFinder.getAuthorityNames(); assertTrue(authorities.contains("CRS")); CRSAuthorityFactory found = ReferencingFactoryFinder.getCRSAuthorityFactory("CRS", null); assertTrue(found instanceof WebCRSFactory); }
/** * Creates a wrappers around the default factories for the specified authority. The factories * are fetched using {@link ReferencingFactoryFinder}. * * @param authority The authority to wraps (example: {@code "EPSG"}). If {@code null}, then all * authority factories must be explicitly specified in the set of hints. * @param userHints An optional set of hints, or {@code null} if none. * @throws FactoryRegistryException if at least one factory can not be obtained. * @since 2.4 */ protected AuthorityFactoryAdapter(final String authority, final Hints userHints) throws FactoryRegistryException { this( ReferencingFactoryFinder.getCRSAuthorityFactory( authority, trim(userHints, Hints.CRS_AUTHORITY_FACTORY)), ReferencingFactoryFinder.getCSAuthorityFactory( authority, trim(userHints, Hints.CS_AUTHORITY_FACTORY)), ReferencingFactoryFinder.getDatumAuthorityFactory( authority, trim(userHints, Hints.DATUM_AUTHORITY_FACTORY)), ReferencingFactoryFinder.getCoordinateOperationAuthorityFactory( authority, trim(userHints, Hints.COORDINATE_OPERATION_AUTHORITY_FACTORY))); }
/** Make sure that a singleton instance is registered. */ @Test public void testRegistration() { String authority = "URN:OGC:DEF"; final AuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory(authority, null); assertSame(factory, ReferencingFactoryFinder.getCRSAuthorityFactory(authority, null)); assertSame(factory, ReferencingFactoryFinder.getCSAuthorityFactory(authority, null)); assertSame(factory, ReferencingFactoryFinder.getDatumAuthorityFactory(authority, null)); /* * Tests the X-OGC namespace, which should be synonymous. */ authority = "URN:X-OGC:DEF"; assertSame(factory, ReferencingFactoryFinder.getCRSAuthorityFactory(authority, null)); assertSame(factory, ReferencingFactoryFinder.getCSAuthorityFactory(authority, null)); assertSame(factory, ReferencingFactoryFinder.getDatumAuthorityFactory(authority, null)); }
/** Tests fetching the URN authority when the "longitude first axis order" hint is set. */ @Test public void testWhenForceXY() throws FactoryException { try { Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING, "http"); Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); try { ReferencingFactoryFinder.getCRSAuthorityFactory("URN:OGC:DEF", null); fail("URN factory should not accept FORCE_LONGITUDE_FIRST_AXIS_ORDER = TRUE"); } catch (FactoryNotFoundException e) { // This is the expected exception. } CoordinateReferenceSystem crs = CRS.decode("URN:OGC:DEF:CRS:CRS:84", true); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); crs = CRS.decode("URN:OGC:DEF:CRS:CRS:84"); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); } finally { Hints.removeSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING); Hints.removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER); } } }
/** * Tests fetching the HTTP URI CRS factory when the "longitude first axis order" hint is set. * This test ensures that the factory ignores this hint. */ @Test public void testWhenForceXY() throws FactoryException { try { Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING, "http"); Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); try { ReferencingFactoryFinder.getCRSAuthorityFactory("http://www.opengis.net/def", null); fail("HTTP URI factory should not accept FORCE_LONGITUDE_FIRST_AXIS_ORDER = true"); } catch (FactoryNotFoundException e) { // success } CoordinateReferenceSystem crs = CRS.decode("http://www.opengis.net/def/crs/CRS/0/84", true); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); crs = CRS.decode("http://www.opengis.net/def/crs/CRS/0/84"); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); } finally { Hints.removeSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING); Hints.removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER); } }
/** Tests the CRS factory. */ @Test public void testCRS() throws FactoryException { CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("http://www.opengis.net/gml", null); GeographicCRS crs; try { crs = factory.createGeographicCRS("CRS:84"); fail(); } catch (NoSuchAuthorityCodeException exception) { // This is the expected exception. assertEquals("CRS:84", exception.getAuthorityCode()); } crs = factory.createGeographicCRS("http://www.opengis.net/gml/srs/crs.xml#84"); assertSame(crs, CRS.decode("http://www.opengis.net/gml/srs/crs.xml#84")); assertSame(crs, CRS.decode("CRS:84")); assertNotSame(crs, DefaultGeographicCRS.WGS84); assertFalse(DefaultGeographicCRS.WGS84.equals(crs)); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); // Test CRS:83 crs = factory.createGeographicCRS("http://www.opengis.net/gml/srs/crs.xml#83"); assertSame(crs, CRS.decode("CRS:83")); assertFalse(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); } }
/** Tests the HTTP URI CRS factory. */ @Test public void testCRS() throws FactoryException { CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("http://www.opengis.net/def", null); GeographicCRS crs; try { crs = factory.createGeographicCRS("CRS:84"); fail(); } catch (NoSuchAuthorityCodeException exception) { assertEquals("CRS:84", exception.getAuthorityCode()); } crs = factory.createGeographicCRS("http://www.opengis.net/def/crs/CRS/WMS1.3/84"); assertSame(crs, factory.createGeographicCRS("http://www.opengis.net/def/crs/CRS/1.3/84")); assertSame(crs, factory.createGeographicCRS("HTTP://WWW.OPENGIS.NET/DEF/CRS/CRS/1.3/84")); assertSame(crs, factory.createGeographicCRS("HTTP://WWW.OPENGIS.NET/DEF/CRS/CRS/0/84")); assertSame(crs, CRS.decode("http://www.opengis.net/def/crs/CRS/1.3/84")); assertSame(crs, CRS.decode("CRS:84")); assertNotSame(crs, DefaultGeographicCRS.WGS84); assertFalse(DefaultGeographicCRS.WGS84.equals(crs)); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); crs = factory.createGeographicCRS("http://www.opengis.net/def/crs/CRS/1.3/83"); assertSame(crs, CRS.decode("CRS:83")); assertFalse(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); }
/** Makes sure that the authority factory has the proper name. */ public void testAuthority() { CRSAuthorityFactory factory; Citation authority; // Tests the official factory. factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", null); authority = factory.getAuthority(); assertNotNull(authority); assertEquals("European Petroleum Survey Group", authority.getTitle().toString(Locale.US)); assertTrue(Citations.identifierMatches(authority, "EPSG")); // Tests the modified factory. factory = new OrderedAxisAuthorityFactory("EPSG", null, null); authority = factory.getAuthority(); assertNotNull(authority); assertTrue(Citations.identifierMatches(authority, "EPSG")); }
/** Tests the CRS factory. */ @Test public void testCRS() throws FactoryException { CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("URN:OGC:DEF", null); GeographicCRS crs; try { crs = factory.createGeographicCRS("CRS:84"); fail(); } catch (NoSuchAuthorityCodeException exception) { // This is the expected exception. assertEquals("CRS:84", exception.getAuthorityCode()); } crs = factory.createGeographicCRS("urn:ogc:def:crs:CRS:WMS1.3: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, CRS.decode("urn:ogc:def:crs:CRS:1.3:84")); assertSame(crs, CRS.decode("CRS:84")); assertNotSame(crs, DefaultGeographicCRS.WGS84); assertFalse(DefaultGeographicCRS.WGS84.equals(crs)); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); // Test CRS:83 crs = factory.createGeographicCRS("urn:ogc:def:crs:CRS:1.3:83"); assertSame(crs, CRS.decode("CRS:83")); assertFalse(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); }
/** * Tests {@link IdentifiedObjectFinder#createFromCodes}. We uses the CRS factory for testing * purpose. */ @Test public void testCreateFromCodes() throws FactoryException { final CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("CRS", null); final IdentifiedObjectFinder proxy = new IdentifiedObjectFinder(factory, GeographicCRS.class); CoordinateReferenceSystem expected = factory.createCoordinateReferenceSystem("84"); assertNotSame(expected, DefaultGeographicCRS.WGS84); assertSame(expected, proxy.createFromCodes(expected, false)); assertSame(expected, proxy.createFromIdentifiers(expected)); assertNull(proxy.createFromNames(expected)); assertSame(expected, proxy.createFromCodes(DefaultGeographicCRS.WGS84, false)); assertNull(proxy.createFromIdentifiers(DefaultGeographicCRS.WGS84)); assertNull(proxy.createFromNames(DefaultGeographicCRS.WGS84)); expected = factory.createCoordinateReferenceSystem("83"); assertSame(expected, proxy.createFromCodes(expected, false)); assertSame(expected, proxy.createFromIdentifiers(expected)); assertNull(proxy.createFromNames(expected)); } }