本文整理了Java中org.geotools.referencing.CRS
类的一些代码示例,展示了CRS
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CRS
类的具体详情如下:
包路径:org.geotools.referencing.CRS
类名称:CRS
[英]Simple utility class for making use of the CoordinateReferenceSystem and associated org.opengis.referencing.Factory implementations. This utility class is made up of static final functions. This class is not a factory or a builder. It makes use of the GeoAPI factory interfaces provided by ReferencingFactoryFinder.
The following methods may be added in a future version:
When using CoordinateReferenceSystem matching methods of this class ( #equalsIgnoreMetadata(Object,Object), #lookupIdentifier(IdentifiedObject,boolean), #lookupEpsgCode(CoordinateReferenceSystem,boolean), #lookupIdentifier(IdentifiedObject,boolean), #lookupIdentifier(Citation,CoordinateReferenceSystem,boolean)) against objects derived from a database other than the official EPSG one it may be advisable to set a non zero comparison tolerance with Hints#putSystemDefault(java.awt.RenderingHints.Key,Object) using the Hints#COMPARISON_TOLERANCE key. A value of 10e-9 has proved to give satisfactory results with definitions commonly found in .prj files accompaining shapefiles and georeferenced images.
Warning: the tolerance value is used in all internal comparison, this will also change the way math transforms are setup. Use with care.
[中]用于使用CoordinateReferenceSystem和关联组织的简单实用程序类。opengis。参考。工厂实现。此实用程序类由静态final函数组成。此类不是工厂或生成器。它利用了ReferenceGFactoryFinder提供的GeoAPI工厂接口。
未来版本中可能会添加以下方法:
*坐标引用系统解析XML(字符串)
使用此类的CoordinateReferenceSystem匹配方法时(#equalsIgnoreMetadata(Object,Object),#lookupIdentifier(IdentifiedObject,boolean),#lookupEpsgCode(CoordinateReferenceSystem,boolean),#lookupIdentifier(IdentifiedObject,boolean),#lookupIdentifier(引文、坐标引用系统、布尔值))针对从官方EPSG one以外的数据库派生的对象,建议使用提示#比较#容差键设置带有提示#putSystemDefault(java.awt.RenderingHints.Key、Object)的非零比较容差。10e-9的值已证明能给出令人满意的结果,其定义通常在中找到。包含形状文件和地理参考图像的prj文件。
警告:公差值用于所有内部比较,这也将更改数学变换的设置方式。小心使用。
代码示例来源:origin: geoserver/geoserver
@Test
public void testLatLonBounds() throws Exception {
ReferencedEnvelope nativeBounds =
new ReferencedEnvelope(700000, 800000, 4000000, 4100000, null);
CoordinateReferenceSystem crs = CRS.decode("EPSG:32632", true);
CatalogBuilder cb = new CatalogBuilder(getCatalog());
ReferencedEnvelope re = cb.getLatLonBounds(nativeBounds, crs);
assertEquals(DefaultGeographicCRS.WGS84, re.getCoordinateReferenceSystem());
assertEquals(11.22, re.getMinX(), 0.01);
assertEquals(36.1, re.getMinY(), 0.01);
}
代码示例来源:origin: geoserver/geoserver
/**
* Test method for {@link CoordinateOperationFactoryUsingWKT#createCoordinateOperation}.
*
* @throws TransformException
*/
@Test
public void testCreateOperationFromCustomCodes() throws Exception {
// Test CRSs
CoordinateReferenceSystem source = CRS.decode(SOURCE_CRS);
CoordinateReferenceSystem target = CRS.decode(TARGET_CRS);
MathTransform mt = CRS.findMathTransform(source, target, true);
// Test MathTransform
double[] p = new double[2];
mt.transform(SRC_TEST_POINT, 0, p, 0, 1);
assertEquals(p[0], DST_TEST_POINT[0], 1e-8);
assertEquals(p[1], DST_TEST_POINT[1], 1e-8);
}
代码示例来源:origin: geoserver/geoserver
/**
* Computes the geographic bounds of a {@link ResourceInfo} by reprojecting the available native
* bounds
*
* @param rinfo
* @return the geographic bounds, or null if the native bounds are not available
* @throws IOException
*/
public ReferencedEnvelope getLatLonBounds(
ReferencedEnvelope nativeBounds, CoordinateReferenceSystem declaredCRS)
throws IOException {
if (nativeBounds != null && declaredCRS != null) {
// make sure we use the declared CRS, not the native one, the may differ
if (!CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, declaredCRS)) {
// transform
try {
ReferencedEnvelope bounds =
new ReferencedEnvelope(nativeBounds, CRS.getHorizontalCRS(declaredCRS));
return bounds.transform(DefaultGeographicCRS.WGS84, true);
} catch (Exception e) {
throw (IOException) new IOException("transform error").initCause(e);
}
} else {
return new ReferencedEnvelope(nativeBounds, DefaultGeographicCRS.WGS84);
}
}
return null;
}
代码示例来源:origin: geoserver/geoserver
@Override
public Object fromString(String str) {
if (str.toUpperCase().startsWith("EPSG:")) {
try {
return CRS.decode(str);
} catch (Exception e) {
XStreamPersister.LOGGER.log(Level.WARNING, "Error decode epsg code: " + str, e);
}
} else {
try {
return CRS.parseWKT(str);
} catch (FactoryException e) {
XStreamPersister.LOGGER.log(Level.WARNING, "Error decode wkt: " + str, e);
}
}
return null;
}
}
代码示例来源:origin: geoserver/geoserver
final CoordinateReferenceSystem sourceCRS = envelope.getCoordinateReferenceSystem();
if (CRS.equalsIgnoreMetadata(sourceCRS, DefaultGeographicCRS.WGS84)) {
return new GeneralEnvelope(envelope);
if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) {
targetEnvelope = CRS.transform(envelope, targetCRS);
} else {
targetEnvelope = new GeneralEnvelope(envelope);
代码示例来源:origin: org.geoserver/gs-wcs2_0
@Test
public void testBasic() throws Exception {
final File xml =
new File("./src/test/resources/rangesubset/requestGetCoverageRangeSubsetting.xml");
final String request = FileUtils.readFileToString(xml);
MockHttpServletResponse response = postAsServletResponse("wcs", request);
assertEquals("image/tiff", response.getContentType());
byte[] tiffContents = getBinary(response);
File file = File.createTempFile("bm_gtiff", "bm_gtiff.tiff", new File("./target"));
FileUtils.writeByteArrayToFile(file, tiffContents);
final GeoTiffReader reader = new GeoTiffReader(file);
assertTrue(
CRS.equalsIgnoreMetadata(
reader.getCoordinateReferenceSystem(), CRS.decode("EPSG:4326", true)));
assertEquals(360, reader.getOriginalGridRange().getSpan(0));
assertEquals(360, reader.getOriginalGridRange().getSpan(1));
final GridCoverage2D coverage = reader.read(null);
assertEquals(1, coverage.getSampleDimensions().length);
GridCoverage2D sourceCoverage =
(GridCoverage2D)
this.getCatalog()
.getCoverageByName("BlueMarble")
.getGridCoverageReader(null, null)
.read(null);
assertEnvelopeEquals(sourceCoverage, coverage);
reader.dispose();
scheduleForCleaning(coverage);
scheduleForCleaning(sourceCoverage);
}
代码示例来源:origin: geotools/geotools
final CoordinateReferenceSystem sourceCRS = sourceCoverage.getCoordinateReferenceSystem();
if (targetCRS == null) {
if (targetGG != null && targetGG.isDefined(GridGeometry2D.CRS_BITMASK)) {
if (!CRS.equalsIgnoreMetadata(targetCRS, targetGGCRS)
&& !CRS.findMathTransform(targetCRS, targetGGCRS).isIdentity()) {
throw new IllegalArgumentException(
Errors.format(
return targetCoverage;
if (CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) {
gridRange = CRS.transform(allSteps.inverse(), gridRange);
targetEnvelope = CRS.transform(operation, sourceEnvelope);
targetEnvelope.setCoordinateReferenceSystem(targetCRS);
GeneralEnvelope gridRange = CRS.transform(step1.inverse(), targetEnvelope);
case DataBuffer.TYPE_FLOAT:
Envelope source = CRS.transform(sourceGG.getEnvelope(), targetCRS);
Envelope target = CRS.transform(targetGG.getEnvelope(), targetCRS);
assert CRS.equalsIgnoreMetadata(targetCoverage.getCoordinateReferenceSystem(), targetCRS)
代码示例来源:origin: geotools/geotools
/** Tests {@link CRS#getHorizontalCRS} from a Geographic 3D CR. */
public void testHorizontalFromGeodetic() throws FactoryException {
// retrives "WGS 84 (geographic 3D)"
CoordinateReferenceSystem compound = CRS.decode("EPSG:4327");
CoordinateReferenceSystem horizontal = CRS.getHorizontalCRS(compound);
// the horizonal version is basically 4326, but it won't compare positively
// with 4326, not even using CRS.equalsIgnoreMetadata(), so we check the axis directly
CoordinateSystem cs = horizontal.getCoordinateSystem();
assertEquals(2, cs.getDimension());
assertEquals(AxisDirection.NORTH, cs.getAxis(0).getDirection());
assertEquals(AxisDirection.EAST, cs.getAxis(1).getDirection());
}
代码示例来源:origin: geotools/geotools
ImageUtilities.getReferencedEnvelopeFromGeographicBoundingBox(
new GeographicBoundingBoxImpl(coverageEnvelope));
coverageGeographicCRS2D = coverageGeographicBBox.getCoordinateReferenceSystem();
coverageCRS2D = CRS.getHorizontalCRS(coverageCRS);
assert coverageCRS2D.getCoordinateSystem().getDimension() == 2;
if (coverageCRS.getCoordinateSystem().getDimension() != 2) {
final MathTransform transform =
CRS.findMathTransform(
coverageCRS, (CoordinateReferenceSystem) coverageCRS2D);
final GeneralEnvelope bbox = CRS.transform(transform, coverageEnvelope);
bbox.setCoordinateReferenceSystem(coverageCRS2D);
coverageBBox = new ReferencedEnvelope(bbox);
} else {
coverageBBox = new ReferencedEnvelope(coverageEnvelope);
代码示例来源:origin: geotools/geotools
(GridCoverage2DReader) GRID_PROPERTY_NAME.evaluate(gridWrapper);
if (CRS.equalsIgnoreMetadata(
reader.getCoordinateReferenceSystem(),
gridGeometry.getCoordinateReferenceSystem())) {
gridGeometry.getEnvelope();
GeneralEnvelope transformed =
org.geotools.referencing.CRS.transform(
atOriginal.inverse(), worldEnvelope);
int minx = (int) Math.floor(transformed.getMinimum(0));
int miny = (int) Math.floor(transformed.getMinimum(1));
int maxx = (int) Math.ceil(transformed.getMaximum(0));
int maxy = (int) Math.ceil(transformed.getMaximum(1));
Rectangle rect =
new ReferencedEnvelope(readGG.getEnvelope());
CoordinateReferenceSystem coverageCRS =
coverage.getCoordinateReferenceSystem2D();
if (!CRS.equalsIgnoreMetadata(
renderingEnvelope.getCoordinateReferenceSystem(), coverageCRS)) {
renderingEnvelope = renderingEnvelope.transform(coverageCRS, true);
if (coverage.getEnvelope2D().intersects(renderingEnvelope)) {
代码示例来源:origin: geotools/geotools
cropEnvelope = (GeneralEnvelope) envelope;
} else if (envelope instanceof Envelope) {
cropEnvelope = new GeneralEnvelope((Envelope) envelope);
Envelope e2d =
JTS.getEnvelope2D(
cropRoi.getEnvelopeInternal(), source.getCoordinateReferenceSystem());
cropEnvelope = new GeneralEnvelope(e2d);
final Envelope2D sourceEnvelope = source.getEnvelope2D();
destinationCRS = source.getCoordinateReferenceSystem2D();
ge.setCoordinateReferenceSystem(destinationCRS);
destinationEnvelope = ge;
if (!CRS.equalsIgnoreMetadata(sourceCRS, destinationCRS)) {
throw new CannotCropException(
Errors.format(
ErrorKeys.MISMATCHED_ENVELOPE_CRS_$2,
sourceCRS.getName().getCode(),
destinationCRS.getName().getCode()));
new GeneralEnvelope((Envelope) destinationEnvelope);
intersectionEnvelope.setCoordinateReferenceSystem(source.getCoordinateReferenceSystem());
(AffineTransform)
((GridGeometry2D) source.getGridGeometry())
.getGridToCRS(PixelInCell.CELL_CORNER);
代码示例来源:origin: geotools/geotools
@Test
public void testConic() throws Exception {
// setup a request large enough to cause severe reprojection deformation
CoordinateReferenceSystem crs = CRS.decode("EPSG:32632", true);
ReferencedEnvelope mapExtent = new ReferencedEnvelope(-1.5e7, 1.5e7, 0, 1e6, crs);
// System.out.println(mapExtent.transform(DefaultGeographicCRS.WGS84, true));
GridCoverageReaderHelper helper =
new GridCoverageReaderHelper(
reader,
new Rectangle(400, 200),
mapExtent,
Interpolation.getInstance(Interpolation.INTERP_NEAREST));
// read single coverage with no projection handling, we should get the full requested area
GridCoverage2D coverage = helper.readCoverage(null);
Envelope2D envelope = coverage.getEnvelope2D();
// System.out.println(envelope);
assertTrue(envelope.getMinX() < -100);
assertTrue(envelope.getMaxX() > 100);
// now read via the projection handlers
ProjectionHandler handler =
ProjectionHandlerFinder.getHandler(
mapExtent, reader.getCoordinateReferenceSystem(), true);
List<GridCoverage2D> coverages = helper.readCoverages(null, handler);
// System.out.println(coverages);
assertEquals(1, coverages.size());
envelope = coverages.get(0).getEnvelope2D();
// west/east limited to 45 degrees from the central meridian
assertEquals(-36, envelope.getMinX(), EPS);
assertEquals(54, envelope.getMaxX(), EPS);
}
代码示例来源:origin: geotools/geotools
graphics.dispose();
CoordinateReferenceSystem nativeCrs = CRS.decode("EPSG:4326", true);
ReferencedEnvelope mapExtent = new ReferencedEnvelope(0, 90, 0, 90, nativeCrs);
GridCoverage2D coverage =
CoverageFactoryFinder.getGridCoverageFactory(null)
.create("test", bi, new ReferencedEnvelope(0, 90, 0, 90, nativeCrs));
assertEquals(coverage.getNumSampleDimensions(), 3);
GridCoverage2DReader reader = new GeoTiffReader(coverageFile);
代码示例来源:origin: geotools/geotools
final MathTransform transformTo2D;
CoordinateReferenceSystem requestedEnvelopeCRS2D =
requestedEnvelope.getCoordinateReferenceSystem();
if (requestedEnvelopeCRS2D.getCoordinateSystem().getDimension() != 2) {
transformTo2D =
CRS.findMathTransform(
requestedEnvelopeCRS2D, CRS.getHorizontalCRS(requestedEnvelopeCRS2D));
requestedEnvelopeCRS2D = CRS.getHorizontalCRS(requestedEnvelopeCRS2D);
} else transformTo2D = IdentityTransform.create(2);
if (!transformTo2D.isIdentity()) {
requestedEnvelope2D = CRS.transform(transformTo2D, requestedEnvelope);
requestedEnvelope2D.setCoordinateReferenceSystem(requestedEnvelopeCRS2D);
} else requestedEnvelope2D = new GeneralEnvelope(requestedEnvelope);
assert requestedEnvelopeCRS2D.getCoordinateSystem().getDimension() == 2;
return requestedEnvelope2D;
代码示例来源:origin: geotools/geotools
"test",
new float[200][100],
new ReferencedEnvelope(
-180, 180, -90, 90, DefaultGeographicCRS.WGS84));
GridCoverage2DReader reader =
new GeneralEnvelope((BoundingBox) coverage.getEnvelope2D());
this.originalGridRange = coverage.getGridGeometry().getGridRange();
CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true);
ReferencedEnvelope mapExtent =
new ReferencedEnvelope(-20000000, 20000000, -20000000, 20000000, crs);
代码示例来源:origin: geoserver/geoserver
CoordinateReferenceSystem crs = CRS.decode(srs);
wli.setSRS(srs);
wli.setNativeCRS(crs);
wli.setSRS("EPSG:4326");
srs = "EPSG:4326";
wli.setNativeCRS(CRS.decode("EPSG:4326"));
} else if (srs.equals("CRS:83")) {
wli.setSRS("EPSG:4269");
srs = "EPSG:4269";
wli.setNativeCRS(CRS.decode("EPSG:4269"));
} else if (srs.equals("CRS:27")) {
wli.setSRS("EPSG:4267");
srs = "EPSG:4267";
wli.setNativeCRS(CRS.decode("EPSG:4267"));
if (llbbox != null) {
ReferencedEnvelope re =
new ReferencedEnvelope(
llbbox.getMinX(),
llbbox.getMaxX(),
try {
wli.setLatLonBoundingBox(
wli.getNativeBoundingBox().transform(DefaultGeographicCRS.WGS84, true));
} catch (Exception e) {
LOGGER.log(Level.INFO, "Could not transform native bbox into a lat/lon one", e);
代码示例来源:origin: geotools/geotools
ReferencedEnvelope targetEnvelope = ReferencedEnvelope.reference(renderingEnvelope);
ReferencedEnvelope coveragesEnvelope = null;
for (GridCoverage2D coverage : coverages) {
ReferencedEnvelope re = ReferencedEnvelope.reference(coverage.getEnvelope2D());
if (coveragesEnvelope == null) {
coveragesEnvelope = re;
} else {
coveragesEnvelope.expandToInclude(re);
new ReferencedEnvelope(
targetEnvelope.intersection(coveragesEnvelope),
renderingEnvelope.getCoordinateReferenceSystem());
if (targetEnvelope.isEmpty() || targetEnvelope.isNull()) {
return null;
MathTransform2D mt = coverages.get(0).getGridGeometry().getCRSToGrid2D();
Rectangle rasterSpaceEnvelope;
rasterSpaceEnvelope = CRS.transform(mt, targetEnvelope).toRectangle2D().getBounds();
GridEnvelope2D gridRange = new GridEnvelope2D(rasterSpaceEnvelope);
GridGeometry2D gridGeometry = new GridGeometry2D(gridRange, targetEnvelope);
代码示例来源:origin: geotools/geotools
CoordinateReferenceSystem nativeCrs = CRS.decode("EPSG:26915", true);
GridCoverage2D coverage =
CoverageFactoryFinder.getGridCoverageFactory(null)
"test",
bi,
new ReferencedEnvelope(
baseX,
baseX + bi.getWidth(),
MathTransform r2m = coverage.getGridGeometry().getGridToCRS();
Envelope env = new Envelope(25, 75, 25, 75);
ReferencedEnvelope read26915 = new ReferencedEnvelope(JTS.transform(env, r2m), nativeCrs);
CoordinateReferenceSystem mapCRS = CRS.decode("EPSG:3857", true);
ReferencedEnvelope read3857 = read26915.transform(mapCRS, true);
Layer layer =
new GridReaderLayer(
new GeoTiffReader(testFile), sb.createStyle(sb.createRasterSymbolizer()));
MapContent mc = new MapContent();
mc.getViewport().setBounds(read3857);
代码示例来源:origin: opentripplanner/OpenTripPlanner
@Override
public void createIndividuals() {
try {
coverageCRS = CRS.decode(crsCode, true);
} catch (Exception e) {
LOG.error("error decoding coordinate reference system code.", e);
return;
}
if (boundsFromGraph) {
// autowire graph service or pass in
}
gridEnvelope = new GridEnvelope2D(0, 0, cols, rows);
refEnvelope = new ReferencedEnvelope(left, right, bottom, top, coverageCRS);
gridGeometry = new GridGeometry2D(gridEnvelope, refEnvelope);
super.createIndividuals0();
}
代码示例来源:origin: geotools/geotools
coverageGeographicCRS2D =
coverageGeographicBBox != null
? coverageGeographicBBox.getCoordinateReferenceSystem()
: null;
coverageCRS2D = CRS.getHorizontalCRS(coverageCRS);
assert coverageCRS2D.getCoordinateSystem().getDimension() == 2;
if (coverageCRS.getCoordinateSystem().getDimension() != 2) {
final MathTransform transform = CRS.findMathTransform(coverageCRS, coverageCRS2D);
final GeneralEnvelope bbox = CRS.transform(transform, coverageEnvelope);
coverageBBox = ReferencedEnvelope.create(bbox, coverageCRS2D);
} else {
ReferencedEnvelope.create(
coverageEnvelope, coverageEnvelope.getCoordinateReferenceSystem());
内容来源于网络,如有侵权,请联系作者删除!