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

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

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

CRS.lookupEpsgCode介绍

[英]Looks up an EPSG code for the given CoordinateReferenceSystem). This is a convenience method for #lookupIdentifier(Citations,IdentifiedObject,boolean)( Citations#EPSG, crs, fullScan) except that code is parsed as an integer.
[中]查找给定坐标引用系统的EPSG代码)。这是#lookupIdentifier(Citations,IdentifiedObject,boolean)( Citations#EPSG, crs, fullScan)的一种方便方法,只是代码被解析为整数。

代码示例

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

  1. @Override
  2. public String toString(Object obj) {
  3. CoordinateReferenceSystem crs = (CoordinateReferenceSystem) obj;
  4. try {
  5. Integer epsg = CRS.lookupEpsgCode(crs, false);
  6. if (epsg != null) {
  7. return "EPSG:" + epsg;
  8. }
  9. } catch (FactoryException e) {
  10. XStreamPersister.LOGGER.warning(
  11. "Could not determine epsg code of crs, encoding as WKT");
  12. }
  13. return new CRSConverter().toString(crs);
  14. }

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

  1. Integer code = CRS.lookupEpsgCode(crs, extensive);
  2. if (code != null) ftinfo.setSRS("EPSG:" + code);
  3. } catch (FactoryException e) {

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

  1. Integer code = CRS.lookupEpsgCode(nativeCRS, false);
  2. if (code != null) {
  3. cinfo.setSRS("EPSG:" + code);

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

  1. @Test
  2. public void testReprojectLayerGroup()
  3. throws NoSuchAuthorityCodeException, FactoryException, Exception {
  4. Catalog catalog = getCatalog();
  5. CatalogBuilder cb = new CatalogBuilder(catalog);
  6. LayerGroupInfo lg = catalog.getFactory().createLayerGroup();
  7. LayerInfo l = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS));
  8. lg.getLayers().add(l);
  9. lg.getStyles().add(null);
  10. lg.setName("test-reproject");
  11. // EPSG:4901 "equivalent" but different uom
  12. String wkt =
  13. "GEOGCS[\"GCS_ATF_Paris\",DATUM[\"D_ATF\",SPHEROID[\"Plessis_1817\",6376523.0,308.64]],PRIMEM[\"Paris\",2.337229166666667],UNIT[\"Grad\",0.01570796326794897]]";
  14. CoordinateReferenceSystem lCrs = CRS.parseWKT(wkt);
  15. ((FeatureTypeInfo) l.getResource()).setSRS(null);
  16. ((FeatureTypeInfo) l.getResource()).setNativeCRS(lCrs);
  17. assertNull(CRS.lookupEpsgCode(lCrs, false));
  18. // Use the real thing now
  19. CoordinateReferenceSystem lgCrs = CRS.decode("EPSG:4901");
  20. assertNotNull(CRS.lookupEpsgCode(lgCrs, false));
  21. // Reproject our layer group to EPSG:4901. We expect it to have an EPSG code.
  22. cb.calculateLayerGroupBounds(lg, lgCrs);
  23. assertNotNull(CRS.lookupEpsgCode(lg.getBounds().getCoordinateReferenceSystem(), false));
  24. }

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

  1. Integer code = CRS.lookupEpsgCode(nativeCRS, false);
  2. if (code != null) {
  3. cinfo.setSRS("EPSG:" + code);

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

  1. static Integer findSRID(GridCoverage2D raster) throws Exception {
  2. return CRS.lookupEpsgCode(raster.getCoordinateReferenceSystem(), true);
  3. }

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

  1. static Integer findSRID(ReferencedEnvelope e) throws Exception {
  2. return CRS.lookupEpsgCode(e.getCoordinateReferenceSystem(), true);
  3. }

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

  1. static DBObject encodeCRSToGeoJSON(CoordinateReferenceSystem crs) {
  2. if (crs == null) {
  3. return null;
  4. }
  5. Integer epsgCode = null;
  6. try {
  7. epsgCode = CRS.lookupEpsgCode(crs, true);
  8. } catch (FactoryException ignore) {
  9. }
  10. if (epsgCode == null) {
  11. return null;
  12. }
  13. DBObject crsDBO = new BasicDBObject(KEY_type, VALUE_name);
  14. crsDBO.put(
  15. KEY_properties, new BasicDBObject(KEY_name, PREFIX_URN_OGC + "EPSG:" + epsgCode));
  16. return crsDBO;
  17. }
  18. }

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

  1. /**
  2. * Computes the declared SRS of a layer based on the layer schema and the EPSG forcing flag
  3. *
  4. * @param schema
  5. * @return
  6. * @throws FactoryException
  7. * @throws NoSuchAuthorityCodeException
  8. */
  9. private CoordinateReferenceSystem getDeclaredSRS(FeatureType schema) throws FactoryException {
  10. // compute the default SRS of the feature source
  11. CoordinateReferenceSystem declaredCRS = schema.getCoordinateReferenceSystem();
  12. if (isEPSGAxisOrderForced()) {
  13. Integer code = CRS.lookupEpsgCode(declaredCRS, false);
  14. if (code != null) {
  15. declaredCRS = CRS.decode("urn:ogc:def:crs:EPSG::" + code);
  16. }
  17. }
  18. return declaredCRS;
  19. }

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

  1. private static org.opengis.geometry.Envelope getCRSEnvelope(CoordinateReferenceSystem targetCRS)
  2. throws FactoryException, NoSuchAuthorityCodeException {
  3. if (targetCRS.getDomainOfValidity() == null) {
  4. Integer code = CRS.lookupEpsgCode(targetCRS, true);
  5. if (code != null) {
  6. CRS.decode("EPSG:" + code, CRS.getAxisOrder(targetCRS) != AxisOrder.NORTH_EAST);
  7. }
  8. }
  9. org.opengis.geometry.Envelope envelope = CRS.getEnvelope(targetCRS);
  10. return envelope;
  11. }

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

  1. Integer epsgCode = CRS.lookupEpsgCode(crs, false);
  2. if (epsgCode == null) {
  3. throw new IllegalArgumentException(

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

  1. static Integer findSRID(SimpleFeatureType schema) throws Exception {
  2. CoordinateReferenceSystem crs = schema.getCoordinateReferenceSystem();
  3. if (crs == null) {
  4. GeometryDescriptor gd = findGeometryDescriptor(schema);
  5. crs = gd.getCoordinateReferenceSystem();
  6. }
  7. return crs != null ? CRS.lookupEpsgCode(crs, true) : null;
  8. }

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

  1. @Test
  2. public void testLookup() throws NoSuchAuthorityCodeException, FactoryException {
  3. CoordinateReferenceSystem crs = CRS.decode("EPSG:" + CODE);
  4. assertEquals(Integer.valueOf(CODE), CRS.lookupEpsgCode(crs, true));
  5. assertEquals(Integer.valueOf(CODE), CRS.lookupEpsgCode(crs, false));
  6. }

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

  1. CoordinateReferenceSystem crs = (CoordinateReferenceSystem) g.getUserData();
  2. try {
  3. Integer code = CRS.lookupEpsgCode(crs, false);
  4. if (code != null) {
  5. ai.addAttribute("", "srsName", "", "anyURI", "EPSG:" + code);

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

  1. gc.setSRID(CRS.lookupEpsgCode(crs, true));
  2. } catch (FactoryException e) {

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

  1. /** Encodes the given geometry with no srsName attribute and forcing 2D */
  2. public void encode(Geometry geometry) {
  3. String srsName = null;
  4. // see if we have a EPSG CRS attached to the geometry
  5. if (geometry.getUserData() instanceof CoordinateReferenceSystem) {
  6. try {
  7. CoordinateReferenceSystem crs =
  8. (CoordinateReferenceSystem) geometry.getUserData();
  9. Integer code = CRS.lookupEpsgCode(crs, false);
  10. if (code != null) {
  11. if (AxisOrder.NORTH_EAST.equals(CRS.getAxisOrder(crs))) {
  12. srsName = "urn:ogc:def:crs:EPSG::" + code;
  13. } else {
  14. srsName = "EPSG:" + code;
  15. }
  16. }
  17. } catch (Exception e) {
  18. LOGGER.fine("Failed to encode the CoordinateReferenceSystem into a srsName");
  19. }
  20. }
  21. encode(geometry, srsName);
  22. }

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

  1. /**
  2. * Looks up the geometry srs by trying a number of heuristics. Returns -1 if all attempts at
  3. * guessing the srid failed.
  4. */
  5. protected int getGeometrySRID(Geometry g, AttributeDescriptor descriptor) throws IOException {
  6. int srid = getDescriptorSRID(descriptor);
  7. if (g == null) {
  8. return srid;
  9. }
  10. // check for srid in the jts geometry then
  11. if (srid <= 0 && g.getSRID() > 0) {
  12. srid = g.getSRID();
  13. }
  14. // check if the geometry has anything
  15. if (srid <= 0 && g.getUserData() instanceof CoordinateReferenceSystem) {
  16. // check for crs object
  17. CoordinateReferenceSystem crs = (CoordinateReferenceSystem) g.getUserData();
  18. try {
  19. Integer candidate = CRS.lookupEpsgCode(crs, false);
  20. if (candidate != null) srid = candidate;
  21. } catch (Exception e) {
  22. // ok, we tried...
  23. }
  24. }
  25. return srid;
  26. }

代码示例来源: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. public void testSchema() throws Exception {
  2. SimpleFeatureType schema = dataStore.getSchema(tname(getLine3d()));
  3. CoordinateReferenceSystem crs =
  4. schema.getGeometryDescriptor().getCoordinateReferenceSystem();
  5. assertEquals(Integer.valueOf(getEpsgCode()), CRS.lookupEpsgCode(crs, false));
  6. assertEquals(
  7. getNativeSRID(),
  8. schema.getGeometryDescriptor().getUserData().get(JDBCDataStore.JDBC_NATIVE_SRID));
  9. assertEquals(
  10. 3, schema.getGeometryDescriptor().getUserData().get(Hints.COORDINATE_DIMENSION));
  11. }

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

  1. public void testSchema() throws Exception {
  2. if (!isGeographySupportAvailable()) {
  3. return;
  4. }
  5. SimpleFeatureType ft = dataStore.getFeatureSource(tname("geopoint")).getSchema();
  6. assertNotNull(ft);
  7. assertTrue(ft.getDescriptor(aname("geo")) instanceof GeometryDescriptor);
  8. assertEquals(Point.class, ft.getDescriptor("geo").getType().getBinding());
  9. int epsg =
  10. CRS.lookupEpsgCode(
  11. ((GeometryDescriptor) ft.getDescriptor(aname("geo")))
  12. .getCoordinateReferenceSystem(),
  13. false);
  14. assertEquals(4326, epsg);
  15. }

相关文章