@cogeotiff/core

中文文档
9.5.0发布于 2026/03/26MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 1.8万

与 云优化了 GEOTIff 和蒂夫斯语

中文使用文档
文档目录3 节
  1. 使用量
  2. 标记
  3. 实例

@ cogeotif/ 核心

与 云优化了 GEOTIff 和蒂夫斯语

  • 完全基于 Javascript, 在浏览器和节点中工作
  • 懒惰地装入 Tiffs 图像和元数据
  • 支持巨大的 100GB+ COG
  • 使用GDAL COG优化,一般每个瓦片只读取一到两个!
  • 从 URL、 文件、 Google Cloud 或 AWS S3 装入 Tiffs
  • 用于生产 LINZ的基图 从蒂夫斯取来数十亿块瓷砖!

使用量

从远程 http 源装入 COG

import { SourceHttp } from '@chunkd/source-url';
import { Tiff } from '@cogeotiff/core'

const source = new SourceHttp('https://example.com/cog.tif');
const tiff = await Tiff.create(source);

/** Load a specific tile from a specific image */
const tile = await tiff.images[5].getTile(2, 2);

/** Load the 5th image in the Tiff */
const img = tiff.images[5];
if (img.isTiled()) {
    /** Load tile x:10 y:10 */
    const tile = await img.getTile(10, 10);
    tile.mimeType; // image/jpeg
    tile.bytes; // Raw image buffer
}

/** Get the origin point of the tiff */
const origin = img.origin;
/** Bounding box of the tiff */
const bbox = img.bbox;

// Tiff tags can be accessed via some helpers
const noData = img.noData; // -9999
const noDataTag = img.tags.get(TiffTag.GdalNoData) // Tag information such as file offset or tagId
const noDataValue = img.value(TiffTag.GdalNoData) // "-9999" (tag is stored as a string)

标记

在打字符中,标记对于大多数常见的用例来说是一定的打字安全,

img.value(TiffTag.ImageWidth) // number
img.value(TiffTag.BitsPerSample) // number[]

有些标记会输出常数使其更容易使用

import {Photometric} from '@cogeotiff/core'


const photometric = img.value(TiffTag.Photometric)

if( photometric == Photometric.Rgb) { 
  // Tiff is a RGB photometric tiff
}

关于常数的完整列表,请参见 ./src/index.ts (中文(简体) )

GeoTiff 标记装入到一个单独的位置

import {RasterTypeKey} from '@cogeotiff/core'

const pixelIsArea = img.valueGeo(TiffTagGeo.GTRasterTypeGeoKey) == RasterTypeKey.PixelIsArea

实例

更多的例子可以看见

版本与发布记录

@cogeotiff/core 共发布 55 个版本,首次发布于 2019/09/12;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
9.5.0latest2026/03/267 个月前
9.4.02026/02/278 个月前
9.3.02026/02/238 个月前
9.2.02026/02/198 个月前
9.1.22025/11/1111 个月前
9.1.12025/11/101 年前

关于 @cogeotiff/core 的常见问题

@cogeotiff/core 是什么?

与 云优化了 GEOTIff 和蒂夫斯语

如何安装 @cogeotiff/core?

在项目目录运行 npm install @cogeotiff/core,或使用 pnpm add / yarn add / bun add。

@cogeotiff/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cogeotiff/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cogeotiff/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^12.20.0 || ^14.13.1 || >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cogeotiff/core 可以商用吗?

@cogeotiff/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cogeotiff/core 的下载量有多少?

根据 npm 官方下载统计,@cogeotiff/core 在 2026/10/11 – 2026/11/09 这 30 天内被下载 18,090 次,日均约 603 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cogeotiff/core 还在维护吗?

最新版本 9.5.0 发布于 2026/03/26(7 个月前);至今共发布 55 个版本,其中过去 12 个月发布了 5 个;首次发布于 2019/09/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。