Package org.geotools.gce.imagemosaic
Class Utils
- Object
-
- Utils
-
public class Utils extends Object
Sparse utilities for the various mosaic classes. I use them to extract complex code from other places.- Author:
- Simone Giannecchini, GeoSolutions S.A.S.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Utils.BBOXFilterExtractor
Extracts a bbox from a filter in case there is at least one.static class
Utils.Prop
static class
Utils.SourceGetter
Given a source object, allow to retrieve (when possible) the related url, the related file or the original input source object itself.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkColorModels(ColorModel defaultCM, byte[][] defaultPalette, ColorModel actualCM)
This method checks theColorModel
of the current image with the one of the first image in order to check if they are compatible or not in order to perform a mosaic operation.static String
checkDirectory(String testingDirectory, boolean writable)
static boolean
checkFileReadable(File file)
Checks that aFile
is a real file, exists and is readable.static Map<String,Serializable>
createDataStoreParamsFromPropertiesFile(URL datastoreProperties)
static Map<String,Serializable>
createDataStoreParamsFromPropertiesFile(Properties properties, DataStoreFactorySpi spi)
static Range<? extends Number>
createRange(Object firstValue, Object secondValue)
Create a Range of numbers from a couple of values.static Geometry
decimate(Geometry geometry)
Decimate a geometry (reducing the number of vertices) for incoming bufferingstatic IOFileFilter
excludeFilters(IOFileFilter inputFilter, IOFileFilter... filters)
static byte[][]
extractPalette(IndexColorModel indexColorModel)
Extract the palette from anIndexColorModel
.static Map<String,Serializable>
filterDataStoreParams(Properties properties, DataStoreFactorySpi spi)
static void
fixH2DatabaseLocation(Map<String,Serializable> params, String parentLocation)
static void
fixH2MVCCParam(Map<String,Serializable> params)
static void
fixPostgisDBCreationParams(Map<String,Serializable> datastoreParams)
static Object
getAttribute(SimpleFeature feature, String attribute)
static BorderExtender
getBorderExtenderHint(RenderingHints renderHints)
static IOFileFilter
getCleanupFilter()
static File
getFile(String strValue, File rootFolder)
Returns the File associated to the rootFolder if not absolutestatic String
getFileInfo(File file)
Creates a human readable message that describe the providedFile
object in terms of its properties.static Object
getHintIfAvailable(RenderingHints hints, RenderingHints.Key key)
static Histogram
getHistogram(String file)
Setup aHistogram
object by deserializing a file representing a serialized Histogram.static ImageLayout
getImageLayoutHint(RenderingHints renderHints)
static String
getIndexerProperty(String locationPath, String propertyName)
static ImageInputStreamSpi
getInputStreamSPIFromURL(URL granuleUrl)
static String
getMessageFromException(Exception exception)
static ImageReaderSpi
getReaderSpiFromStream(ImageReaderSpi suggestedSPI, ImageInputStream inStream)
static TileCache
getTileCacheHint(RenderingHints renderHints)
static TileScheduler
getTileSchedulerHint(RenderingHints renderHints)
static boolean
homogeneousCheck(int numberOfLevels, double[][] resolutionLevels, double[][] compareLevels)
Check whether 2 resolution levels sets are homogeneous (within a tolerance)static boolean
isH2Store(DataStoreFactorySpi spi)
static boolean
isOracleStore(DataStoreFactorySpi spi)
Checks if the provided factory spi builds a Oracle storestatic boolean
isPostgisStore(DataStoreFactorySpi spi)
Checks if the provided factory spi builds a Postgis storestatic boolean
isSQLServerStore(DataStoreFactorySpi spi)
Checks if the provided factory spi builds a SQLServer storestatic boolean
isSupportedCRS(GridCoverage2DReader reader, CoordinateReferenceSystem crs)
Check if the provided reader is a MultiCRS Reader and it can support the specified crs.static boolean
isValidMosaicSchema(SimpleFeatureType schema, String locationAttributeName)
Returns true if the type is usable as a mosaic indexstatic RenderedImage
loadSampleImage(File sampleImageFile)
Load a sample image from which we can take the sample model and color model to be used to fill holes in responses.static void
marshal(Indexer indexer, File indexerFile)
Marshals the Indexer object to the specified filestatic PAMDataset
mergePamDatasets(PAMDataset[] pamDatasets)
Merge statistics across datasets.static boolean
minimalIndexCheck(Object source)
Simple minimal check which checks whether and indexer file existsstatic ReferencedEnvelope
parseEnvelope(String bboxString)
Parses a bbox in the form of MIX,MINY MAXX,MAXYstatic ReferencedEnvelope
reprojectEnvelope(ReferencedEnvelope sourceEnvelope, CoordinateReferenceSystem targetCRS, ReferencedEnvelope targetReferenceEnvelope)
static Geometry
reprojectEnvelopeToGeometry(ReferencedEnvelope sourceEnvelope, CoordinateReferenceSystem targetCRS, ReferencedEnvelope targetReferenceEnvelope)
Reprojects an envelope using theProjectionHandler
machinery.static ROI
roiIntersect(ROI roi, ROIGeometry roiGeometry, RenderingHints hints)
Intersects a ROI with a ROI geometry, with fallback on GeometrySnapper if a TopologyException occursstatic Hints
setupJAIHints(RenderingHints inputHints)
static void
storeSampleImage(File sampleImageFile, SampleModel defaultSM, ColorModel defaultCM)
Store a sample image from which we can derive the default SM and CMstatic Indexer
unmarshal(File indexerFile)
Unmarshal the file and return and Indexer object.
-
-
-
Field Detail
-
FF
public static final FilterFactory FF
-
DEFAULT_RANGE_READER
public static final String DEFAULT_RANGE_READER
- See Also:
- Constant Field Values
-
EXCLUDE_MOSAIC
public static final Hints.Key EXCLUDE_MOSAIC
-
EXCLUDE_MOSAIC_HINTS
public static final Hints EXCLUDE_MOSAIC_HINTS
Hints to use for avoiding to search for the imagemosaic format
-
CHECK_AUXILIARY_METADATA
public static final Hints.Key CHECK_AUXILIARY_METADATA
-
COG_SETTINGS
public static final Hints.Key COG_SETTINGS
-
AUXILIARY_FILES_PATH
public static final Hints.Key AUXILIARY_FILES_PATH
-
AUXILIARY_DATASTORE_PATH
public static final Hints.Key AUXILIARY_DATASTORE_PATH
-
PARENT_DIR
public static final Hints.Key PARENT_DIR
-
MOSAIC_READER
public static final Hints.Key MOSAIC_READER
-
RANGE_SPLITTER_CHAR
public static final String RANGE_SPLITTER_CHAR
- See Also:
- Constant Field Values
-
PAM_DATASET
@Deprecated public static final String PAM_DATASET
Deprecated.- See Also:
- Constant Field Values
-
DATASTORE_PROPERTIES
public static final String DATASTORE_PROPERTIES
- See Also:
- Constant Field Values
-
PROPERTIES_SEPARATOR
public static final String PROPERTIES_SEPARATOR
- See Also:
- Constant Field Values
-
RGB_TO_GRAY_MATRIX
public static final double[][] RGB_TO_GRAY_MATRIX
RGB to GRAY coefficients (for Luminance computation)
-
SAMPLE_IMAGE_ALLOWLIST_PROPERTY_NAME
public static final String SAMPLE_IMAGE_ALLOWLIST_PROPERTY_NAME
System propertyorg.geotools.gce.imagemosaic.sampleimage.allowlist
used to validate sample image deserialization.- See Also:
- Constant Field Values
-
DEFAULT_WILCARD
public static final String DEFAULT_WILCARD
Default wildcard for creating mosaics.- See Also:
- Constant Field Values
-
DEFAULT_PATH_BEHAVIOR
public static final boolean DEFAULT_PATH_BEHAVIOR
Default path behavior with respect to absolute paths.- See Also:
- Constant Field Values
-
DEFAULT_PRIORITY
public static final int DEFAULT_PRIORITY
Default priority for the underlyingThread
.- See Also:
- Constant Field Values
-
DEFAULT_LOCATION_ATTRIBUTE
public static final String DEFAULT_LOCATION_ATTRIBUTE
Default location attribute name.- See Also:
- Constant Field Values
-
DEFAULT_INDEX_NAME
public static final String DEFAULT_INDEX_NAME
- See Also:
- Constant Field Values
-
SHAPE_SPI
public static final DataStoreFactorySpi SHAPE_SPI
-
DEFAULT_RECURSION_BEHAVIOR
public static final boolean DEFAULT_RECURSION_BEHAVIOR
- See Also:
- Constant Field Values
-
DEFAULT_COLLECT_RAT
public static final boolean DEFAULT_COLLECT_RAT
- See Also:
- Constant Field Values
-
DEFAULT_FOOTPRINT_MANAGEMENT
public static final boolean DEFAULT_FOOTPRINT_MANAGEMENT
- See Also:
- Constant Field Values
-
DEFAULT_CONFIGURATION_CACHING
public static final boolean DEFAULT_CONFIGURATION_CACHING
- See Also:
- Constant Field Values
-
DEFAULT_COLOR_EXPANSION_BEHAVIOR
public static final boolean DEFAULT_COLOR_EXPANSION_BEHAVIOR
- See Also:
- Constant Field Values
-
UTC_TIME_ZONE
public static final TimeZone UTC_TIME_ZONE
-
SAMPLE_IMAGE_NAME_LEGACY
public static final String SAMPLE_IMAGE_NAME_LEGACY
- See Also:
- Constant Field Values
-
SAMPLE_IMAGE_NAME
public static final String SAMPLE_IMAGE_NAME
- See Also:
- Constant Field Values
-
PAM_DATASET_NAME
public static final String PAM_DATASET_NAME
- See Also:
- Constant Field Values
-
BBOX
public static final String BBOX
- See Also:
- Constant Field Values
-
TIME_DOMAIN
public static final String TIME_DOMAIN
- See Also:
- Constant Field Values
-
ELEVATION_DOMAIN
public static final String ELEVATION_DOMAIN
- See Also:
- Constant Field Values
-
CRS_DOMAIN
public static final String CRS_DOMAIN
- See Also:
- Constant Field Values
-
RESOLUTION_DOMAIN
public static final String RESOLUTION_DOMAIN
- See Also:
- Constant Field Values
-
RESOLUTION_X_DOMAIN
public static final String RESOLUTION_X_DOMAIN
- See Also:
- Constant Field Values
-
RESOLUTION_Y_DOMAIN
public static final String RESOLUTION_Y_DOMAIN
- See Also:
- Constant Field Values
-
ADDITIONAL_DOMAIN
public static final String ADDITIONAL_DOMAIN
- See Also:
- Constant Field Values
-
OBJECT_FACTORY
public static ObjectFactory OBJECT_FACTORY
-
-
Method Detail
-
isSupportedCRS
public static boolean isSupportedCRS(GridCoverage2DReader reader, CoordinateReferenceSystem crs) throws FactoryException, IOException
Check if the provided reader is a MultiCRS Reader and it can support the specified crs.- Throws:
FactoryException
IOException
-
getAttribute
public static Object getAttribute(SimpleFeature feature, String attribute)
-
parseEnvelope
public static ReferencedEnvelope parseEnvelope(String bboxString)
Parses a bbox in the form of MIX,MINY MAXX,MAXY- Parameters:
bboxString
- the string to parse the bbox from- Returns:
- a
ReferencedEnvelope
with the parse bbox or null
-
excludeFilters
public static IOFileFilter excludeFilters(IOFileFilter inputFilter, IOFileFilter... filters)
-
checkFileReadable
public static boolean checkFileReadable(File file)
Checks that aFile
is a real file, exists and is readable.- Parameters:
file
- theFile
instance to check. Must not be null.- Returns:
true
in case the file is a real file, exists and is readable;false
otherwise.
-
getFileInfo
public static String getFileInfo(File file)
Creates a human readable message that describe the providedFile
object in terms of its properties.Useful for creating meaningful log messages.
-
checkDirectory
public static String checkDirectory(String testingDirectory, boolean writable) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
createDataStoreParamsFromPropertiesFile
public static Map<String,Serializable> createDataStoreParamsFromPropertiesFile(URL datastoreProperties) throws IOException
- Throws:
IOException
-
storeSampleImage
public static void storeSampleImage(File sampleImageFile, SampleModel defaultSM, ColorModel defaultCM) throws IOException
Store a sample image from which we can derive the default SM and CM- Parameters:
sampleImageFile
- where we should store the imagedefaultSM
- theSampleModel
for the sample image.defaultCM
- theColorModel
for the sample image.- Throws:
IOException
- in case something bad occurs during writing.
-
loadSampleImage
public static RenderedImage loadSampleImage(File sampleImageFile)
Load a sample image from which we can take the sample model and color model to be used to fill holes in responses.Format of sample image is limited and may be customized using
SAMPLE_IMAGE_ALLOWLIST
system propertyorg.geotools.gce.imagemosaic.sampleimage.allowlist
.- Parameters:
sampleImageFile
- the path to sample image.- Returns:
- a sample image from which we can take the sample model and color model to be used to fill holes in responses.
-
createDataStoreParamsFromPropertiesFile
public static Map<String,Serializable> createDataStoreParamsFromPropertiesFile(Properties properties, DataStoreFactorySpi spi) throws IOException
- Throws:
IOException
-
filterDataStoreParams
public static Map<String,Serializable> filterDataStoreParams(Properties properties, DataStoreFactorySpi spi) throws IOException
- Throws:
IOException
-
getIndexerProperty
public static String getIndexerProperty(String locationPath, String propertyName)
-
getHistogram
public static Histogram getHistogram(String file)
Setup aHistogram
object by deserializing a file representing a serialized Histogram.- Returns:
- the deserialized histogram.
-
getImageLayoutHint
public static ImageLayout getImageLayoutHint(RenderingHints renderHints)
-
getTileCacheHint
public static TileCache getTileCacheHint(RenderingHints renderHints)
-
getBorderExtenderHint
public static BorderExtender getBorderExtenderHint(RenderingHints renderHints)
-
getTileSchedulerHint
public static TileScheduler getTileSchedulerHint(RenderingHints renderHints)
-
getHintIfAvailable
public static Object getHintIfAvailable(RenderingHints hints, RenderingHints.Key key)
-
setupJAIHints
public static Hints setupJAIHints(RenderingHints inputHints)
-
createRange
public static Range<? extends Number> createRange(Object firstValue, Object secondValue)
Create a Range of numbers from a couple of values.
-
minimalIndexCheck
public static boolean minimalIndexCheck(Object source)
Simple minimal check which checks whether and indexer file exists
-
homogeneousCheck
public static boolean homogeneousCheck(int numberOfLevels, double[][] resolutionLevels, double[][] compareLevels)
Check whether 2 resolution levels sets are homogeneous (within a tolerance)
-
unmarshal
public static Indexer unmarshal(File indexerFile) throws JAXBException
Unmarshal the file and return and Indexer object.- Throws:
JAXBException
-
marshal
public static void marshal(Indexer indexer, File indexerFile) throws JAXBException
Marshals the Indexer object to the specified file- Throws:
JAXBException
-
checkColorModels
public static boolean checkColorModels(ColorModel defaultCM, byte[][] defaultPalette, ColorModel actualCM)
This method checks theColorModel
of the current image with the one of the first image in order to check if they are compatible or not in order to perform a mosaic operation.It is worth to point out that we also check if, in case we have two index color model image, we also try to suggest whether or not we should do a color expansion.
- Returns:
- a boolean asking to skip this feature.
-
isH2Store
public static boolean isH2Store(DataStoreFactorySpi spi)
-
fixH2DatabaseLocation
public static void fixH2DatabaseLocation(Map<String,Serializable> params, String parentLocation) throws MalformedURLException
- Throws:
MalformedURLException
-
isOracleStore
public static boolean isOracleStore(DataStoreFactorySpi spi)
Checks if the provided factory spi builds a Oracle store
-
isPostgisStore
public static boolean isPostgisStore(DataStoreFactorySpi spi)
Checks if the provided factory spi builds a Postgis store
-
isSQLServerStore
public static boolean isSQLServerStore(DataStoreFactorySpi spi)
Checks if the provided factory spi builds a SQLServer store
-
mergePamDatasets
public static PAMDataset mergePamDatasets(PAMDataset[] pamDatasets)
Merge statistics across datasets.
-
getCleanupFilter
public static IOFileFilter getCleanupFilter()
-
fixH2MVCCParam
public static void fixH2MVCCParam(Map<String,Serializable> params)
-
fixPostgisDBCreationParams
public static void fixPostgisDBCreationParams(Map<String,Serializable> datastoreParams)
-
getReaderSpiFromStream
public static ImageReaderSpi getReaderSpiFromStream(ImageReaderSpi suggestedSPI, ImageInputStream inStream) throws IOException
- Throws:
IOException
-
getInputStreamSPIFromURL
public static ImageInputStreamSpi getInputStreamSPIFromURL(URL granuleUrl) throws IOException
- Throws:
IOException
-
extractPalette
public static byte[][] extractPalette(IndexColorModel indexColorModel)
Extract the palette from anIndexColorModel
.
-
isValidMosaicSchema
public static boolean isValidMosaicSchema(SimpleFeatureType schema, String locationAttributeName)
Returns true if the type is usable as a mosaic index
-
reprojectEnvelope
public static ReferencedEnvelope reprojectEnvelope(ReferencedEnvelope sourceEnvelope, CoordinateReferenceSystem targetCRS, ReferencedEnvelope targetReferenceEnvelope) throws FactoryException, TransformException
- Throws:
FactoryException
TransformException
-
reprojectEnvelopeToGeometry
public static Geometry reprojectEnvelopeToGeometry(ReferencedEnvelope sourceEnvelope, CoordinateReferenceSystem targetCRS, ReferencedEnvelope targetReferenceEnvelope) throws FactoryException, TransformException
Reprojects an envelope using theProjectionHandler
machinery. The output can be a multipolygon in case of wrapping, which might or might not be what you want, act accordingly- Throws:
FactoryException
TransformException
-
getFile
public static File getFile(String strValue, File rootFolder) throws IOException
Returns the File associated to the rootFolder if not absolute- Throws:
IOException
-
decimate
public static Geometry decimate(Geometry geometry)
Decimate a geometry (reducing the number of vertices) for incoming buffering
-
roiIntersect
public static ROI roiIntersect(ROI roi, ROIGeometry roiGeometry, RenderingHints hints)
Intersects a ROI with a ROI geometry, with fallback on GeometrySnapper if a TopologyException occurs
-
-