@Test public void testEnvelopes() throws NoSuchAuthorityCodeException, FactoryException, TransformException { final GeneralEnvelope envelope3D = new GeneralEnvelope(DefaultGeographicCRS.WGS84_3D); envelope3D.setEnvelope(0, 0, 0, 10, 10, 10); final Envelope requestedEnvelope = Utilities.getRequestedEnvelope2D(envelope3D); assertEquals(0, requestedEnvelope.getMinimum(0), DELTA); assertEquals(0, requestedEnvelope.getMinimum(1), DELTA); assertEquals(10, requestedEnvelope.getMaximum(0), DELTA); assertEquals(10, requestedEnvelope.getMaximum(1), DELTA); assertEquals(10, envelope3D.getMaximum(2), DELTA); boolean is3D = true; try { requestedEnvelope.getMaximum(2); } catch (IndexOutOfBoundsException e) { is3D = false; } assertFalse(is3D); }
public static GeneralEnvelope getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope) throws FactoryException, TransformException { if (requestedEnvelope == null) throw new IllegalArgumentException("requested envelope is null"); GeneralEnvelope requestedEnvelope2D = null; 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; }
Utilities { public static GeneralEnvelope getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope) throws FactoryException, TransformException { if (requestedEnvelope == null) throw new IllegalArgumentException("requested envelope is null"); GeneralEnvelope requestedEnvelope2D = null; 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; } }
Utilities { public static GeneralEnvelope getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope) throws FactoryException, TransformException { if (requestedEnvelope == null) throw new IllegalArgumentException("requested envelope is null"); GeneralEnvelope requestedEnvelope2D = null; 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; } private  Utilities(); }
Utilities { public static GeneralEnvelope getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope) throws FactoryException, TransformException { if (requestedEnvelope == null) throw new IllegalArgumentException("requested envelope is null"); GeneralEnvelope requestedEnvelope2D = null; 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; } private  Utilities(); static ReferenceIdentifier[] getIdentifiers(final String nameIdentifier); static DefaultGeodeticDatum getDefaultGeodeticDatum(
            final String name,
            final double equatorialRadius,
            final double inverseFlattening,
            Unit unit); static File getFileFromCustomInput(Object input); @SuppressWarnings("deprecation") static CoordinateReferenceSystem getMercator2SPProjectedCRS(
            final double standardParallel,
            final double centralMeridian,
            final double natOriginLat,
            GeographicCRS sourceCRS,
            Hints hints); static GeographicCRS getBaseCRS(
            final double equatorialRadius, final double inverseFlattening); static String getAttributeValue(NamedNodeMap attributes, String attributeName); static Unit<? extends Quantity<?>> parseUnit(final String uom); static Envelope getEnvelopeAsWGS84(final Envelope envelope, boolean get2D); static GeneralEnvelope getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope); static Rectangle getCropRegion(
            GeneralEnvelope envelope, final MathTransform gridToWorldTransform); static GeneralEnvelope getIntersection(
            final Envelope2D baseEnvelope2D,
            final CoordinateReferenceSystem spatialReferenceSystem2D,
            GeneralEnvelope requestedEnvelope2D,
            Rectangle requestedDim,
            MathTransform2D readGridToWorld,
            final Envelope2D wgs84BaseEnvelope2D); static MathTransform getOriginalGridToWorld(
            MathTransform raster2Model, final PixelInCell pixInCell); static GeneralEnvelope evaluateRequestedParams(
            GridEnvelope originalGridRange,
            Envelope2D baseEnvelope2D,
            CoordinateReferenceSystem spatialReferenceSystem2D,
            MathTransform originalGridToWorld,
            GeneralEnvelope requestedEnvelope,
            Rectangle sourceRegion,
            Rectangle requestedDim,
            MathTransform2D readGridToWorld,
            Envelope2D wgs84BaseEnvelope2D); static GridCoverage createCoverageFromImage(
            final GridCoverageFactory coverageFactory,
            final String coverageName,
            int imageIndex,
            PlanarImage image,
            MathTransform raster2Model,
            final CoordinateReferenceSystem spatialReferenceSystem2D,
            GeneralEnvelope coverageEnvelope2D,
            final GridSampleDimension[] sampleDimensions); static void setDecimationParameters(
            ImageReadParam readP,
            GridEnvelope baseGridRange,
            double[] requestedRes,
            double[] highestRes); static NameImpl buildCoverageName(URL input); static void setReadParameters(
            OverviewPolicy overviewPolicy,
            ImageReadParam readParam,
            GeneralEnvelope requestedEnvelope,
            Rectangle requestedDim,
            double[] highestRes,
            GridEnvelope gridRange,
            PixelInCell pixelInCell); static GridCoverage createCoverage(
            ImageReaderSpi spi,
            Object input,
            final int imageIndex,
            ImageReadParam imageReadParam,
            final boolean useJAI,
            final boolean useMultithreading,
            final boolean newTransform,
            final GridSampleDimension[] sampleDimensions,
            final String coverageName,
            GridCoverageFactory coverageFactory,
            MathTransform raster2Model,
            CoordinateReferenceSystem coordinateReferenceSystem,
            GeneralEnvelope coverageEnvelope2D); @SuppressWarnings("PMD.CloseResource") // stream managed in the returned delayed read op static PlanarImage readImage(
            final ImageReaderSpi spi,
            final Object input,
            final int imageIndex,
            final boolean useJAI,
            final ImageReadParam imageReadParam,
            final boolean useMultithreading); static GridCoverage compute(
            Object input,
            final int imageIndex,
            final boolean needTransformation,
            final boolean isEmptyRequest,
            final boolean useJAI,
            ImageReadParam imageReadParam,
            final boolean useMultithreading,
            final GridSampleDimension[] sampleDimensions,
            final ImageReaderSpi imageReaderSpi,
            final String coverageName,
            final GridCoverageFactory coverageFactory,
            final MathTransform raster2Model,
            final CoordinateReferenceSystem coordinateReferenceSystem,
            final GeneralEnvelope envelope2D); static final boolean ensureValidString(final String... strings); static String buildIso8601Time(String date, String time); static boolean checkFileReadable(final File file); static String getFileInfo(final File file); static Properties loadPropertiesFromURL(URL propsURL); }
