Class CoverageUtilities
- java.lang.Object
-
- org.hortonmachine.gears.utils.coverage.CoverageUtilities
-
public class CoverageUtilities extends Object
A class of utilities bound to raster analysis
- Since:
- 0.1
- Author:
- Andrea Antonello - www.hydrologis.com
-
-
Constructor Summary
Constructors Constructor Description CoverageUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.geotools.coverage.grid.GridCoverage2Dapply(org.geotools.coverage.grid.GridCoverage2D coverage, DoubleUnaryOperator operator)Apply an operation to the coverage's values.static org.geotools.coverage.grid.GridCoverage2DbuildCoverage(String name, double[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol)Creates acoveragefrom a double[][] matrix and the necessary geographic Information.static org.geotools.coverage.grid.GridCoverage2DbuildCoverage(String name, float[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol)Creates acoveragefrom a float[][] matrix and the necessary geographic Information.static org.geotools.coverage.grid.GridCoverage2DbuildCoverage(String name, int[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol)static org.geotools.coverage.grid.GridCoverage2DbuildCoverage(String name, RenderedImage renderedImage, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs)Creates acoveragefrom theimageand the necessary geographic Information.static org.geotools.coverage.grid.GridCoverage2DbuildCoverage(String name, WritableRaster writableRaster, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs)Creates acoveragefrom thewritable rasterand the necessary geographic Information.static org.geotools.coverage.grid.GridCoverage2DbuildCoverageWithNovalue(String name, double[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol, double novalue)static org.geotools.coverage.grid.GridCoverage2DbuildCoverageWithNovalue(String name, int[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol, int novalue)static org.geotools.coverage.grid.GridCoverage2DbuildCoverageWithNovalue(String name, RenderedImage renderedImage, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, double novalue)static org.geotools.coverage.grid.GridCoverage2DbuildCoverageWithNovalue(String name, WritableRaster writableRaster, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, double novalue)Creates acoveragefrom thewritable rasterand the necessary geographic Information.static org.geotools.coverage.grid.GridCoverage2DbuildDummyCoverage()Creates a uselessGridCoverage2Dthat might be usefull as placeholder.static double[][]calculateHypsographic(org.geotools.coverage.grid.GridCoverage2D elevationCoverage, int bins, IHMProgressMonitor pm)Calculates the hypsographic curve for the given raster, using the supplied bins.static org.geotools.coverage.grid.GridCoverage2DclipCoverage(org.geotools.coverage.grid.GridCoverage2D coverage, org.geotools.geometry.jts.ReferencedEnvelope envelope)Clip a coverage to a given envelope.static int[]colRowFromCoordinate(org.locationtech.jts.geom.Coordinate coordinate, org.geotools.coverage.grid.GridGeometry2D gridGeometry, Point point)Utility method to get col and row of a coordinate from aGridGeometry2D.static org.locationtech.jts.geom.CoordinatecoordinateFromColRow(int col, int row, org.geotools.coverage.grid.GridGeometry2D gridGeometry)Utility method to get the coordinate of a col and row from aGridGeometry2D.static org.geotools.coverage.grid.GridCoverage2DcoverageValuesMapper(org.geotools.coverage.grid.GridCoverage2D valuesMap, org.geotools.coverage.grid.GridCoverage2D maskMap)Mappes the values of a map (valuesMap) into the valid pixels of the second map (maskMap).static org.geotools.coverage.grid.GridCoverage2DcreateCoverageFromTemplate(org.geotools.coverage.grid.GridCoverage2D template, Double value, WritableRaster[] writableRasterHolder)Creates a newGridCoverage2Dusing an existing as template.static org.opengis.parameter.GeneralParameterValue[]createGridGeometryGeneralParameter(double xres, double yres, double north, double south, double east, double west, org.opengis.referencing.crs.CoordinateReferenceSystem crs)Utility method to create read parameters forGridCoverageReaderstatic org.opengis.parameter.GeneralParameterValue[]createGridGeometryGeneralParameter(int width, int height, double north, double south, double east, double west, org.opengis.referencing.crs.CoordinateReferenceSystem crs)Utility method to create read parameters forGridCoverageReaderstatic org.opengis.parameter.GeneralParameterValue[]createGridGeometryGeneralParameter(RegionMap regionMap, org.opengis.referencing.crs.CoordinateReferenceSystem crs)Utility method to create read parameters forGridCoverageReaderstatic org.geotools.coverage.grid.GridCoverage2DcreateSubCoverageFromTemplate(org.geotools.coverage.grid.GridCoverage2D template, org.geotools.geometry.Envelope2D subregion, Double value, WritableRaster[] writableRasterHolder)Create a subcoverage given a template coverage and an envelope.static WritableRastercreateWritableRaster(int width, int height, Class<?> dataClass, SampleModel sampleModel, Object value)Creates awritable raster.static WritableRastercreateWritableRasterFromArray(int width, int height, int[] pixels)Create aWritableRasterfrom a int array.static WritableRastercreateWritableRasterFromMatrix(double[][] matrix, boolean matrixIsRowCol)Create aWritableRasterfrom a double matrix.static WritableRastercreateWritableRasterFromMatrix(float[][] matrix, boolean matrixIsRowCol)Create aWritableRasterfrom a float matrix.static WritableRastercreateWritableRasterFromMatrix(int[][] matrix, boolean matrixIsRowCol)static List<ProfilePoint>doProfile(javax.media.jai.iterator.RandomIter mapIter, org.geotools.coverage.grid.GridGeometry2D gridGeometry, org.locationtech.jts.geom.Coordinate... coordinates)Calculates the profile of a raster map between givencoordinates.static List<ProfilePoint>doProfile(org.geotools.coverage.grid.GridCoverage2D coverage, org.locationtech.jts.geom.Coordinate... coordinates)Calculates the profile of a raster map between givencoordinates.static WritableRasterdoubleArray2WritableRaster(double[] array, int width, int height)Transforms an array of values into aWritableRaster.static booleanequals(WritableRaster wr1, WritableRaster wr2)Checks two rasters for equality of content.static List<org.locationtech.jts.geom.Coordinate>extractPolygonOnCoverage(javax.media.jai.iterator.RandomIter coverageIterator, int cols, int rows, double xRes, org.geotools.coverage.grid.GridGeometry2D gridGeometry, org.locationtech.jts.geom.Polygon polygon, double defaultValue)Extracts the positions and values of a polygon mapped on a raster(rasterization).static RegionMapgeneralParameterValues2RegionParamsMap(org.opengis.parameter.GeneralParameterValue[] params)static org.geotools.coverage.grid.GridCoverage2DgetGridCoverage(org.geotools.coverage.grid.io.GridCoverage2DReader reader, double north, double south, double east, double west, double xRes, double yRes, org.opengis.referencing.crs.CoordinateReferenceSystem crs)Get aGridCoverage2Dfrom a reader.static int[]getLoopColsRowsForSubregion(org.geotools.coverage.grid.GridCoverage2D gridCoverage, org.geotools.geometry.Envelope2D subregion)Get the cols and rows ranges to use to loop the original gridcoverage.static DoublegetNovalue(org.geotools.coverage.grid.GridCoverage2D raster)Get the novalue defined for the raster.static javax.media.jai.iterator.RandomItergetRandomIterator(org.geotools.coverage.grid.GridCoverage2D coverage)Creates aRandomIterfor the givenGridCoverage2D.static double[]getRegionArrayFromGridCoverage(org.geotools.coverage.grid.GridCoverage2D gridCoverage)Get the array of region parameters covered by thecoverage.static int[]getRegionColsRows(org.geotools.coverage.grid.GridCoverage2D gridCoverage)Get the array of rows and cols.static RegionMapgetRegionParamsFromGridCoverage(org.geotools.coverage.grid.GridCoverage2D gridCoverage)Get the parameters of the region covered by thecoverage.static RegionMapgetRegionParamsFromImageMosaicReader(org.geotools.gce.imagemosaic.ImageMosaicReader reader)Get the parameters of the region covered by theImageMosaicReader.static org.locationtech.jts.geom.PolygongetRegionPolygon(org.geotools.coverage.grid.GridCoverage2D gridCoverage)Create a bounds polygon of aGridCoverage2D.static doublegetValue(org.geotools.coverage.grid.GridCoverage2D raster, double easting, double northing)Simple method to get a value from a single band raster.static doublegetValue(org.geotools.coverage.grid.GridCoverage2D raster, int col, int row)Simple method to get a value from a single band raster.static doublegetValue(org.geotools.coverage.grid.GridCoverage2D raster, org.locationtech.jts.geom.Coordinate coordinate)static javax.media.jai.iterator.WritableRandomItergetWritableRandomIterator(int width, int height)Creates aWritableRandomIter.static javax.media.jai.iterator.WritableRandomItergetWritableRandomIterator(WritableRaster raster)Creates aWritableRandomIter.static List<org.locationtech.jts.geom.Polygon>gridcoverageToCellPolygons(org.geotools.coverage.grid.GridCoverage2D coverage, Predicate<org.locationtech.jts.geom.Coordinate> keepCoordinatePredicate, boolean doIncrementalMerge, IHMProgressMonitor pm)Extracts a list of polygons from the cell bounds of a givencoverage.static RegionMapgridGeometry2RegionParamsMap(org.geotools.coverage.grid.GridGeometry2D gridGeometry)static org.geotools.coverage.grid.GridGeometry2DgridGeometryFromRegionParams(HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs)static org.geotools.coverage.grid.GridGeometry2DgridGeometryFromRegionValues(double north, double south, double east, double west, int cols, int rows, org.opengis.referencing.crs.CoordinateReferenceSystem crs)static Point2DgridToWorld(org.geotools.coverage.grid.GridGeometry2D gridGeometry, int x, int y)Utility to tranform row/col to easting/westing.static WritableRasterintegerArray2WritableRaster(int[] array, double divide, int width, int height)Transforms an array of integer values into aWritableRaster.static org.geotools.coverage.grid.GridCoverage2Dinvert(org.geotools.coverage.grid.GridCoverage2D raster, double max)static booleanisGrass(String path)Checks if the given path is a GRASS raster file.static RegionMapmakeRegionParamsMap(double north, double south, double west, double east, double xRes, double yRes, int width, int height)static org.geotools.coverage.grid.GridCoverage2DmergeCoverages(org.geotools.coverage.grid.GridCoverage2D valuesMap, org.geotools.coverage.grid.GridCoverage2D onMap)Coverage merger.static javax.media.jai.ROIprepareROI(org.locationtech.jts.geom.Geometry roi, AffineTransform mt2d)Utility method for transforming a geometry ROI into the raster space, using the provided affine transformation.static byte[]renderedImage2ByteArray(RenderedImage renderedImage, boolean doRowsThenCols)Transform a double values rendered image in its byte array.static double[]renderedImage2DoubleArray(RenderedImage renderedImage)Transform a rendered image in its array representation.static double[]renderedImage2DoubleArray(RenderedImage renderedImage, int bandNumber)Transform a rendered image in its array representation.static WritableRasterrenderedImage2DoubleWritableRaster(RenderedImage renderedImage, boolean nullBorders)static int[]renderedImage2IntegerArray(RenderedImage renderedImage, double multiply)Transform a double values rendered image in its integer array representation by scaling the values.static WritableRasterrenderedImage2IntWritableRaster(RenderedImage renderedImage, boolean nullBorders)static WritableRasterrenderedImage2ShortWritableRaster(RenderedImage renderedImage, boolean nullBorders)static WritableRasterrenderedImage2WritableRaster(RenderedImage renderedImage, boolean nullBorders)Creates a compatibleWritableRasterfrom aRenderedImage.static WritableRasterreplaceNovalue(RenderedImage renderedImage, double newValue)Replace the current internal novalue with a given value.static voidsetNovalueBorder(WritableRaster raster)Creates a border of novalues.static org.geotools.coverage.grid.GridCoverage2DsumCoverages(org.geotools.coverage.grid.GridCoverage2D gc1, org.geotools.coverage.grid.GridCoverage2D gc2)static voidwriteWorldFiles(org.geotools.coverage.grid.GridCoverage2D coverage, String outPath)
-
-
-
Field Detail
-
NORTH
public static final String NORTH
- See Also:
- Constant Field Values
-
SOUTH
public static final String SOUTH
- See Also:
- Constant Field Values
-
WEST
public static final String WEST
- See Also:
- Constant Field Values
-
EAST
public static final String EAST
- See Also:
- Constant Field Values
-
XRES
public static final String XRES
- See Also:
- Constant Field Values
-
YRES
public static final String YRES
- See Also:
- Constant Field Values
-
ROWS
public static final String ROWS
- See Also:
- Constant Field Values
-
COLS
public static final String COLS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRandomIterator
public static javax.media.jai.iterator.RandomIter getRandomIterator(org.geotools.coverage.grid.GridCoverage2D coverage)
Creates aRandomIterfor the givenGridCoverage2D.It is important to use this method since it supports also large GRASS rasters.
- Parameters:
coverage- the coverage on which to wrap aRandomIter.- Returns:
- the iterator.
-
getWritableRandomIterator
public static javax.media.jai.iterator.WritableRandomIter getWritableRandomIterator(int width, int height)Creates aWritableRandomIter.It is important to use this method since it supports also large GRASS rasters.
If the size would throw an integer overflow, a
GrassLegacyRandomIterwill be proposed to try to save the saveable.- Parameters:
raster- the coverage on which to wrap aWritableRandomIter.- Returns:
- the iterator.
-
getWritableRandomIterator
public static javax.media.jai.iterator.WritableRandomIter getWritableRandomIterator(WritableRaster raster)
Creates aWritableRandomIter.It is important to use this method since it supports also large GRASS rasters.
If the size would throw an integer overflow, a
GrassLegacyRandomIterwill be proposed to try to save the saveable.- Parameters:
raster- the coverage on which to wrap aWritableRandomIter.- Returns:
- the iterator.
-
getGridCoverage
public static org.geotools.coverage.grid.GridCoverage2D getGridCoverage(org.geotools.coverage.grid.io.GridCoverage2DReader reader, double north, double south, double east, double west, double xRes, double yRes, org.opengis.referencing.crs.CoordinateReferenceSystem crs) throws ExceptionGet aGridCoverage2Dfrom a reader.- Parameters:
reader- the reader to use.north- north bound.south- south bound.east- east bound.west- west bound.xRes- x resolution.yRes- y resolution.crs- theCoordinateReferenceSystem.- Returns:
- the read coverage.
- Throws:
Exception
-
createWritableRaster
public static WritableRaster createWritableRaster(int width, int height, Class<?> dataClass, SampleModel sampleModel, Object value)
Creates awritable raster.- Parameters:
width- width of the raster to create.height- height of the raster to create.dataClass- data type for the raster. Ifnull, defaults to double.sampleModel- the samplemodel to use. Ifnull, defaults tonew ComponentSampleModel(dataType, width, height, 1, width, new int[]{0});.value- value to which to set the raster to. If null, the default of the raster creation is used, which is 0.- Returns:
- a
writable raster.
-
createCoverageFromTemplate
public static org.geotools.coverage.grid.GridCoverage2D createCoverageFromTemplate(org.geotools.coverage.grid.GridCoverage2D template, Double value, WritableRaster[] writableRasterHolder)Creates a newGridCoverage2Dusing an existing as template.- Parameters:
template- the template to use.value- the value to set the new raster to, if notnull.writableRasterHolder- an array of length 1 to place the writable raster in, that was can be used to populate the coverage. Ifnull, it is ignored.- Returns:
- the new coverage.
-
createSubCoverageFromTemplate
public static org.geotools.coverage.grid.GridCoverage2D createSubCoverageFromTemplate(org.geotools.coverage.grid.GridCoverage2D template, org.geotools.geometry.Envelope2D subregion, Double value, WritableRaster[] writableRasterHolder)Create a subcoverage given a template coverage and an envelope.- Parameters:
template- the template coverage used for the resolution.subregion- the envelope to extract to the new coverage. This should be snapped on the resolution of the coverage, in order to avoid shifts.value- the value to set the new raster to, if notnull.writableRasterHolder- an array of length 1 to place the writable raster in, that was can be used to populate the coverage. Ifnull, it is ignored.- Returns:
- the new coverage.
-
clipCoverage
public static org.geotools.coverage.grid.GridCoverage2D clipCoverage(org.geotools.coverage.grid.GridCoverage2D coverage, org.geotools.geometry.jts.ReferencedEnvelope envelope) throws ExceptionClip a coverage to a given envelope. The region is cut to keep the resolution consistent.- Throws:
Exception
-
apply
public static org.geotools.coverage.grid.GridCoverage2D apply(org.geotools.coverage.grid.GridCoverage2D coverage, DoubleUnaryOperator operator) throws ExceptionApply an operation to the coverage's values.- Parameters:
coverage- the original coverage.operator- the operator to apply.- Returns:
- the new coverage.
- Throws:
Exception
-
getRegionParamsFromGridCoverage
public static RegionMap getRegionParamsFromGridCoverage(org.geotools.coverage.grid.GridCoverage2D gridCoverage)
Get the parameters of the region covered by thecoverage.
-
getRegionParamsFromImageMosaicReader
public static RegionMap getRegionParamsFromImageMosaicReader(org.geotools.gce.imagemosaic.ImageMosaicReader reader) throws IOException
Get the parameters of the region covered by theImageMosaicReader.- Parameters:
reader- the ImageMosaicReader.- Returns:
- the
mapof parameters. (NORTHand the other static vars can be used to retrieve them. - Throws:
IOException
-
getRegionArrayFromGridCoverage
public static double[] getRegionArrayFromGridCoverage(org.geotools.coverage.grid.GridCoverage2D gridCoverage)
Get the array of region parameters covered by thecoverage.- Parameters:
gridCoverage- the coverage.- Returns:
- the array of region parameters as [n, s, w, e, xres, yres, cols, rows]
-
getRegionColsRows
public static int[] getRegionColsRows(org.geotools.coverage.grid.GridCoverage2D gridCoverage)
Get the array of rows and cols.- Parameters:
gridCoverage- the coverage.- Returns:
- the array as [cols, rows]
-
getRegionPolygon
public static org.locationtech.jts.geom.Polygon getRegionPolygon(org.geotools.coverage.grid.GridCoverage2D gridCoverage)
Create a bounds polygon of aGridCoverage2D.- Parameters:
gridCoverage- the coverage to use.- Returns:
- the bounding polygon.
-
getLoopColsRowsForSubregion
public static int[] getLoopColsRowsForSubregion(org.geotools.coverage.grid.GridCoverage2D gridCoverage, org.geotools.geometry.Envelope2D subregion) throws ExceptionGet the cols and rows ranges to use to loop the original gridcoverage.- Parameters:
gridCoverage- the coverage.subregion- the sub region of the coverage to get the cols and rows to loop on.- Returns:
- the array of looping values in the form [minCol, maxCol, minRow, maxRow].
- Throws:
Exception
-
generalParameterValues2RegionParamsMap
public static RegionMap generalParameterValues2RegionParamsMap(org.opengis.parameter.GeneralParameterValue[] params)
-
gridGeometry2RegionParamsMap
public static RegionMap gridGeometry2RegionParamsMap(org.geotools.coverage.grid.GridGeometry2D gridGeometry)
-
makeRegionParamsMap
public static RegionMap makeRegionParamsMap(double north, double south, double west, double east, double xRes, double yRes, int width, int height)
-
gridGeometryFromRegionParams
public static org.geotools.coverage.grid.GridGeometry2D gridGeometryFromRegionParams(HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
-
gridGeometryFromRegionValues
public static org.geotools.coverage.grid.GridGeometry2D gridGeometryFromRegionValues(double north, double south, double east, double west, int cols, int rows, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
-
createGridGeometryGeneralParameter
public static org.opengis.parameter.GeneralParameterValue[] createGridGeometryGeneralParameter(int width, int height, double north, double south, double east, double west, org.opengis.referencing.crs.CoordinateReferenceSystem crs)Utility method to create read parameters forGridCoverageReader- Parameters:
width- the needed number of columns.height- the needed number of columns.north- the northern boundary.south- the southern boundary.east- the eastern boundary.west- the western boundary.crs- theCoordinateReferenceSystem. Can be null, even if it should not.- Returns:
- the
array of parameters.
-
createGridGeometryGeneralParameter
public static org.opengis.parameter.GeneralParameterValue[] createGridGeometryGeneralParameter(RegionMap regionMap, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
Utility method to create read parameters forGridCoverageReader- Parameters:
regionMap- the RegionMap.crs- theCoordinateReferenceSystem. Can be null, even if it should not.- Returns:
- the
array of parameters.
-
createGridGeometryGeneralParameter
public static org.opengis.parameter.GeneralParameterValue[] createGridGeometryGeneralParameter(double xres, double yres, double north, double south, double east, double west, org.opengis.referencing.crs.CoordinateReferenceSystem crs)Utility method to create read parameters forGridCoverageReader- Parameters:
xres- the X resolution.yres- the Y resolution.north- the northern boundary.south- the southern boundary.east- the eastern boundary.west- the western boundary.crs- theCoordinateReferenceSystem. Can be null, even if it should not.- Returns:
- the
array of parameters.
-
createWritableRasterFromMatrix
public static WritableRaster createWritableRasterFromMatrix(double[][] matrix, boolean matrixIsRowCol)
Create aWritableRasterfrom a double matrix.- Parameters:
matrix- the matrix to take the data from.matrixIsRowCol- a flag to tell if the matrix has rowCol or colRow order.- Returns:
- the produced raster.
-
createWritableRasterFromMatrix
public static WritableRaster createWritableRasterFromMatrix(float[][] matrix, boolean matrixIsRowCol)
Create aWritableRasterfrom a float matrix.- Parameters:
matrix- the matrix to take the data from.matrixIsRowCol- a flag to tell if the matrix has rowCol or colRow order.- Returns:
- the produced raster.
-
createWritableRasterFromMatrix
public static WritableRaster createWritableRasterFromMatrix(int[][] matrix, boolean matrixIsRowCol)
-
createWritableRasterFromArray
public static WritableRaster createWritableRasterFromArray(int width, int height, int[] pixels)
Create aWritableRasterfrom a int array.- Parameters:
width- the width of the raster to create.height- the height of the raster to create.pixels- the array of data.- Returns:
- the produced raster.
-
buildCoverage
public static org.geotools.coverage.grid.GridCoverage2D buildCoverage(String name, double[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol)
Creates acoveragefrom a double[][] matrix and the necessary geographic Information.- Parameters:
name- the name of the coverage.dataMatrix- the matrix containing the data.envelopeParams- the map of boundary parameters.crs- theCoordinateReferenceSystem.matrixIsRowCol- a flag to tell if the matrix has rowCol or colRow order.- Returns:
- the
coverage.
-
buildCoverageWithNovalue
public static org.geotools.coverage.grid.GridCoverage2D buildCoverageWithNovalue(String name, double[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol, double novalue)
-
buildCoverage
public static org.geotools.coverage.grid.GridCoverage2D buildCoverage(String name, float[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol)
Creates acoveragefrom a float[][] matrix and the necessary geographic Information.- Parameters:
name- the name of the coverage.dataMatrix- the matrix containing the data.envelopeParams- the map of boundary parameters.crs- theCoordinateReferenceSystem.matrixIsRowCol- a flag to tell if the matrix has rowCol or colRow order.- Returns:
- the
coverage.
-
buildCoverage
public static org.geotools.coverage.grid.GridCoverage2D buildCoverage(String name, int[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol)
-
buildCoverageWithNovalue
public static org.geotools.coverage.grid.GridCoverage2D buildCoverageWithNovalue(String name, int[][] dataMatrix, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, boolean matrixIsRowCol, int novalue)
-
buildCoverage
public static org.geotools.coverage.grid.GridCoverage2D buildCoverage(String name, RenderedImage renderedImage, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
Creates acoveragefrom theimageand the necessary geographic Information.- Parameters:
name- the name of the coverage.renderedImage- the image containing the data.envelopeParams- the map of boundary parameters.crs- theCoordinateReferenceSystem.- Returns:
- the
coverage.
-
buildCoverageWithNovalue
public static org.geotools.coverage.grid.GridCoverage2D buildCoverageWithNovalue(String name, RenderedImage renderedImage, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, double novalue)
-
buildCoverage
public static org.geotools.coverage.grid.GridCoverage2D buildCoverage(String name, WritableRaster writableRaster, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
Creates acoveragefrom thewritable rasterand the necessary geographic Information.- Parameters:
name- the name of the coverage.writableRaster- the raster containing the data.envelopeParams- the map of boundary parameters.crs- theCoordinateReferenceSystem.- Returns:
- the
coverage.
-
buildCoverageWithNovalue
public static org.geotools.coverage.grid.GridCoverage2D buildCoverageWithNovalue(String name, WritableRaster writableRaster, HashMap<String,Double> envelopeParams, org.opengis.referencing.crs.CoordinateReferenceSystem crs, double novalue)
Creates acoveragefrom thewritable rasterand the necessary geographic Information.This also sets the nodata value in the metadata (useful for tiffs for example).
- Parameters:
name- the name of the coverage.writableRaster- the raster containing the data.envelopeParams- the map of boundary parameters.crs- theCoordinateReferenceSystem.novalue- the novalue to set in the metadata.- Returns:
- the
coverage.
-
buildDummyCoverage
public static org.geotools.coverage.grid.GridCoverage2D buildDummyCoverage()
Creates a uselessGridCoverage2Dthat might be usefull as placeholder.- Returns:
- the dummy grod coverage.
-
renderedImage2WritableRaster
public static WritableRaster renderedImage2WritableRaster(RenderedImage renderedImage, boolean nullBorders)
Creates a compatibleWritableRasterfrom aRenderedImage.- Parameters:
renderedImage- the image to convert.nullBorders- a flag that indicates if the borders should be set to null.- Returns:
- the converted writable raster.
-
renderedImage2DoubleWritableRaster
public static WritableRaster renderedImage2DoubleWritableRaster(RenderedImage renderedImage, boolean nullBorders)
-
renderedImage2IntWritableRaster
public static WritableRaster renderedImage2IntWritableRaster(RenderedImage renderedImage, boolean nullBorders)
-
renderedImage2ShortWritableRaster
public static WritableRaster renderedImage2ShortWritableRaster(RenderedImage renderedImage, boolean nullBorders)
-
renderedImage2DoubleArray
public static double[] renderedImage2DoubleArray(RenderedImage renderedImage)
Transform a rendered image in its array representation.- Parameters:
renderedImage- the rendered image to transform.- Returns:
- the array holding the data.
-
renderedImage2DoubleArray
public static double[] renderedImage2DoubleArray(RenderedImage renderedImage, int bandNumber)
Transform a rendered image in its array representation.- Parameters:
renderedImage- the rendered image to transform.bandNumber- the the number of the band to consider..- Returns:
- the array holding the data.
-
renderedImage2IntegerArray
public static int[] renderedImage2IntegerArray(RenderedImage renderedImage, double multiply)
Transform a double values rendered image in its integer array representation by scaling the values.- Parameters:
renderedImage- the rendered image to transform.multiply- value by which to multiply the values before casting to integer.- Returns:
- the array holding the data.
-
renderedImage2ByteArray
public static byte[] renderedImage2ByteArray(RenderedImage renderedImage, boolean doRowsThenCols)
Transform a double values rendered image in its byte array.No check is done if the double value fits in a byte.
- Parameters:
renderedImage- the rendered image to transform.doRowsThenCols- iftrue, rows are processed in the outer loop.- Returns:
- the array holding the data.
-
integerArray2WritableRaster
public static WritableRaster integerArray2WritableRaster(int[] array, double divide, int width, int height)
Transforms an array of integer values into aWritableRaster.- Parameters:
array- the values to transform.divide- the factor by which to divide the values.width- the width of the resulting image.height- the height of the resulting image.- Returns:
- the raster.
-
doubleArray2WritableRaster
public static WritableRaster doubleArray2WritableRaster(double[] array, int width, int height)
Transforms an array of values into aWritableRaster.- Parameters:
array- the values to transform.divide- the factor by which to divide the values.width- the width of the resulting image.height- the height of the resulting image.- Returns:
- the raster.
-
setNovalueBorder
public static void setNovalueBorder(WritableRaster raster)
Creates a border of novalues.- Parameters:
raster- the raster to process.
-
doProfile
public static List<ProfilePoint> doProfile(org.geotools.coverage.grid.GridCoverage2D coverage, org.locationtech.jts.geom.Coordinate... coordinates) throws Exception
Calculates the profile of a raster map between givencoordinates.- Parameters:
coverage- the coverage from which to extract the profile.coordinates- the coordinates to use to trace the profile.- Returns:
- the list of
ProfilePoints. - Throws:
Exception
-
doProfile
public static List<ProfilePoint> doProfile(javax.media.jai.iterator.RandomIter mapIter, org.geotools.coverage.grid.GridGeometry2D gridGeometry, org.locationtech.jts.geom.Coordinate... coordinates) throws org.opengis.referencing.operation.TransformException
Calculates the profile of a raster map between givencoordinates.Note that novalues and points outside of the given raster region are added to the list with a
novalueelevation.- Parameters:
mapIter- themap iterator.gridGeometry- the gridgeometry of the map.coordinates- theCoordinates to create the profile on.- Returns:
- the list of
ProfilePoints. - Throws:
org.opengis.referencing.operation.TransformException
-
gridToWorld
public static Point2D gridToWorld(org.geotools.coverage.grid.GridGeometry2D gridGeometry, int x, int y) throws org.geotools.coverage.grid.InvalidGridGeometryException, org.opengis.referencing.operation.TransformException
Utility to tranform row/col to easting/westing.- Parameters:
gridGeometry-x-y-- Returns:
- the world easting and northing.
- Throws:
org.geotools.coverage.grid.InvalidGridGeometryExceptionorg.opengis.referencing.operation.TransformException
-
replaceNovalue
public static WritableRaster replaceNovalue(RenderedImage renderedImage, double newValue)
Replace the current internal novalue with a given value.- Parameters:
renderedImage- aRenderedImage.newValue- the value to put in instead of the novalue.- Returns:
- the rendered image with the substituted novalue.
-
prepareROI
public static javax.media.jai.ROI prepareROI(org.locationtech.jts.geom.Geometry roi, AffineTransform mt2d) throws ExceptionUtility method for transforming a geometry ROI into the raster space, using the provided affine transformation.- Parameters:
roi- aGeometryin model space.mt2d- anAffineTransformthat maps from raster to model space. This is already referred to the pixel corner.- Returns:
- a
ROIsuitable for using with JAI. - Throws:
org.geotools.process.ProcessException- in case there are problems with ivnerting the providedAffineTransform. Very unlikely to happen.Exception
-
isGrass
public static boolean isGrass(String path)
Checks if the given path is a GRASS raster file.Note that there is no check on the existence of the file.
- Parameters:
path- the path to check.- Returns:
- true if the file is a grass raster.
-
colRowFromCoordinate
public static int[] colRowFromCoordinate(org.locationtech.jts.geom.Coordinate coordinate, org.geotools.coverage.grid.GridGeometry2D gridGeometry, Point point)Utility method to get col and row of a coordinate from aGridGeometry2D.- Parameters:
coordinate- the coordinate to transform.gridGeometry- the gridgeometry to use.point- if notnull, the row col values are put inside the supplied point's x and y.- Returns:
- the array with [col, row] or
nullif something went wrong.
-
coordinateFromColRow
public static org.locationtech.jts.geom.Coordinate coordinateFromColRow(int col, int row, org.geotools.coverage.grid.GridGeometry2D gridGeometry)Utility method to get the coordinate of a col and row from aGridGeometry2D.- Parameters:
col- the col to transform.row- the row to transform.gridGeometry- the gridgeometry to use.- Returns:
- the coordinate or
nullif something went wrong.
-
coverageValuesMapper
public static org.geotools.coverage.grid.GridCoverage2D coverageValuesMapper(org.geotools.coverage.grid.GridCoverage2D valuesMap, org.geotools.coverage.grid.GridCoverage2D maskMap)Mappes the values of a map (valuesMap) into the valid pixels of the second map (maskMap).- Parameters:
valuesMap- the map holding the values that are needed in the resulting map.maskMap- the map to use as mask for the values.- Returns:
- the map containing the values of the valuesMap, but only in the places in which the maskMap is valid.
-
mergeCoverages
public static org.geotools.coverage.grid.GridCoverage2D mergeCoverages(org.geotools.coverage.grid.GridCoverage2D valuesMap, org.geotools.coverage.grid.GridCoverage2D onMap)Coverage merger.Values from valuesMap are placed into the onMap coverage, if they are valid.
- Parameters:
valuesMap- the map from which to take teh valid values to place in the output map.onMap- the base map on which to place the valuesMap values.- Returns:
- the merged map of valuesMap over onMap.
-
sumCoverages
public static org.geotools.coverage.grid.GridCoverage2D sumCoverages(org.geotools.coverage.grid.GridCoverage2D gc1, org.geotools.coverage.grid.GridCoverage2D gc2)
-
calculateHypsographic
public static double[][] calculateHypsographic(org.geotools.coverage.grid.GridCoverage2D elevationCoverage, int bins, IHMProgressMonitor pm)Calculates the hypsographic curve for the given raster, using the supplied bins.- Parameters:
elevationCoverage- the elevation raster.bins- the bins to use.pm- the monitor.- Returns:
- the matrix containing the hypsographic curve in [elev, area] pairs per row.
-
getValue
public static double getValue(org.geotools.coverage.grid.GridCoverage2D raster, int col, int row)Simple method to get a value from a single band raster.Note that this method does always return a value. If invalid, a novalue is returned.
- Parameters:
raster- the single band raster.col- the column.row- the row.- Returns:
- the value in the [col, row] of the first band.
-
getValue
public static double getValue(org.geotools.coverage.grid.GridCoverage2D raster, double easting, double northing)Simple method to get a value from a single band raster.Note that this method does always return a value. If invalid, a novalue is returned.
- Parameters:
raster-easting-northing-- Returns:
-
getValue
public static double getValue(org.geotools.coverage.grid.GridCoverage2D raster, org.locationtech.jts.geom.Coordinate coordinate)
-
invert
public static org.geotools.coverage.grid.GridCoverage2D invert(org.geotools.coverage.grid.GridCoverage2D raster, double max)
-
equals
public static boolean equals(WritableRaster wr1, WritableRaster wr2)
Checks two rasters for equality of content.- Parameters:
wr1- the first raster.wr2- the second raster.- Returns:
true, if the rasters contain the same values.
-
writeWorldFiles
public static void writeWorldFiles(org.geotools.coverage.grid.GridCoverage2D coverage, String outPath) throws Exception- Throws:
Exception
-
gridcoverageToCellPolygons
public static List<org.locationtech.jts.geom.Polygon> gridcoverageToCellPolygons(org.geotools.coverage.grid.GridCoverage2D coverage, Predicate<org.locationtech.jts.geom.Coordinate> keepCoordinatePredicate, boolean doIncrementalMerge, IHMProgressMonitor pm)
Extracts a list of polygons from the cell bounds of a givencoverage.Note that the cells are added in a rows and cols order (for each row evaluate each column).
The userdata of the geometry contains the value of the raster.
- Parameters:
coverage- the coverage to use.keepCoordinatePredicate- an optional predicate to filter out some of the cells.- Returns:
- the list of envelope geometries.
-
extractPolygonOnCoverage
public static List<org.locationtech.jts.geom.Coordinate> extractPolygonOnCoverage(javax.media.jai.iterator.RandomIter coverageIterator, int cols, int rows, double xRes, org.geotools.coverage.grid.GridGeometry2D gridGeometry, org.locationtech.jts.geom.Polygon polygon, double defaultValue) throws Exception
Extracts the positions and values of a polygon mapped on a raster(rasterization).Bound checks (polygon completely covering the raster) need to be made before running this method.
- Parameters:
coverageIterator- the raster from which to extract the values.cols- the cols of the raster.rows- the rows of the raster.xRes- the resolution of the raster.gridGeometry- theGridGeometry2Dof the raster.polygon- the polygon to extract.defaultValue- a defaultvalue in case no raster is supplied.- Returns:
- the list of coordinates, with the z values set to the raster or default value.
- Throws:
Exception
-
getNovalue
public static Double getNovalue(org.geotools.coverage.grid.GridCoverage2D raster)
Get the novalue defined for the raster.- Parameters:
raster-- Returns:
- the novalue or null if none defined.
-
-