diff --git a/packages/core/src/const/tiff.tag.id.ts b/packages/core/src/const/tiff.tag.id.ts index 5f02edfb..fd759a1e 100644 --- a/packages/core/src/const/tiff.tag.id.ts +++ b/packages/core/src/const/tiff.tag.id.ts @@ -42,12 +42,15 @@ export enum RasterTypeKey { } export enum ModelTypeCode { + Unknown = 0, /** Projection Coordinate System */ Projected = 1, /** Geographic latitude-longitude System */ Geographic = 2, /** Geocentric (X,Y,Z) Coordinate System */ Geocentric = 3, + + UserDefined = 32767, } /** Sub file type for tag 255 {@link TiffTag.OldSubFileType} */ diff --git a/packages/core/src/tiff.image.ts b/packages/core/src/tiff.image.ts index de3c4ba5..31cfa2cf 100644 --- a/packages/core/src/tiff.image.ts +++ b/packages/core/src/tiff.image.ts @@ -1,5 +1,13 @@ import { getCompressionMimeType, TiffCompressionMimeType, TiffMimeType } from './const/tiff.mime.js'; -import { Compression, SubFileType, TiffTag, TiffTagGeo, TiffTagGeoType, TiffTagType } from './const/tiff.tag.id.js'; +import { + Compression, + ModelTypeCode, + SubFileType, + TiffTag, + TiffTagGeo, + TiffTagGeoType, + TiffTagType, +} from './const/tiff.tag.id.js'; import { fetchAllOffsets, fetchLazy, getValueAt } from './read/tiff.tag.factory.js'; import { Tag, TagInline, TagOffset } from './read/tiff.tag.js'; import { Tiff } from './tiff.js'; @@ -336,12 +344,30 @@ export class TiffImage { /** * Attempt to read the EPSG Code from TiffGeoTags * - * looks at both TiffTagGeo.ProjectionGeoKey and TiffTagGeo.ProjectedCRSGeoKey + * looks at TiffTagGeo.ProjectionGeoKey, TiffTagGeo.ProjectedCRSGeoKey and TiffTagGeo.GeodeticCRSGeoKey * - * @returns EPSG Code if it exists + * @returns EPSG Code if it exists and is not user defined. */ get epsg(): number | null { - const projection = this.valueGeo(TiffTagGeo.ProjectionGeoKey) ?? this.valueGeo(TiffTagGeo.ProjectedCRSGeoKey); + const proj = this.valueGeo(TiffTagGeo.ProjectionGeoKey); + if (proj != null && proj !== InvalidProjectionCode) return proj; + + let projection: number | null = null; + switch (this.valueGeo(TiffTagGeo.GTModelTypeGeoKey)) { + case ModelTypeCode.Unknown: + return null; + case ModelTypeCode.Projected: + projection = this.valueGeo(TiffTagGeo.ProjectedCRSGeoKey); + break; + case ModelTypeCode.Geographic: + projection = this.valueGeo(TiffTagGeo.GeodeticCRSGeoKey); + break; + case ModelTypeCode.Geocentric: + projection = this.valueGeo(TiffTagGeo.GeodeticCRSGeoKey); + break; + case ModelTypeCode.UserDefined: + return null; + } if (projection === InvalidProjectionCode) return null; return projection; }