/** * Returns the Well Know Text from a code. * * @param code Value allocated by authority. * @return The Well Know Text (WKT) for the specified code. * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found. */ public String getWKT(final String code) throws NoSuchAuthorityCodeException { ensureNonNull("code", code); final String wkt = definitions.getProperty(trimAuthority(code)); if (wkt == null) { throw noSuchAuthorityCode(IdentifiedObject.class, code); } return wkt.trim(); }
/** * Returns a coordinate reference system from a code. If the object type is know at compile * time, it is recommended to invoke the most precise method instead of this one. * * @param code Value allocated by authority. * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found. * @throws FactoryException if the object creation failed for some other reason. */ @Override public CoordinateReferenceSystem createCoordinateReferenceSystem(final String code) throws NoSuchAuthorityCodeException, FactoryException { final String wkt = getWKT(code); final Parser parser = getParser(); try { synchronized (parser) { parser.code = code; // parseCoordinateReferenceSystem provides a slightly faster path than parseObject. return parser.parseCoordinateReferenceSystem(wkt); } } catch (ParseException exception) { throw new FactoryException(exception); } }
/** * Creates the backing store authority factory. * * @return The backing store to uses in {@code createXXX(...)} methods. * @throws FactoryNotFoundException if the no {@code epsg.properties} file has been found. * @throws FactoryException if the constructor failed to find or read the file. This exception * usually has an {@link IOException} as its cause. */ protected AbstractAuthorityFactory createBackingStore() throws FactoryException { try { URL url = getDefinitionsURL(); if (url == null) { throw new FactoryNotFoundException( Errors.format(ErrorKeys.FILE_DOES_NOT_EXIST_$1, FILENAME)); } final Iterator<? extends Identifier> ids = getAuthority().getIdentifiers().iterator(); final String authority = ids.hasNext() ? ids.next().getCode() : "EPSG"; final LogRecord record = Loggings.format( Level.CONFIG, LoggingKeys.USING_FILE_AS_FACTORY_$2, url.getPath(), authority); record.setLoggerName(LOGGER.getName()); LOGGER.log(record); return new PropertyAuthorityFactory(factories, getAuthorities(), url); } catch (IOException exception) { throw new FactoryException(Errors.format(ErrorKeys.CANT_READ_$1, FILENAME), exception); } }
/** * Gets a description of the object corresponding to a code. * * @param code Value allocated by authority. * @return A description of the object, or {@code null} if the object corresponding to the * specified {@code code} has no description. * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found. * @throws FactoryException if the query failed for some other reason. */ public InternationalString getDescriptionText(final String code) throws NoSuchAuthorityCodeException, FactoryException { final String wkt = getWKT(code); int start = wkt.indexOf('"'); if (start >= 0) { final int end = wkt.indexOf('"', ++start); if (end >= 0) { return new SimpleInternationalString(wkt.substring(start, end).trim()); } } return null; }
/** Add the authority code to the specified properties, if not already present. */ @Override protected Map<String, Object> alterProperties(Map<String, Object> properties) { Object candidate = properties.get(IdentifiedObject.IDENTIFIERS_KEY); if (candidate == null && code != null) { properties = new HashMap<String, Object>(properties); code = trimAuthority(code); final Object identifiers; if (authorities.length <= 1) { identifiers = new NamedIdentifier(authority, code); } else { final NamedIdentifier[] ids = new NamedIdentifier[authorities.length]; for (int i = 0; i < ids.length; i++) { ids[i] = new NamedIdentifier(authorities[i], code); } identifiers = ids; } properties.put(IdentifiedObject.IDENTIFIERS_KEY, identifiers); } return super.alterProperties(properties); } }
ensureNonNull("authorities", authorities); if (authorities.length == 0) { throw new IllegalArgumentException(Errors.format(ErrorKeys.EMPTY_ARRAY)); ensureNonNull("authority", authority); final InputStream in = definitions.openStream(); this.definitions.load(in);
void registerAdditionalCRS() throws KlabException { URL epsg = null; File epp = new File(KLAB.CONFIG.getDataPath() + File.separator + "epsg.properties"); if (epp.exists()) { try { epsg = epp.toURI().toURL(); } catch (MalformedURLException e) { throw new KlabIOException(e); } } if (epsg != null) { Hints hints = new Hints(Hints.CRS_AUTHORITY_FACTORY, PropertyAuthorityFactory.class); ReferencingFactoryContainer referencingFactoryContainer = ReferencingFactoryContainer .instance(hints); PropertyAuthorityFactory factory; try { factory = new PropertyAuthorityFactory(referencingFactoryContainer, Citations .fromName("EPSG"), epsg); ReferencingFactoryFinder.addAuthorityFactory(factory); } catch (IOException e) { throw new KlabIOException(e); } } }
/** * Returns an arbitrary object from a code. If the object type is know at compile time, it is * recommended to invoke the most precise method instead of this one. * * @param code Value allocated by authority. * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found. * @throws FactoryException if the object creation failed for some other reason. */ @Override public IdentifiedObject createObject(final String code) throws NoSuchAuthorityCodeException, FactoryException { final String wkt = getWKT(code); final Parser parser = getParser(); try { synchronized (parser) { parser.code = code; return (IdentifiedObject) parser.parseObject(wkt); } } catch (ParseException exception) { throw new FactoryException(exception); } }