read method
Read the raster accessing the file.
The optional imageIndex
defines the image to open.
Implementation
@override
void read([int? imageIndex]) {
if (imageIndex == null) {
imageIndex = 0;
}
_imageBytes = _file.readAsBytesSync();
TiffDecoder? tiffDecoder;
if (GeoimageUtils.isTiff(_file.path)) {
_image = decodeTiff(_imageBytes);
tiffDecoder = TiffDecoder();
//_image = tiffDecoder.decodeImage(_imageBytes);
_image = tiffDecoder.decode(_imageBytes);
} else {
_image = decodeImage(_imageBytes);
}
if (_image == null) {
throw StateError("Unable to decode image.");
}
var wesnxyValues =
GeoimageUtils.parseWorldFile(_file.path, _image!.width, _image!.height);
var prjWkt = GeoimageUtils.getPrjWkt(_file.path);
if (wesnxyValues != null) {
// has worldfile
_geoInfo = GeoInfo.fromValues(
_image!.width,
_image!.height,
wesnxyValues[4],
-wesnxyValues[5],
wesnxyValues[0],
wesnxyValues[3],
prjWkt);
} else if (tiffDecoder != null) {
// without worldfile only tiffs can contain geoinfo
var tiffInfo = tiffDecoder.info;
if (tiffInfo != null) {
_tiffImage = tiffInfo.images[imageIndex];
if (_tiffImage != null) {
_geoInfo = GeoInfo(_tiffImage!, prjWkt);
}
}
} else {
throw ArgumentError("The supplied image is not a supported geoimage.");
}
}