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

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

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

CRS.parseWKT介绍

[英]Parses a Well Known Text (WKT) into a CRS object. This convenience method is a shorthand for the following: FactoryFinder. ReferencingFactoryFinder#getCRSFactory(null). org.opengis.referencing.crs.CRSFactory#createFromWKT(wkt);
[中]将{$0$}(WKT)解析为CRS对象。此方便方法是以下内容的简写:FactoryFinder. ReferencingFactoryFinder#getCRSFactory(null). org.opengis.referencing.crs.CRSFactory#createFromWKT(wkt);

代码示例

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

  1. @Override
  2. public Object fromString(String str) {
  3. if (str.toUpperCase().startsWith("EPSG:")) {
  4. try {
  5. return CRS.decode(str);
  6. } catch (Exception e) {
  7. XStreamPersister.LOGGER.log(Level.WARNING, "Error decode epsg code: " + str, e);
  8. }
  9. } else {
  10. try {
  11. return CRS.parseWKT(str);
  12. } catch (FactoryException e) {
  13. XStreamPersister.LOGGER.log(Level.WARNING, "Error decode wkt: " + str, e);
  14. }
  15. }
  16. return null;
  17. }
  18. }

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

  1. @Override
  2. public Object fromString(String str) {
  3. try {
  4. return CRS.parseWKT(str);
  5. } catch (Exception e) {
  6. try {
  7. return new SRSConverter().fromString(str);
  8. } catch (Exception e1) {
  9. }
  10. throw new RuntimeException(e);
  11. }
  12. }
  13. }

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

  1. if ((paramValues.get(index) != null)
  2. && (((String) paramValues.get(index)).length() > 0)) {
  3. value = CRS.parseWKT((String) paramValues.get(index));

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

  1. if (key.equalsIgnoreCase("crs")) {
  2. if ((params.get(key) != null) && (((String) params.get(key)).length() > 0)) {
  3. value = CRS.parseWKT((String) params.get(key));
  4. } else {
  5. LOGGER.info("Unable to find a crs for the coverage param, using EPSG:4326");

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

  1. @Test
  2. public void testSRSConverter() throws Exception {
  3. CoordinateReferenceSystem crs = CRS.decode("EPSG:4901");
  4. SRSConverter c = new SRSConverter();
  5. assertEquals("EPSG:4901", c.toString(crs));
  6. // definition with odd UOM that won't be matched to the EPSG one
  7. assertFalse(
  8. "EPSG:4901"
  9. .equals(
  10. c.toString(
  11. CRS.parseWKT(
  12. "GEOGCS[\"GCS_ATF_Paris\",DATUM[\"D_ATF\",SPHEROID[\"Plessis_1817\",6376523.0,308.64]],PRIMEM[\"Paris\",2.337229166666667],UNIT[\"Grad\",0.01570796326794897]]"))));
  13. }

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

  1. CoordinateReferenceSystem crs = CRS.parseWKT(nativeCrsWkt);
  2. coverage.setNativeCRS(crs);

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

  1. @Test
  2. public void testInitCoverageSRSLookup_GEOS8973() throws Exception {
  3. Catalog cat = getCatalog();
  4. CatalogBuilder cb = new CatalogBuilder(cat);
  5. cb.setStore(cat.getCoverageStoreByName(MockData.WORLD.getLocalPart()));
  6. CoverageInfo cinfo = cb.buildCoverage();
  7. cinfo.setSRS(null);
  8. String wkt =
  9. "GEOGCS[\"ED50\",\n"
  10. + " DATUM[\"European Datum 1950\",\n"
  11. + " SPHEROID[\"International 1924\", 6378388.0, 297.0]],\n"
  12. + "PRIMEM[\"Greenwich\", 0.0],\n"
  13. + "UNIT[\"degree\", 0.017453292519943295]]";
  14. CoordinateReferenceSystem testCRS = CRS.parseWKT(wkt);
  15. cinfo.setNativeCRS(testCRS);
  16. cb.initCoverage(cinfo, "srs lookup");
  17. assertEquals("EPSG:4230", cinfo.getSRS());
  18. }

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

  1. private CoordinateReferenceSystem getLambertPolar() throws FactoryException {
  2. String crsWKT =
  3. "PROJCS[\"North_Pole_Lambert_Azimuthal_Equal_Area\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\","
  4. + "SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],"
  5. + "PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],"
  6. + "PARAMETER[\"Central_Meridian\",0],PARAMETER[\"Latitude_Of_Origin\",90],UNIT[\"Meter\",1]]";
  7. return CRS.parseWKT(crsWKT);
  8. }

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

  1. /** Returns a ED50 CRS with the specified name. */
  2. private static CoordinateReferenceSystem getED50(final String name) throws FactoryException {
  3. final String wkt =
  4. "GEOGCS[\""
  5. + name
  6. + "\",\n"
  7. + " DATUM[\"European Datum 1950\",\n"
  8. + " SPHEROID[\"International 1924\", 6378388.0, 297.0]],\n"
  9. + "PRIMEM[\"Greenwich\", 0.0],\n"
  10. + "UNIT[\"degree\", 0.017453292519943295]]";
  11. return CRS.parseWKT(wkt);
  12. }

代码示例来源: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: geotools/geotools

  1. static Geometry reprojectAndDensify(
  2. Geometry first,
  3. CoordinateReferenceSystem sourceCRS,
  4. CoordinateReferenceSystem targetCRS)
  5. throws FactoryException, TransformException {
  6. if (targetCRS == null) {
  7. targetCRS = CRS.parseWKT(ECKERT_IV_WKT);
  8. }
  9. MathTransform firstTransform = CRS.findMathTransform(sourceCRS, targetCRS);
  10. Geometry geometry = JTS.transform(densify(first, sourceCRS, 0.01d), firstTransform);
  11. return geometry;
  12. }

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

  1. /** Tests the {@link CRS#parseWKT} method. */
  2. public void testWKT() throws FactoryException {
  3. String wkt =
  4. "GEOGCS[\"WGS 84\",\n"
  5. + " DATUM[\"WGS_1984\",\n"
  6. + " SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],\n"
  7. + " TOWGS84[0,0,0,0,0,0,0], AUTHORITY[\"EPSG\",\"6326\"]],\n"
  8. + " PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],\n"
  9. + " UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],\n"
  10. + " AXIS[\"Lat\",NORTH], AXIS[\"Long\",EAST],\n"
  11. + " AUTHORITY[\"EPSG\",\"4326\"]]";
  12. CoordinateReferenceSystem crs = CRS.parseWKT(wkt);
  13. assertNotNull(crs);
  14. }

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

  1. @Test
  2. public void parseWKT() throws Exception {
  3. String[] wkts = {
  4. "PROJCS[\"Wagner_IV\", GEOGCS[\"WGS84\", DATUM[\"WGS84\", SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"degree\",0.017453292519943295], AXIS[\"Longitude\",EAST], AXIS[\"Latitude\",NORTH]], PROJECTION[\"Wagner_IV\"], UNIT[\"m\", 1.0], AXIS[\"Easting\", EAST], AXIS[\"Northing\", NORTH]]",
  5. "PROJCS[\"Wagner_V\", GEOGCS[\"WGS84\", DATUM[\"WGS84\", SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"degree\",0.017453292519943295], AXIS[\"Longitude\",EAST], AXIS[\"Latitude\",NORTH]], PROJECTION[\"Wagner_V\"], UNIT[\"m\", 1.0], AXIS[\"Easting\", EAST], AXIS[\"Northing\", NORTH]]"
  6. };
  7. for (String wkt : wkts) {
  8. assertNotNull(CRS.parseWKT(wkt));
  9. }
  10. }

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

  1. @Test
  2. public void testLambertParsing() throws FactoryException {
  3. String initialLambertWkt =
  4. "PROJCS[\"LAMBERT WKT\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\","
  5. + "SPHEROID[\"WGS_1984\",6371200.0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\","
  6. + "0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic\"],"
  7. + "PARAMETER[\"standard_parallel_1\",25.0],PARAMETER[\"latitude_of_origin\",25.0],"
  8. + "PARAMETER[\"central_meridian\",-95.0],PARAMETER[\"false_easting\",0],"
  9. + "PARAMETER[\"false_northing\",0],PARAMETER[\"Scale_Factor\",1.0],UNIT[\"m\",1]]";
  10. CoordinateReferenceSystem lambertCRS = CRS.parseWKT(initialLambertWkt);
  11. String parsedLambertWkt = lambertCRS.toWKT();
  12. CoordinateReferenceSystem lambertCRS2 = CRS.parseWKT(parsedLambertWkt);
  13. assertTrue(CRS.equalsIgnoreMetadata(lambertCRS, lambertCRS2));
  14. }

代码示例来源: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. public void testLenient() throws Exception {
  2. CoordinateReferenceSystem lenientTarget;
  3. lenientTarget =
  4. CRS.parseWKT(
  5. "PROJCS[\"MGI (Ferro) / Austria GK West Zone\",GEOGCS[\"MGI (Ferro)\",DATUM[\"Militar_Geographische_Institut_Ferro\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",\"7004\"]],AUTHORITY[\"EPSG\",\"6805\"]],PRIMEM[\"Ferro\",-17.66666666666667,AUTHORITY[\"EPSG\",\"8909\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4805\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",28],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",-5000000],AUTHORITY[\"EPSG\",\"31251\"],AXIS[\"Y\",EAST],AXIS[\"X\",NORTH]]");
  6. SimpleFeatureIterator reproject =
  7. new ReprojectingFeatureCollection(delegate, lenientTarget).features();
  8. reproject.close();
  9. }

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

  1. @BeforeClass
  2. public static void setupClass() throws FactoryException, TransformException {
  3. sphericalGeosCRS = CRS.parseWKT(sphericalGeosWKT);
  4. sphericalGeosToGeog =
  5. CRS.findMathTransform(
  6. sphericalGeosCRS, CRS.getProjectedCRS(sphericalGeosCRS).getBaseCRS(), true);
  7. geogToSphericalGeos = sphericalGeosToGeog.inverse();
  8. ellipsoidalGeosCRS = CRS.parseWKT(ellipsoidalGeosWKT);
  9. ellipsoidalGeosToGeog =
  10. CRS.findMathTransform(
  11. ellipsoidalGeosCRS,
  12. CRS.getProjectedCRS(ellipsoidalGeosCRS).getBaseCRS(),
  13. true);
  14. geogToEllipsoidalGeos = ellipsoidalGeosToGeog.inverse();
  15. }

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

  1. protected void setUp() throws Exception {
  2. super.setUp();
  3. target =
  4. CRS.parseWKT(
  5. "PROJCS[\"BC_Albers\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101],TOWGS84[0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Albers_Conic_Equal_Area\"],PARAMETER[\"False_Easting\",1000000],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-126],PARAMETER[\"Standard_Parallel_1\",50],PARAMETER[\"Standard_Parallel_2\",58.5],PARAMETER[\"Latitude_Of_Origin\",45],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"42102\"]]");
  6. MathTransform2D tx =
  7. (MathTransform2D)
  8. ReferencingFactoryFinder.getCoordinateOperationFactory(null)
  9. .createOperation(crs, target)
  10. .getMathTransform();
  11. transformer = new GeometryCoordinateSequenceTransformer();
  12. transformer.setMathTransform(tx);
  13. transformer.setCoordinateReferenceSystem(target);
  14. }

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

  1. @Test
  2. public void testTransformExtraMZ() throws Exception {
  3. LiteCoordinateSequence cs = new LiteCoordinateSequence(1, 4);
  4. cs.setArray(new double[] {1000000, 4000000, 25, 48});
  5. CoordinateReferenceSystem sourceCrs = CRS.parseWKT(JTSTest.UTM_ZONE_10N);
  6. CoordinateReferenceSystem destCrs = DefaultGeographicCRS.WGS84;
  7. DefaultCoordinateSequenceTransformer cst;
  8. cst = new DefaultCoordinateSequenceTransformer(new LiteCoordinateSequenceFactory());
  9. MathTransform tx = CRS.findMathTransform(sourceCrs, destCrs, true);
  10. LiteCoordinateSequence transformed = (LiteCoordinateSequence) cst.transform(cs, tx);
  11. assertEquals(25.0, transformed.getOrdinate(0, 2), 0.0);
  12. assertEquals(48.0, transformed.getOrdinate(0, 3), 0.0);
  13. }

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

  1. @Test
  2. public void testLiteToStandard() throws Exception {
  3. LiteCoordinateSequence cs = new LiteCoordinateSequence(1, 2);
  4. cs.setArray(new double[] {1000000, 4000000});
  5. CoordinateReferenceSystem sourceCrs = CRS.parseWKT(JTSTest.UTM_ZONE_10N);
  6. CoordinateReferenceSystem destCrs = DefaultGeographicCRS.WGS84;
  7. DefaultCoordinateSequenceTransformer cst;
  8. cst = new DefaultCoordinateSequenceTransformer(/* standard cs factory */ );
  9. MathTransform tx = CRS.findMathTransform(sourceCrs, destCrs, true);
  10. CoordinateSequence transformed = cst.transform(cs, tx);
  11. CoordinateSequence reference = transform(cs, tx);
  12. assertEquals(reference.getOrdinate(0, 0), transformed.getOrdinate(0, 0), 0.0);
  13. assertEquals(reference.getOrdinate(0, 1), transformed.getOrdinate(0, 1), 0.0);
  14. }

相关文章