Skip to content

Commit

Permalink
fix(core): load more projection information
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Jan 7, 2024
1 parent 6001be4 commit 57dd0a9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/const/tiff.tag.id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
34 changes: 30 additions & 4 deletions packages/core/src/tiff.image.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 57dd0a9

Please sign in to comment.