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

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

本文整理了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

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

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

/**
   * 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;
    }
  }
}

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

/**
 * 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;
  }
}

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

/**
 * 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;
}

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

/**
 * 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;
}

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

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

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

/**
 * 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);
}

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

/**
 * 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));
}

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

/**
 *
 * <!-- 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;
}

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

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

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

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

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

/**
 * 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);
}

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

/** 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);
  }
}

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

/** 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));
}

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

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

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

/** 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");
      }
    }
  }
}

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

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;
}

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

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;
}

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

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;
}

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

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);
}

相关文章