public Set getAuthorityCodes(Class type) throws FactoryException { return crsAuthority.getAuthorityCodes(type); }
/** * Check if any custom EPSG maps the provided crs and return that one * * @throws FactoryException */ public static CoordinateReferenceSystem lookupForCustomEpsg(CoordinateReferenceSystem crs) throws FactoryException { if (!crsFactories.isEmpty()) { for (CRSAuthorityFactory crsFactory : crsFactories) { Set<String> codes = crsFactory.getAuthorityCodes(CoordinateReferenceSystem.class); for (String code : codes) { CoordinateReferenceSystem decodedCRS = CRS.decode("EPSG:" + code); if (CRS.equalsIgnoreMetadata(decodedCRS, crs)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Found valid epsgCode for the custom CRS: " + code); } return decodedCRS; } } } } return crs; }
/** * 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); } }
/** * Implementation of {@link CRS#getSupportedCodes}. Provided here in order to reduce the amount * of class loading when using {@link CRS} for other purpose than CRS decoding. */ static Set<String> getSupportedCodes(final String authority) { final Set<String> result = new LinkedHashSet<String>(AUTHORITY_LESS); for (final CRSAuthorityFactory factory : ReferencingFactoryFinder.getCRSAuthorityFactories(null)) { if (Citations.identifierMatches(factory.getAuthority(), authority)) { final Set<String> codes; try { codes = factory.getAuthorityCodes(CoordinateReferenceSystem.class); } catch (Exception exception) { /* * Failed to fetch the codes either because of a database connection problem * (FactoryException), or because we are using a simple factory that doesn't * support this operation (UnsupportedOperationException), or any unexpected * reason. No codes from this factory will be added to the set. */ CRS.unexpectedException("getSupportedCodes", exception); continue; } if (codes != null) { result.addAll(codes); } } } return result; }
/** Tests the {@link AllAuthoritiesFactory#getAuthorityCodes} method. */ @Test public void testAuthorityCodes() throws FactoryException { final CRSAuthorityFactory all = AllAuthoritiesFactory.DEFAULT; final Collection codes = all.getAuthorityCodes(CoordinateReferenceSystem.class); assertFalse(codes.isEmpty()); assertTrue(codes.contains("CRS:84")); assertTrue(codes.contains("AUTO:42001") || codes.contains("AUTO2:42001")); }
/** Tests the amount of codes available. */ public void testCodes() throws FactoryException { final CRSAuthorityFactory factory = new OrderedAxisAuthorityFactory("EPSG", null, null); final Set codes = factory.getAuthorityCodes(CoordinateReferenceSystem.class); assertNotNull(codes); assertTrue(codes.size() >= 3000); }
/** * Tests the number of CRS that can be created. This test will be executed only if this test * suite is run with the {@code -verbose} option provided on the command line. */ public void testSuccess() throws FactoryException { if (!verbose) { return; } final CRSAuthorityFactory factory = new OrderedAxisAuthorityFactory("EPSG", null, null); Set codes = factory.getAuthorityCodes(CoordinateReferenceSystem.class); int total = codes.size(); int count = 0; for (Iterator i = codes.iterator(); i.hasNext(); ) { CoordinateReferenceSystem crs; String code = (String) i.next(); try { crs = factory.createCoordinateReferenceSystem(code); assertNotNull(crs); count++; } catch (FactoryException e) { // System.err.println("WARNING (CRS: " + code + " ):" + e.getMessage()); } } // System.out.println("Success: " + count + "/" + total + " (" + (count * 100) / total + // "%)"); }
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); } }
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); } }
@Override public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) throws FactoryException { return factory().getAuthorityCodes(type); } }
@Override public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) throws FactoryException { return factory().getAuthorityCodes(type); } }
/** * Check if any custom EPSG maps the provided crs and return that one * * @throws FactoryException */ public static CoordinateReferenceSystem lookupForCustomEpsg(CoordinateReferenceSystem crs) throws FactoryException { if (!crsFactories.isEmpty()) { for (CRSAuthorityFactory crsFactory : crsFactories) { Set<String> codes = crsFactory.getAuthorityCodes(CoordinateReferenceSystem.class); for (String code : codes) { CoordinateReferenceSystem decodedCRS = CRS.decode("EPSG:" + code); if (CRS.equalsIgnoreMetadata(decodedCRS, crs)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Found valid epsgCode for the custom CRS: " + code); } return decodedCRS; } } } } return crs; }
static List<SRS> buildCodeList() { long t = System.currentTimeMillis(); Set<String> codes = CRS.getSupportedCodes("EPSG"); try { codes.addAll(customFactory.getAuthorityCodes(CoordinateReferenceSystem.class)); } catch (FactoryException e) { LOGGER.log(Level.WARNING, "Error occurred while trying to gather custom CRS codes", e); } // make a set with each code Set<SRS> idSet = new HashSet<SRS>(); for (String code : codes) { // make sure we're using just the non prefix part String id = code.substring(code.indexOf(':') + 1); // avoid WGS84DD and eventual friends, as we're still not able to handle them, // if they are chosen exceptions arises everywhere if (NUMERIC.matcher(id).matches()) { idSet.add(new SRS(id)); } } List<SRS> srsList = new ArrayList<SRS>(idSet); Collections.sort(srsList, new CodeComparator()); // sort to get them in order return srsList; }
static List<SRS> buildCodeList() { // long t = System.currentTimeMillis(); Set<String> codes = CRS.getSupportedCodes("EPSG"); try { codes.addAll(customFactory.getAuthorityCodes(CoordinateReferenceSystem.class)); } catch (FactoryException e) { LOGGER.log(Level.WARNING, "Error occurred while trying to gather custom CRS codes", e); } // make a set with each code Set<SRS> idSet = new HashSet<SRS>(); for (String code : codes) { // make sure we're using just the non prefix part String id = code.substring(code.indexOf(':') + 1); // avoid WGS84DD and eventual friends, as we're still not able to handle them, // if they are chosen exceptions arises everywhere if (NUMERIC.matcher(id).matches()) { idSet.add(new SRS(id)); } } List<SRS> srsList = new ArrayList<SRS>(idSet); Collections.sort(srsList, new CodeComparator()); // sort to get them in order return srsList; }
/** * 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); } }
CRSAuthorityFactory factory = (CRSAuthorityFactory) object; try { Set<String> codes = factory.getAuthorityCodes(CoordinateReferenceSystem.class); for( Object codeObj : codes ) { String code = (String) codeObj;
/** * Get List of supported EPSG codes * * @return Supported EPSG codes */ public Set<String> getSupportedCRS() { try { Set<String> authorityCodes = getCrsAuthorityFactory().getAuthorityCodes(CoordinateReferenceSystem.class); if (CollectionHelper.isNotEmpty(authorityCodes) && CollectionHelper.isNotEmpty(this.supportedCRS)) { return CollectionHelper.conjunctCollectionsToSet(authorityCodes, this.supportedCRS); } else if (CollectionHelper.isEmpty(authorityCodes)) { return Sets.newHashSet(Integer.toString(getStorageEPSG()), Integer.toString(getStorage3DEPSG())); } return authorityCodes; } catch (FactoryException fe) { LOGGER.warn("Error while querying supported EPSG codes", fe); } return Collections.emptySet(); }
defaultProperties.setProperty("OBJECTS.KIND", "Coordinate Reference Systems (CRS)"); defaultProperties.setProperty("FILENAME", "CRS-Codes.html"); final Collection<String> codes = factory.getAuthorityCodes(CoordinateReferenceSystem.class); final int previousCount = rows.size(); for (final String code : codes) {
/** * 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")); }
for (final String code : factory.getAuthorityCodes(GeneralDerivedCRS.class)) { final CoordinateReferenceSystem crs; try {