org.geotools.referencing.CRS.lookupIdentifier()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(437)

本文整理了Java中org.geotools.referencing.CRS.lookupIdentifier()方法的一些代码示例,展示了CRS.lookupIdentifier()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CRS.lookupIdentifier()方法的具体详情如下:
包路径:org.geotools.referencing.CRS
类名称:CRS
方法名:lookupIdentifier

CRS.lookupIdentifier介绍

[英]Looks up an identifier of the specified authority for the given CoordinateReferenceSystem). This method is similar to #lookupIdentifier(IdentifiedObject,boolean)(object, fullScan) except that the search is performed only among the factories of the given authority.

If the CRS does not have an ReferenceIdentifier which corresponds to the Citations#EPSG authority, then:

  • if fullScan is true, then this method scans the factories in search for an object #equalsIgnoreMetadata, to the given object. If one is found, its identifier is returned.
  • Otherwise (if fullScan is false or if no identifier was found in the previous step), this method returns null.
    [中]查找给定CoordinationReferenceSystem)的指定权限的标识符。此方法与#lookupIdentifier(IdentifiedObject,boolean)(object, fullScan)类似,只是搜索仅在给定权限的工厂中执行。
    如果CRS没有与引文#EPSG机构对应的参考标识,则:
    *如果fullScan为true,则此方法扫描工厂以搜索给定对象的对象#equalsIgnoreMetadata。如果找到一个,则返回其标识符。
    *否则(如果fullScan为false或在上一步中未找到标识符),此方法将返回null。

代码示例

