private int indexOf(CoordinateReferenceSystem crs, Set<AxisDirection> direction) { CoordinateSystem cs = crs.getCoordinateSystem(); for (int index = 0; index < cs.getDimension(); index++) { CoordinateSystemAxis axis = cs.getAxis(index); if (direction.contains(axis.getDirection())) return index; } return -1; } }
if (!CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, coverageCRS)) { try { CRS.findMathTransform( coverageCRS, DefaultGeographicCRS.WGS84, true); if (!transform.isIdentity()) { final CoordinateSystem coordinateSystem = coverageCRS.getCoordinateSystem(); final int dimension = coordinateSystem.getDimension(); for (int i = 0; i < dimension; i++) { CoordinateSystemAxis axis = coordinateSystem.getAxis(i); if (axis.getDirection().absolute().compareTo(AxisDirection.NORTH) == 0) { this.northDimension = i; new IOException( "Unable to find nort dimension in the coverage CRS+ " + coverageCRS.toWKT()); throw ioe;
/** * Convenience method for checking coordinate reference system validity. * * @throws IllegalArgumentException if the CRS dimension is not valid. */ protected void checkCoordinateReferenceSystemDimension() throws MismatchedDimensionException { if (crs != null) { final int expected = getDimension(); final int dimension = crs.getCoordinateSystem().getDimension(); if (dimension > expected) { // check dimensions and choose ReferencedEnvelope or ReferencedEnvelope3D // or the factory method ReferencedEnvelope.reference( CoordinateReferenceSystem ) throw new MismatchedDimensionException( Errors.format( ErrorKeys.MISMATCHED_DIMENSION_$3, crs.getName().getCode(), Integer.valueOf(dimension), Integer.valueOf(expected))); } } }
return null; if (isForcedLonLat() && CRS.getAxisOrder(crs, false) == AxisOrder.NORTH_EAST) { try { Integer code = CRS.lookupEpsgCode(crs, false); if (code != null) { return "urn:ogc:def:crs:EPSG::" + code; Set<ReferenceIdentifier> identifiers = crs.getIdentifiers(); if (identifiers.isEmpty()) { final ReferenceIdentifier name = crs.getName(); if (name != null) { return name.toString(); } else { for (ReferenceIdentifier identifier : crs.getIdentifiers()) { String srs = identifier.toString(); if (srs.contains("EPSG:") || srs.contains("CRS:")) { ReferenceIdentifier name = crs.getName(); if (name != null && (name.toString().contains("EPSG:") || name.toString().contains("CRS:"))) {
/** Tests the (latitude, longitude) axis order for EPSG:4326. */ public void testCorrectAxisOrder() throws NoSuchAuthorityCodeException, FactoryException { final CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); final CoordinateSystem cs = crs.getCoordinateSystem(); assertEquals(2, cs.getDimension()); CoordinateSystemAxis axis0 = cs.getAxis(0); assertEquals("Lat", axis0.getAbbreviation()); CoordinateSystemAxis axis1 = cs.getAxis(1); assertEquals("Long", axis1.getAbbreviation()); }
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);
+ requestedExtent + " " + reqCrs.getCoordinateSystem().getAxis(0).getDirection() + " (" + reqCrs.getName() + ")"); "Layer CRS not matching: " + "req:" + reqCrs.getName() + " cov:" + layerEnv.getCoordinateReferenceSystem().getName()); Level.WARNING, "Requested extent can't be projected to tile CRS (" + reqCrs.getCoordinateSystem().getName() + " -> " + tileCrs.getCoordinateSystem().getName() + ") :" + ex.getMessage()); .getCoordinateSystem() .getAxis(0) .getDirection() + " (" + reqExtentInTileCrs.getCoordinateReferenceSystem().getName() + ")"); .getCoordinateSystem()
return size; CoordinateReferenceSystem horizontal = CRS.getHorizontalCRS(crs); if (horizontal != null) { crs = horizontal; Unit<Length> unit = (Unit<Length>) crs.getCoordinateSystem().getAxis(0).getUnit(); if (unit == null) { LOGGER.finer(
GeneralEnvelope envelope = reader.getOriginalEnvelope(); GeneralEnvelope wgs84envelope = CoverageStoreUtils.getWGS84LonLatEnvelope(envelope); final String nativeCrsName = CRS.lookupIdentifier(crs, false); writer.write( "<envelope crs=\"" writer.write( "<pos>" + wgs84envelope.getMinimum(0) + " " + wgs84envelope.getMinimum(1) + "</pos>\n"); writer.write( "<pos>" + wgs84envelope.getMaximum(0) + " " + wgs84envelope.getMaximum(1) writer.write("<low>" + lower + "</low>\n"); writer.write("<high>" + upper + "</high>\n"); final CoordinateSystem cs = crs.getCoordinateSystem(); for (int i = 0; i < cs.getDimension(); i++) { writer.write("<axisName>" + cs.getAxis(i).getName().getCode() + "</axisName>\n");
throws TransformException, FactoryException { if (crs == null) { if (isEmpty()) { return new ReferencedEnvelope(targetCRS); } else { if (getDimension() != targetCRS.getCoordinateSystem().getDimension()) { if (lenient) { return JTS.transformTo3D(this, targetCRS, lenient, numPointsForTransformation); Errors.format( ErrorKeys.MISMATCHED_DIMENSION_$3, crs.getName().getCode(), Integer.valueOf(getDimension()), Integer.valueOf(targetCRS.getCoordinateSystem().getDimension()))); CRS.getCoordinateOperationFactory(lenient); final GeneralEnvelope transformed = CRS.transform(operation, this); transformed.setCoordinateReferenceSystem(targetCRS);
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); requestedEnvelope2D = CRS.transform(transformTo2D, requestedEnvelope); requestedEnvelope2D.setCoordinateReferenceSystem(requestedEnvelopeCRS2D); } else requestedEnvelope2D = new GeneralEnvelope(requestedEnvelope); assert requestedEnvelopeCRS2D.getCoordinateSystem().getDimension() == 2; return requestedEnvelope2D;
final CoordinateReferenceSystem crs2D = CRS.getHorizontalCRS(destinationCrs); if (crs2D == null) throw new TransformException( Errors.format(ErrorKeys.CANT_REDUCE_TO_TWO_DIMENSIONS_$1, destinationCrs)); final boolean lonFirst = crs2D.getCoordinateSystem() .getAxis(0) .getDirection() .absolute() .equals(AxisDirection.EAST); final GeneralEnvelope newEnvelope = lonFirst ? new GeneralEnvelope( new double[] {mapExtent.getMinX(), mapExtent.getMinY()}, new double[] {mapExtent.getMaxX(), mapExtent.getMaxY()}) : new GeneralEnvelope( new double[] {mapExtent.getMinY(), mapExtent.getMinX()}, new double[] {mapExtent.getMaxY(), mapExtent.getMaxX()}); newEnvelope.setCoordinateReferenceSystem(destinationCrs);
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());
@Test public void testCRSConverter() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); CRSConverter c = new CRSConverter(); assertEquals(crs.toWKT(), c.toString(crs)); assertEquals(DefaultGeographicCRS.WGS84.toWKT(), c.toString(DefaultGeographicCRS.WGS84)); CoordinateReferenceSystem crs2 = (CoordinateReferenceSystem) c.fromString(crs.toWKT()); assertTrue(CRS.equalsIgnoreMetadata(crs, crs2)); crs2 = (CoordinateReferenceSystem) c.fromString("EPSG:4326"); assertTrue(CRS.equalsIgnoreMetadata(crs, crs2)); }
/** * Factory method to create the correct ReferencedEnvelope implementation for the provided * CoordinateReferenceSystem. * * @param crs CoordinateReferenceSystem used to select ReferencedEnvelope implementation * @return ReferencedEnvelope, ReferencedEnvelope3D if it is 3d */ public static ReferencedEnvelope create(CoordinateReferenceSystem crs) { if (crs != null && crs.getCoordinateSystem().getDimension() > 2) { return new ReferencedEnvelope3D(crs); } return new ReferencedEnvelope(crs); }
CoordinateSystem coordinateSystem = crs.getCoordinateSystem(); boolean longFirst = coordinateSystem.getAxis(0).getDirection().equals(AxisDirection.EAST); if (longFirst) { tileMatrixMinX = tileMatrix.getTopLeft().getX(); tileMatrixMinX = tileMatrix.getTopLeft().getY(); ReferencedEnvelope ret = new ReferencedEnvelope(crs); double minX = tileIdentifier.getX() * tileSpanX + tileMatrixMinX; double maxY = tileMatrixMaxY - tileIdentifier.getY() * tileSpanY; double minY = maxY - tileSpanY; if (longFirst) { ret.expandToInclude(minX, minY); ret.expandToInclude(maxX, maxY); } else { ret.expandToInclude(minY, minX);
if (CRS.equalsIgnoreMetadata(this.crs, (this.crs = crs))) { return; final CoordinateSystem cs = crs.getCoordinateSystem(); epochs = null; toMillis = null; formats = new Format[cs.getDimension()]; types = new byte[formats.length]; for (int i = 0; i < formats.length; i++) { final Unit<?> unit = cs.getAxis(i).getUnit(); final AxisDirection axis = cs.getAxis(i).getDirection().absolute(); if (AxisDirection.EAST.equals(axis)) { types[i] = LONGITUDE;
if (getDimension() != targetCRS.getCoordinateSystem().getDimension()) { if (lenient) { return JTS.transformTo2D(this, targetCRS, lenient, numPointsForTransformation); Errors.format( ErrorKeys.MISMATCHED_DIMENSION_$3, crs.getName().getCode(), Integer.valueOf(getDimension()), Integer.valueOf(targetCRS.getCoordinateSystem().getDimension()))); CRS.getCoordinateOperationFactory(lenient); final GeneralEnvelope transformed = CRS.transform(operation, this); transformed.setCoordinateReferenceSystem(targetCRS);
/** * Replacement for geometry.getEnvelopeInternal() that returns ReferencedEnvelope or * ReferencedEnvelope3D as appropriate for the provided CRS. * * @param geometry * @param crs * @return ReferencedEnvelope (or ReferencedEnvelope3D) as appropriate */ public static ReferencedEnvelope bounds(Geometry geometry, CoordinateReferenceSystem crs) { if (geometry == null) { return null; } if (crs == null) { return new ReferencedEnvelope(geometry.getEnvelopeInternal(), null); // CRS is not known } else if (crs.getCoordinateSystem().getDimension() >= 3) { ReferencedEnvelope bounds = new ReferencedEnvelope3D(crs); // Note we are visiting all coordinates (rather than just the outer rings // polygons) as holes may contribute to the min / max bounds. for (Coordinate coordinate : geometry.getCoordinates()) { bounds.expandToInclude(coordinate); } return bounds; } else { return new ReferencedEnvelope(geometry.getEnvelopeInternal(), crs); } }
Integer code = CRS.lookupEpsgCode(nativeCRS, false); if (code != null) { cinfo.setSRS("EPSG:" + code); if (nativeCRS != null && !nativeCRS.getIdentifiers().isEmpty()) { cinfo.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED); GeneralEnvelope envelope = reader.getOriginalEnvelope(); cinfo.setNativeBoundingBox(new ReferencedEnvelope(envelope)); cinfo.setLatLonBoundingBox( new ReferencedEnvelope(CoverageStoreUtils.getWGS84LonLatEnvelope(envelope))); } else if (cinfo.getLatLonBoundingBox() == null) { setupBounds(cinfo); } else if (cinfo.getNativeBoundingBox() == null && cinfo.getNativeCRS() != null) { ReferencedEnvelope boundsLatLon = cinfo.getLatLonBoundingBox(); cinfo.setNativeBoundingBox(boundsLatLon.transform(cinfo.getNativeCRS(), true));