-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PB-1028 : do not load a COG while importing it, only read its metadata
renaming the layer type from GeoTIFF (which we shouldn't support much, too big of a risk of users loading very large files and crashing the app because of lack of memory) and clarifying that we support COG (Cloud Optimized GeoTIFF) Adding a dedicated parser for COG files improvements made during this work package : - read the no data value from the COG metadata (instead of arbitrarily setting it to zero) - re-load COG extent if the layer was added at startup through a URL param
- Loading branch information
Showing
14 changed files
with
190 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ules/menu/components/advancedTools/ImportFile/parser/CloudOptimizedGeoTIFFParser.class.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { fromBlob, fromUrl } from 'geotiff' | ||
|
||
import CloudOptimizedGeoTIFFLayer from '@/api/layers/CloudOptimizedGeoTIFFLayer.class' | ||
import OutOfBoundsError from '@/modules/menu/components/advancedTools/ImportFile/parser/errors/OutOfBoundsError.error' | ||
import UnknownProjectionError from '@/modules/menu/components/advancedTools/ImportFile/parser/errors/UnknownProjectionError.error' | ||
import FileParser from '@/modules/menu/components/advancedTools/ImportFile/parser/FileParser.class' | ||
import allCoordinateSystems from '@/utils/coordinates/coordinateSystems' | ||
import { flattenExtent, getExtentIntersectionWithCurrentProjection } from '@/utils/extentUtils' | ||
|
||
export class CloudOptimizedGeoTIFFParser extends FileParser { | ||
constructor() { | ||
super({ | ||
fileExtensions: ['.tif', '.tiff'], | ||
fileContentTypes: [ | ||
'image/tiff', | ||
'image/tiff;subtype=geotiff', | ||
'application=geotiff', | ||
'application=geotiff; profile=cloud-optimized', | ||
'image/tiff; application=geotiff; profile=cloud-optimized', | ||
], | ||
}) | ||
} | ||
|
||
async parseCOGLayer(fileSource, geoTIFFInstance, currentProjection) { | ||
if (!geoTIFFInstance) { | ||
throw false | ||
} | ||
const firstImage = await geoTIFFInstance.getImage() | ||
const imageGeoKey = firstImage.getGeoKeys()?.ProjectedCSTypeGeoKey | ||
const cogProjection = allCoordinateSystems.find( | ||
(coordinateSystem) => coordinateSystem.epsgNumber === imageGeoKey | ||
) | ||
if (!cogProjection) { | ||
throw new UnknownProjectionError( | ||
`Unknown projection found in COG EPSG:${imageGeoKey}`, | ||
`EPSG:${imageGeoKey}` | ||
) | ||
} | ||
const cogExtent = firstImage.getBoundingBox() | ||
const intersection = getExtentIntersectionWithCurrentProjection( | ||
cogExtent, | ||
cogProjection, | ||
currentProjection | ||
) | ||
if (!intersection) { | ||
throw new OutOfBoundsError(`COG is out of bounds of current projection: ${cogExtent}`) | ||
} | ||
return new CloudOptimizedGeoTIFFLayer({ | ||
fileSource: this.isLocalFile(fileSource) ? fileSource.name : fileSource, | ||
visible: true, | ||
opacity: 1.0, | ||
data: fileSource, | ||
noDataValue: firstImage.getGDALNoData(), | ||
extent: flattenExtent(intersection), | ||
}) | ||
} | ||
|
||
async parseUrl(fileUrl, currentProjection, options) { | ||
return this.parseCOGLayer(fileUrl, await fromUrl(fileUrl), currentProjection, options) | ||
} | ||
|
||
async parseLocalFile(file, currentProjection) { | ||
return this.parseCOGLayer(file, await fromBlob(file), currentProjection) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.