代码示例来源:origin: geoserver/geoserver

  1. GeneralEnvelope envelope = reader.getOriginalEnvelope();
  2. GeneralEnvelope wgs84envelope = CoverageStoreUtils.getWGS84LonLatEnvelope(envelope);
  3. final String nativeCrsName = CRS.lookupIdentifier(crs, false);
  4. writer.write(
  5. "<envelope crs=\""

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Returns true if the specified CRS can be used directly to perform WMS requests. Natively
  3. * supported crs will provide the best rendering quality as no client side reprojection is
  4. * necessary, the image coming from the WMS server will be used as-is
  5. *
  6. * @param crs
  7. * @return
  8. */
  9. public boolean isNativelySupported(CoordinateReferenceSystem crs) {
  10. try {
  11. String code = CRS.lookupIdentifier(crs, false);
  12. return code != null && getReader().validSRS.contains(code);
  13. } catch (Throwable t) {
  14. return false;
  15. }
  16. }
  17. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Returns true if the specified CRS can be used directly to perform WMTS requests.
  3. *
  4. * <p>Natively supported crs will provide the best rendering quality as no client side
  5. * reprojection is necessary, the tiles coming from the WMTS server will be used as-is
  6. *
  7. * @param crs
  8. * @return
  9. */
  10. public boolean isNativelySupported(CoordinateReferenceSystem crs) {
  11. try {
  12. String code = CRS.lookupIdentifier(crs, false);
  13. return code != null && getReader().validSRS.contains(code);
  14. } catch (Exception t) {
  15. return false;
  16. }
  17. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Create a properties map for the provided crs.
  3. *
  4. * @param crs CoordinateReferenceSystem or null for default
  5. * @return properties map naming crs identifier
  6. * @throws IOException
  7. */
  8. Map<String, Object> createCRS(CoordinateReferenceSystem crs) throws IOException {
  9. Map<String, Object> obj = new LinkedHashMap<String, Object>();
  10. obj.put("type", "name");
  11. Map<String, Object> props = new LinkedHashMap<String, Object>();
  12. if (crs == null) {
  13. props.put("name", "EPSG:4326");
  14. } else {
  15. try {
  16. String identifier = CRS.lookupIdentifier(crs, true);
  17. props.put("name", identifier);
  18. } catch (FactoryException e) {
  19. throw (IOException) new IOException("Error looking up crs identifier").initCause(e);
  20. }
  21. }
  22. obj.put("properties", props);
  23. return obj;
  24. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Looks up an EPSG code for the given {@linkplain CoordinateReferenceSystem coordinate
  3. * reference system}). This is a convenience method for <code>{@linkplain
  4. * #lookupIdentifier(Citations, IdentifiedObject, boolean) lookupIdentifier}({@linkplain
  5. * Citations#EPSG}, crs, fullScan)</code> except that code is parsed as an integer.
  6. *
  7. * @param crs The coordinate reference system instance, or {@code null}.
  8. * @return The CRS identifier, or {@code null} if none was found.
  9. * @throws FactoryException if an error occured while searching for the identifier.
  10. * @since 2.5
  11. */
  12. public static Integer lookupEpsgCode(
  13. final CoordinateReferenceSystem crs, final boolean fullScan) throws FactoryException {
  14. final String identifier = lookupIdentifier(Citations.EPSG, crs, fullScan);
  15. if (identifier != null) {
  16. final int split = identifier.lastIndexOf(GenericName.DEFAULT_SEPARATOR);
  17. final String code = identifier.substring(split + 1);
  18. // The above code works even if the separator was not found, since in such case
  19. // split == -1, which implies a call to substring(0) which returns 'identifier'.
  20. try {
  21. return Integer.parseInt(code);
  22. } catch (NumberFormatException e) {
  23. throw new FactoryException(
  24. Errors.format(ErrorKeys.ILLEGAL_IDENTIFIER_$1, identifier), e);
  25. }
  26. }
  27. return null;
  28. }

代码示例来源:origin: geotools/geotools

  1. String srs = null;
  2. try {
  3. srs = CRS.lookupIdentifier(getCoordinateReferenceSystem(), false);
  4. } catch (FactoryException e) {
  5. java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e);

代码示例来源:origin: geotools/geotools

  1. /**
  2. * GEOT-1702, make sure looking up for an existing code does not result in a {@link
  3. * StackOverflowException}.
  4. *
  5. * @throws FactoryException If the CRS can't be created.
  6. */
  7. @Test
  8. public void testLookupSuccessfull() throws FactoryException {
  9. CoordinateReferenceSystem crs = CRS.decode("EPSG:42101");
  10. String code = CRS.lookupIdentifier(crs, true);
  11. assertEquals("EPSG:42101", code);
  12. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * GEOT-1702, make sure looking up for a non existing code does not result in a {@link
  3. * StackOverflowException}.
  4. *
  5. * @throws FactoryException If the CRS can't be created.
  6. */
  7. @Test
  8. public void testLookupFailing() throws FactoryException {
  9. CoordinateReferenceSystem crs = CRS.parseWKT(WKT.MERCATOR_GOOGLE);
  10. assertNull(CRS.lookupIdentifier(crs, true));
  11. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. *
  3. * <!-- begin-user-doc -->
  4. * <!-- end-user-doc -->
  5. *
  6. * @generated modifiable
  7. */
  8. public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
  9. SpatialSubsetType spatialSubset = Wcs10Factory.eINSTANCE.createSpatialSubsetType();
  10. List<Node> envelopes = node.getChildren("Envelope");
  11. for (Node envelopeNode : envelopes) {
  12. ReferencedEnvelope envelope = (ReferencedEnvelope) envelopeNode.getValue();
  13. EnvelopeType env = Gml4wcsFactory.eINSTANCE.createEnvelopeType();
  14. env.setSrsName(CRS.lookupIdentifier(envelope.getCoordinateReferenceSystem(), true));
  15. DirectPositionType pos1 = Gml4wcsFactory.eINSTANCE.createDirectPositionType();
  16. DirectPositionType pos2 = Gml4wcsFactory.eINSTANCE.createDirectPositionType();
  17. pos1.setDimension(BigInteger.valueOf(2));
  18. pos2.setDimension(BigInteger.valueOf(2));
  19. pos1.setValue(Arrays.asList(envelope.getMinX(), envelope.getMinY()));
  20. pos2.setValue(Arrays.asList(envelope.getMaxX(), envelope.getMaxY()));
  21. env.getPos().add(pos1);
  22. env.getPos().add(pos2);
  23. spatialSubset.getEnvelope().add(envelope);
  24. }
  25. List<Node> gridsNode = node.getChildren("Grid");
  26. for (Node grid : gridsNode) spatialSubset.getGrid().add(grid.getValue());
  27. return spatialSubset;
  28. }

代码示例来源:origin: geotools/geotools

  1. return CRS.lookupIdentifier(envelope.getCoordinateReferenceSystem(), true);
  2. } catch (FactoryException e) {
  3. return null;

代码示例来源:origin: geotools/geotools

  1. } else {
  2. code = CRS.lookupIdentifier(bbox.getCoordinateReferenceSystem(), false);

代码示例来源:origin: org.geoserver.extension/wps-core

  1. /**
  2. * Encodes the internal object representation of a parameter as a string.
  3. */
  4. public String encode(Object value) throws Exception {
  5. if (value == null) {
  6. return null;
  7. }
  8. return CRS.lookupIdentifier(((CoordinateReferenceSystem) value), true);
  9. }

代码示例来源:origin: org.geoserver.extension/gs-wps-core

  1. /** Encodes the internal object representation of a parameter as a string. */
  2. public String encode(Object value) throws Exception {
  3. if (value == null) {
  4. return null;
  5. }
  6. return CRS.lookupIdentifier(((CoordinateReferenceSystem) value), true);
  7. }
  8. }

代码示例来源:origin: geotools/geotools

  1. /** Tests {@link CRS#lookupIdentifier}. */
  2. public void testFind() throws FactoryException {
  3. CoordinateReferenceSystem crs = getED50("ED50");
  4. assertEquals(
  5. "Should find without scan thanks to the name.",
  6. "EPSG:4230",
  7. CRS.lookupIdentifier(crs, false));
  8. assertEquals(Integer.valueOf(4230), CRS.lookupEpsgCode(crs, false));
  9. crs = getED50("ED50 with unknown name");
  10. if (supportsED50QuickScan()) {
  11. assertEquals(
  12. "With scan allowed, should find the CRS.",
  13. "EPSG:4230",
  14. CRS.lookupIdentifier(crs, false));
  15. assertEquals(Integer.valueOf(4230), CRS.lookupEpsgCode(crs, false));
  16. } else {
  17. assertNull("Should not find the CRS without a scan.", CRS.lookupIdentifier(crs, false));
  18. assertEquals(null, CRS.lookupEpsgCode(crs, false));
  19. }
  20. assertEquals(
  21. "With scan allowed, should find the CRS.",
  22. "EPSG:4230",
  23. CRS.lookupIdentifier(crs, true));
  24. assertEquals(Integer.valueOf(4230), CRS.lookupEpsgCode(crs, true));
  25. }

代码示例来源:origin: geotools/geotools

  1. code = CRS.lookupIdentifier(bbox.getCoordinateReferenceSystem(), false);

代码示例来源:origin: geotools/geotools

  1. /** Sets the CRS. */
  2. private void setCRS() {
  3. if (mapPane != null && mapPane.getMapContent() != null) {
  4. String initial = null;
  5. CoordinateReferenceSystem crs = mapPane.getMapContent().getCoordinateReferenceSystem();
  6. if (crs != null) {
  7. try {
  8. initial = CRS.lookupIdentifier(Citations.EPSG, crs, false);
  9. } catch (Exception ex) {
  10. // do nothing
  11. }
  12. }
  13. CoordinateReferenceSystem newCRS = JCRSChooser.showDialog(null, initial, "EPSG");
  14. if (newCRS != null && (crs == null || !CRS.equalsIgnoreMetadata(crs, newCRS))) {
  15. try {
  16. mapPane.getMapContent().getViewport().setCoordinateReferenceSystem(newCRS);
  17. } catch (Exception ex) {
  18. JExceptionReporter.showDialog(ex, "Failed to set the requested CRS");
  19. }
  20. }
  21. }
  22. }

代码示例来源:origin: org.geoserver/wcs1_1

  1. private String urnIdentifier(final CoordinateReferenceSystem crs) throws FactoryException {
  2. String authorityAndCode = CRS.lookupIdentifier(crs, false);
  3. String code = authorityAndCode.substring(authorityAndCode.lastIndexOf(":") + 1);
  4. // we don't specify the version, but we still need to put a space
  5. // for it in the urn form, that's why we have :: before the code
  6. return "urn:ogc:def:crs:EPSG::" + code;
  7. }

代码示例来源:origin: org.geoserver/gs-wcs1_0

  1. private String urnIdentifier(final CoordinateReferenceSystem crs) throws FactoryException {
  2. String authorityAndCode = CRS.lookupIdentifier(crs, false);
  3. String code = authorityAndCode.substring(authorityAndCode.lastIndexOf(":") + 1);
  4. // we don't specify the version, but we still need to put a space
  5. // for it in the urn form, that's why we have :: before the code
  6. return "urn:ogc:def:crs:EPSG::" + code;
  7. }

代码示例来源:origin: org.geoserver/gs-wcs1_1

  1. protected String urnIdentifier(final CoordinateReferenceSystem crs)
  2. throws FactoryException {
  3. String authorityAndCode = CRS.lookupIdentifier(crs, false);
  4. String code = authorityAndCode.substring(authorityAndCode.lastIndexOf(":") + 1);
  5. // we don't specify the version, but we still need to put a space
  6. // for it in the urn form, that's why we have :: before the code
  7. return "urn:ogc:def:crs:EPSG::" + code;
  8. }

代码示例来源:origin: org.geoserver.importer/importer-core

  1. public SimpleFeatureType apply(ImportTask task, DataStore dataStore,
  2. SimpleFeatureType featureType) throws Exception {
  3. //update the layer metadata
  4. ResourceInfo r = task.getLayer().getResource();
  5. r.setNativeCRS(target);
  6. r.setSRS(CRS.lookupIdentifier(target, true));
  7. if (r.getNativeBoundingBox() != null) {
  8. r.setNativeBoundingBox(r.getNativeBoundingBox().transform(target, true));
  9. }
  10. //retype the schema
  11. return SimpleFeatureTypeBuilder.retype(featureType, target);
  12. }

相关文章