Utilities { public static GeneralEnvelope getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope) throws FactoryException, TransformException { if (requestedEnvelope == null) throw new IllegalArgumentException("requested envelope is null"); GeneralEnvelope requestedEnvelope2D = null; 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; } private  Utilities(); static ReferenceIdentifier[] getIdentifiers(final String nameIdentifier); static DefaultGeodeticDatum getDefaultGeodeticDatum(
            final String name,
            final double equatorialRadius,
            final double inverseFlattening,
            Unit unit); static File getFileFromCustomInput(Object input); @SuppressWarnings("deprecation") static CoordinateReferenceSystem getMercator2SPProjectedCRS(
            final double standardParallel,
            final double centralMeridian,
            final double natOriginLat,
            GeographicCRS sourceCRS,
            Hints hints); static GeographicCRS getBaseCRS(
            final double equatorialRadius, final double inverseFlattening); static String getAttributeValue(NamedNodeMap attributes, String attributeName); static Unit<? extends Quantity<?>> parseUnit(final String uom); static Envelope getEnvelopeAsWGS84(final Envelope envelope, boolean get2D); static GeneralEnvelope getRequestedEnvelope2D(GeneralEnvelope requestedEnvelope); static Rectangle getCropRegion(
            GeneralEnvelope envelope, final MathTransform gridToWorldTransform); static GeneralEnvelope getIntersection(
            final Envelope2D baseEnvelope2D,
            final CoordinateReferenceSystem spatialReferenceSystem2D,
            GeneralEnvelope requestedEnvelope2D,
            Rectangle requestedDim,
            MathTransform2D readGridToWorld,
            final Envelope2D wgs84BaseEnvelope2D); static MathTransform getOriginalGridToWorld(
            MathTransform raster2Model, final PixelInCell pixInCell); static GeneralEnvelope evaluateRequestedParams(
            GridEnvelope originalGridRange,
            Envelope2D baseEnvelope2D,
            CoordinateReferenceSystem spatialReferenceSystem2D,
            MathTransform originalGridToWorld,
            GeneralEnvelope requestedEnvelope,
            Rectangle sourceRegion,
            Rectangle requestedDim,
            MathTransform2D readGridToWorld,
            Envelope2D wgs84BaseEnvelope2D); static GridCoverage createCoverageFromImage(
            final GridCoverageFactory coverageFactory,
            final String coverageName,
            int imageIndex,
            PlanarImage image,
            MathTransform raster2Model,
            final CoordinateReferenceSystem spatialReferenceSystem2D,
            GeneralEnvelope coverageEnvelope2D,
            final GridSampleDimension[] sampleDimensions); static void setDecimationParameters(
            ImageReadParam readP,
            GridEnvelope baseGridRange,
            double[] requestedRes,
            double[] highestRes); static NameImpl buildCoverageName(URL input); static void setReadParameters(
            OverviewPolicy overviewPolicy,
            ImageReadParam readParam,
            GeneralEnvelope requestedEnvelope,
            Rectangle requestedDim,
            double[] highestRes,
            GridEnvelope gridRange,
            PixelInCell pixelInCell); static GridCoverage createCoverage(
            ImageReaderSpi spi,
            Object input,
            final int imageIndex,
            ImageReadParam imageReadParam,
            final boolean useJAI,
            final boolean useMultithreading,
            final boolean newTransform,
            final GridSampleDimension[] sampleDimensions,
            final String coverageName,
            GridCoverageFactory coverageFactory,
            MathTransform raster2Model,
            CoordinateReferenceSystem coordinateReferenceSystem,
            GeneralEnvelope coverageEnvelope2D); @SuppressWarnings("PMD.CloseResource") // stream managed in the returned delayed read op static PlanarImage readImage(
            final ImageReaderSpi spi,
            final Object input,
            final int imageIndex,
            final boolean useJAI,
            final ImageReadParam imageReadParam,
            final boolean useMultithreading); static GridCoverage compute(
            Object input,
            final int imageIndex,
            final boolean needTransformation,
            final boolean isEmptyRequest,
            final boolean useJAI,
            ImageReadParam imageReadParam,
            final boolean useMultithreading,
            final GridSampleDimension[] sampleDimensions,
            final ImageReaderSpi imageReaderSpi,
            final String coverageName,
            final GridCoverageFactory coverageFactory,
            final MathTransform raster2Model,
            final CoordinateReferenceSystem coordinateReferenceSystem,
            final GeneralEnvelope envelope2D); static final boolean ensureValidString(final String... strings); static String buildIso8601Time(String date, String time); static boolean checkFileReadable(final File file); static String getFileInfo(final File file); static Properties loadPropertiesFromURL(URL propsURL);  }