GeneralEnvelope envelope = reader.getOriginalEnvelope(); GeneralEnvelope wgs84envelope = CoverageStoreUtils.getWGS84LonLatEnvelope(envelope); final String nativeCrsName = CRS.lookupIdentifier(crs, false); writer.write( "<envelope crs=\""
/** * Returns true if the specified CRS can be used directly to perform WMS requests. Natively * supported crs will provide the best rendering quality as no client side reprojection is * necessary, the image coming from the WMS server will be used as-is * * @param crs * @return */ public boolean isNativelySupported(CoordinateReferenceSystem crs) { try { String code = CRS.lookupIdentifier(crs, false); return code != null && getReader().validSRS.contains(code); } catch (Throwable t) { return false; } } }
/** * Returns true if the specified CRS can be used directly to perform WMTS requests. * * <p>Natively supported crs will provide the best rendering quality as no client side * reprojection is necessary, the tiles coming from the WMTS server will be used as-is * * @param crs * @return */ public boolean isNativelySupported(CoordinateReferenceSystem crs) { try { String code = CRS.lookupIdentifier(crs, false); return code != null && getReader().validSRS.contains(code); } catch (Exception t) { return false; } }
/** * Create a properties map for the provided crs. * * @param crs CoordinateReferenceSystem or null for default * @return properties map naming crs identifier * @throws IOException */ Map<String, Object> createCRS(CoordinateReferenceSystem crs) throws IOException { Map<String, Object> obj = new LinkedHashMap<String, Object>(); obj.put("type", "name"); Map<String, Object> props = new LinkedHashMap<String, Object>(); if (crs == null) { props.put("name", "EPSG:4326"); } else { try { String identifier = CRS.lookupIdentifier(crs, true); props.put("name", identifier); } catch (FactoryException e) { throw (IOException) new IOException("Error looking up crs identifier").initCause(e); } } obj.put("properties", props); return obj; }
/** * Looks up an EPSG code for the given {@linkplain CoordinateReferenceSystem coordinate * reference system}). This is a convenience method for <code>{@linkplain * #lookupIdentifier(Citations, IdentifiedObject, boolean) lookupIdentifier}({@linkplain * Citations#EPSG}, crs, fullScan)</code> except that code is parsed as an integer. * * @param crs The coordinate reference system instance, or {@code null}. * @return The CRS identifier, or {@code null} if none was found. * @throws FactoryException if an error occured while searching for the identifier. * @since 2.5 */ public static Integer lookupEpsgCode( final CoordinateReferenceSystem crs, final boolean fullScan) throws FactoryException { final String identifier = lookupIdentifier(Citations.EPSG, crs, fullScan); if (identifier != null) { final int split = identifier.lastIndexOf(GenericName.DEFAULT_SEPARATOR); final String code = identifier.substring(split + 1); // The above code works even if the separator was not found, since in such case // split == -1, which implies a call to substring(0) which returns 'identifier'. try { return Integer.parseInt(code); } catch (NumberFormatException e) { throw new FactoryException( Errors.format(ErrorKeys.ILLEGAL_IDENTIFIER_$1, identifier), e); } } return null; }
String srs = null; try { srs = CRS.lookupIdentifier(getCoordinateReferenceSystem(), false); } catch (FactoryException e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e);
/** * GEOT-1702, make sure looking up for an existing code does not result in a {@link * StackOverflowException}. * * @throws FactoryException If the CRS can't be created. */ @Test public void testLookupSuccessfull() throws FactoryException { CoordinateReferenceSystem crs = CRS.decode("EPSG:42101"); String code = CRS.lookupIdentifier(crs, true); assertEquals("EPSG:42101", code); }
/** * GEOT-1702, make sure looking up for a non existing code does not result in a {@link * StackOverflowException}. * * @throws FactoryException If the CRS can't be created. */ @Test public void testLookupFailing() throws FactoryException { CoordinateReferenceSystem crs = CRS.parseWKT(WKT.MERCATOR_GOOGLE); assertNull(CRS.lookupIdentifier(crs, true)); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { SpatialSubsetType spatialSubset = Wcs10Factory.eINSTANCE.createSpatialSubsetType(); List<Node> envelopes = node.getChildren("Envelope"); for (Node envelopeNode : envelopes) { ReferencedEnvelope envelope = (ReferencedEnvelope) envelopeNode.getValue(); EnvelopeType env = Gml4wcsFactory.eINSTANCE.createEnvelopeType(); env.setSrsName(CRS.lookupIdentifier(envelope.getCoordinateReferenceSystem(), true)); DirectPositionType pos1 = Gml4wcsFactory.eINSTANCE.createDirectPositionType(); DirectPositionType pos2 = Gml4wcsFactory.eINSTANCE.createDirectPositionType(); pos1.setDimension(BigInteger.valueOf(2)); pos2.setDimension(BigInteger.valueOf(2)); pos1.setValue(Arrays.asList(envelope.getMinX(), envelope.getMinY())); pos2.setValue(Arrays.asList(envelope.getMaxX(), envelope.getMaxY())); env.getPos().add(pos1); env.getPos().add(pos2); spatialSubset.getEnvelope().add(envelope); } List<Node> gridsNode = node.getChildren("Grid"); for (Node grid : gridsNode) spatialSubset.getGrid().add(grid.getValue()); return spatialSubset; }
return CRS.lookupIdentifier(envelope.getCoordinateReferenceSystem(), true); } catch (FactoryException e) { return null;
} else { code = CRS.lookupIdentifier(bbox.getCoordinateReferenceSystem(), false);
/** * Encodes the internal object representation of a parameter as a string. */ public String encode(Object value) throws Exception { if (value == null) { return null; } return CRS.lookupIdentifier(((CoordinateReferenceSystem) value), true); }
/** Encodes the internal object representation of a parameter as a string. */ public String encode(Object value) throws Exception { if (value == null) { return null; } return CRS.lookupIdentifier(((CoordinateReferenceSystem) value), true); } }
/** Tests {@link CRS#lookupIdentifier}. */ public void testFind() throws FactoryException { CoordinateReferenceSystem crs = getED50("ED50"); assertEquals( "Should find without scan thanks to the name.", "EPSG:4230", CRS.lookupIdentifier(crs, false)); assertEquals(Integer.valueOf(4230), CRS.lookupEpsgCode(crs, false)); crs = getED50("ED50 with unknown name"); if (supportsED50QuickScan()) { assertEquals( "With scan allowed, should find the CRS.", "EPSG:4230", CRS.lookupIdentifier(crs, false)); assertEquals(Integer.valueOf(4230), CRS.lookupEpsgCode(crs, false)); } else { assertNull("Should not find the CRS without a scan.", CRS.lookupIdentifier(crs, false)); assertEquals(null, CRS.lookupEpsgCode(crs, false)); } assertEquals( "With scan allowed, should find the CRS.", "EPSG:4230", CRS.lookupIdentifier(crs, true)); assertEquals(Integer.valueOf(4230), CRS.lookupEpsgCode(crs, true)); }
code = CRS.lookupIdentifier(bbox.getCoordinateReferenceSystem(), false);
/** Sets the CRS. */ private void setCRS() { if (mapPane != null && mapPane.getMapContent() != null) { String initial = null; CoordinateReferenceSystem crs = mapPane.getMapContent().getCoordinateReferenceSystem(); if (crs != null) { try { initial = CRS.lookupIdentifier(Citations.EPSG, crs, false); } catch (Exception ex) { // do nothing } } CoordinateReferenceSystem newCRS = JCRSChooser.showDialog(null, initial, "EPSG"); if (newCRS != null && (crs == null || !CRS.equalsIgnoreMetadata(crs, newCRS))) { try { mapPane.getMapContent().getViewport().setCoordinateReferenceSystem(newCRS); } catch (Exception ex) { JExceptionReporter.showDialog(ex, "Failed to set the requested CRS"); } } } }
private String urnIdentifier(final CoordinateReferenceSystem crs) throws FactoryException { String authorityAndCode = CRS.lookupIdentifier(crs, false); String code = authorityAndCode.substring(authorityAndCode.lastIndexOf(":") + 1); // we don't specify the version, but we still need to put a space // for it in the urn form, that's why we have :: before the code return "urn:ogc:def:crs:EPSG::" + code; }
private String urnIdentifier(final CoordinateReferenceSystem crs) throws FactoryException { String authorityAndCode = CRS.lookupIdentifier(crs, false); String code = authorityAndCode.substring(authorityAndCode.lastIndexOf(":") + 1); // we don't specify the version, but we still need to put a space // for it in the urn form, that's why we have :: before the code return "urn:ogc:def:crs:EPSG::" + code; }
protected String urnIdentifier(final CoordinateReferenceSystem crs) throws FactoryException { String authorityAndCode = CRS.lookupIdentifier(crs, false); String code = authorityAndCode.substring(authorityAndCode.lastIndexOf(":") + 1); // we don't specify the version, but we still need to put a space // for it in the urn form, that's why we have :: before the code return "urn:ogc:def:crs:EPSG::" + code; }
public SimpleFeatureType apply(ImportTask task, DataStore dataStore, SimpleFeatureType featureType) throws Exception { //update the layer metadata ResourceInfo r = task.getLayer().getResource(); r.setNativeCRS(target); r.setSRS(CRS.lookupIdentifier(target, true)); if (r.getNativeBoundingBox() != null) { r.setNativeBoundingBox(r.getNativeBoundingBox().transform(target, true)); } //retype the schema return SimpleFeatureTypeBuilder.retype(featureType, target); }