-
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.
Merge pull request #1083 from geoadmin/feat-PB-1028-do-not-load-entir…
- 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) | ||
} | ||
} |
8 changes: 7 additions & 1 deletion
8
src/modules/menu/components/advancedTools/ImportFile/parser/index.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
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.