/** * Gets all registered registry names * The returned array contains a case-sensitive version of registry names. * * @return an array of names */ public String[] getRegistryNames() { LOGGER.trace("Getting all registry names"); List<String> names = new ArrayList<String>(); for (Registry r : registries.values()) { names.add(r.getRegistryName()); } return names.toArray(new String[names.size()]); }
/** * Return a list of supported codes according an registryName. * * @param registryName (ex : EPSG, IGNF, ESRI) */ public Set<String> getSupportedCodes(String registryName) throws RegistryException { return getRegistryManager().getRegistry(registryName).getSupportedCodes(); }
/** * Returns a {@link org.cts.crs.CoordinateReferenceSystem} corresponding to * an authority and a srid. * * @param authorityAndSrid the code of the desired CRS (for instance * EPSG:4326 or IGNF:LAMBE) * @return * @throws CRSException */ public CoordinateReferenceSystem getCRS(String authorityAndSrid) throws CRSException { CoordinateReferenceSystem crs = CRSPOOL.get(authorityAndSrid.toUpperCase()); if (crs == null) { try { String[] registryNameWithCode = splitRegistryNameAndCode(authorityAndSrid); String authority = registryNameWithCode[0]; String code = registryNameWithCode[1]; if (isRegistrySupported(authority)) { Registry registry = getRegistryManager().getRegistry(authority); crs = registry.getCoordinateReferenceSystem(new Identifier(authority, code, "")); if (crs != null) { CRSPOOL.put(authorityAndSrid.toUpperCase(), crs); } } } catch (RegistryException ex) { throw new CRSException("Cannot create the CRS", ex); } } return crs; }
/** * Register a {@link Registry} in this {@code RegistryManager}. * An existing registry can be replaced by a new one. * Registries are stored in a case-insensitive map (keys are uppercase) * * @param registry the Registry to add * @param replace whether an existing Registry with the same name should be * replaced or not. */ public void addRegistry(Registry registry, boolean replace) { LOGGER.trace("Adding a new registry " + registry.getRegistryName()); String registryName = registry.getRegistryName().toUpperCase(); if (!replace && registries.containsKey(registryName)) { throw new IllegalArgumentException("Registry " + registryName + " already exists"); } registries.put(registryName, registry); fireRegistryAdded(registry.getRegistryName()); }
/** * Read all parameters from the registry * * @param crsCode the code corresponding to the information that must be * extracted from the registry * @param regexPattern the pattern used to split the line that describes the * coordinate system * @return * @throws IOException */ public Map<String, String> readParameters(String crsCode, Pattern regexPattern) throws IOException { InputStream inStr = Registry.class.getResourceAsStream(registry.getRegistryName()); if (inStr == null) { throw new IllegalStateException("Unable to access CRS file: " + registry.getRegistryName()); } BufferedReader reader = new BufferedReader(new InputStreamReader(inStr)); Map<String, String> args; try { args = readRegistry(reader, crsCode, regexPattern); } finally { reader.close(); } return args; }
/** * Return the list of all codes defined by this registry * * @param regex pattern * @return * @throws java.io.IOException */ public Set<String> getSupportedCodes(Pattern regex) throws IOException { InputStream inStr = Registry.class.getResourceAsStream(registry.getRegistryName()); if (inStr == null) { throw new IllegalStateException("Unable to access CRS file: " + registry.getRegistryName()); } BufferedReader br = new BufferedReader(new InputStreamReader(inStr)); try { Set<String> codes = new HashSet<String>(); String line; while (null != (line = br.readLine())) { if (line.startsWith("<")) { String token = regex.split(line, 2)[0]; codes.add(token.substring(1, token.length() - 1)); } } return codes; } finally { br.close(); } } }