/** * Returns the first projected coordinate reference system found in a the given CRS, or {@code * null} if there is none. * * @param crs The coordinate reference system, or {@code null}. * @return The projected CRS, or {@code null} if none. * @since 2.4 */ public static ProjectedCRS getProjectedCRS(final CoordinateReferenceSystem crs) { if (crs instanceof ProjectedCRS) { return (ProjectedCRS) crs; } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getCoordinateReferenceSystems()) { final ProjectedCRS candidate = getProjectedCRS(c); if (candidate != null) { return candidate; } } } return null; }
/** * Returns the {@link MapProjection} driving the specified crs, or {@code null} if none could be * found. * * @param crs The coordinate reference system, or {@code null}. * @return The {@link MapProjection}, or {@code null} if none. */ public static MapProjection getMapProjection(final CoordinateReferenceSystem crs) { ProjectedCRS projectedCRS = CRS.getProjectedCRS(crs); if (projectedCRS == null) return null; Projection conversion = projectedCRS.getConversionFromBase(); MathTransform mt = conversion.getMathTransform(); return unrollProjection(mt); }
private static boolean isPole(DirectPosition point, CoordinateReferenceSystem crs) { DirectPosition result = new DirectPosition2D(); GeographicCRS geographic; try { ProjectedCRS projectedCRS = getProjectedCRS(crs); if (projectedCRS != null) { geographic = projectedCRS.getBaseCRS(); MathTransform mt = CRS.findMathTransform(projectedCRS, geographic); mt.transform(point, result); } else if (crs instanceof GeographicCRS) { result = point; geographic = (GeographicCRS) crs; } else { return false; } } catch (MismatchedDimensionException | TransformException | FactoryException e) { return false; } final double EPS = 1e-6; if (getAxisOrder(geographic) == AxisOrder.NORTH_EAST) { return Math.abs(result.getOrdinate(0) - 90) < EPS || Math.abs(result.getOrdinate(0) + 90) < EPS; } else { return Math.abs(result.getOrdinate(1) - 90) < EPS || Math.abs(result.getOrdinate(1) + 90) < EPS; } }
if (CRS.getProjectedCRS(geometryCRS) != null) { precision = 1e-3; } else {
@BeforeClass public static void setupClass() throws FactoryException, TransformException { sphericalGeosCRS = CRS.parseWKT(sphericalGeosWKT); sphericalGeosToGeog = CRS.findMathTransform( sphericalGeosCRS, CRS.getProjectedCRS(sphericalGeosCRS).getBaseCRS(), true); geogToSphericalGeos = sphericalGeosToGeog.inverse(); ellipsoidalGeosCRS = CRS.parseWKT(ellipsoidalGeosWKT); ellipsoidalGeosToGeog = CRS.findMathTransform( ellipsoidalGeosCRS, CRS.getProjectedCRS(ellipsoidalGeosCRS).getBaseCRS(), true); geogToEllipsoidalGeos = ellipsoidalGeosToGeog.inverse(); }
/** Circumscribed rectangle (smallest) for full disk earth image */ public static Envelope2D circumscribeFullDisk(CoordinateReferenceSystem geosCRS) throws TransformException, FactoryException { if (!isGeostationaryCRS(geosCRS)) { return null; } MathTransform mt = CRS.findMathTransform(geosCRS, CRS.getProjectedCRS(geosCRS).getBaseCRS(), true); MathTransform imt = mt.inverse(); ParameterValueGroup parameters = CRS.getMapProjection(geosCRS).getParameterValues(); double semiMajorAxis = parameters.parameter("semi_major").doubleValue(); double satelliteHeight = parameters.parameter("satellite_height").doubleValue(); double centralMeridian = parameters.parameter("central_meridian").doubleValue(); DirectPosition2D dp2d = new DirectPosition2D(); double halfFoVRadians = Math.acos(semiMajorAxis / (satelliteHeight + semiMajorAxis)); double halfFoVDegrees = Math.toDegrees(halfFoVRadians); dp2d.setLocation(centralMeridian - halfFoVDegrees, 0.); imt.transform(dp2d, dp2d); double xMin = dp2d.getX(); dp2d.setLocation(centralMeridian + halfFoVDegrees, 0.); imt.transform(dp2d, dp2d); double xMax = dp2d.getX(); dp2d.setLocation(centralMeridian, -halfFoVDegrees); imt.transform(dp2d, dp2d); double yMin = dp2d.getY(); dp2d.setLocation(centralMeridian, halfFoVDegrees); imt.transform(dp2d, dp2d); double yMax = dp2d.getY(); return new Envelope2D(geosCRS, xMin, yMin, xMax - xMin, yMax - yMin); }
public Object getValue(final GridCoverage coverage) { final ProjectedCRS crs; crs = CRS.getProjectedCRS(coverage.getCoordinateReferenceSystem()); return (crs!=null) ? crs.getConversionFromBase() : null; } };
/** * Returns the value for this key from the specified grid coverage. */ public Object getValue(final GridCoverage coverage) { final ProjectedCRS crs = CRS.getProjectedCRS(coverage.getCoordinateReferenceSystem()); if (crs != null) { final ParameterValueGroup parameters = crs.getConversionFromBase().getParameterValues(); try { return parameters.parameter(toString()).getValue(); } catch (ParameterNotFoundException exception) { // No value set for the specified parameter. // This is not an error. Just ignore... } } return null; } }