diff --git a/package-lock.json b/package-lock.json index bbe6667..e1b3f00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "license": "MIT", "dependencies": { "@turf/combine": "^4.7.3", + "@types/geojson": "^7946.0.7", "georaster": "^1.0.3", "get-depth": "0.0.0", "mathjs": "^6.6.1", @@ -1444,9 +1445,9 @@ "integrity": "sha1-beLx6YkLj2S2aeS0fAmyCJMGOXc=" }, "node_modules/@types/geojson": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-1.0.6.tgz", - "integrity": "sha512-Xqg/lIZMrUd0VRmSRbCAewtwGZiAk3mEUDvV4op1tGl+LvyPcb/MIOSxTl9z+9+J+R4/vpjiCAT4xeKzH9ji1w==" + "version": "7946.0.7", + "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.7.tgz", + "integrity": "sha512-wE2v81i4C4Ol09RtsWFAqg3BUitWbHSpSlIo+bNdsCJijO9sjme+zm+73ZMCa/qMC8UEERxzGbvmr1cffo2SiQ==" }, "node_modules/@types/glob": { "version": "7.1.3", @@ -12094,6 +12095,11 @@ "terraformer": "~1.0.4" } }, + "node_modules/terraformer-arcgis-parser/node_modules/@types/geojson": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-1.0.6.tgz", + "integrity": "sha512-Xqg/lIZMrUd0VRmSRbCAewtwGZiAk3mEUDvV4op1tGl+LvyPcb/MIOSxTl9z+9+J+R4/vpjiCAT4xeKzH9ji1w==" + }, "node_modules/terser": { "version": "4.8.0", "resolved": "https://registry.npmjs.org/terser/-/terser-4.8.0.tgz", @@ -15643,9 +15649,9 @@ "integrity": "sha1-beLx6YkLj2S2aeS0fAmyCJMGOXc=" }, "@types/geojson": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-1.0.6.tgz", - "integrity": "sha512-Xqg/lIZMrUd0VRmSRbCAewtwGZiAk3mEUDvV4op1tGl+LvyPcb/MIOSxTl9z+9+J+R4/vpjiCAT4xeKzH9ji1w==" + "version": "7946.0.7", + "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.7.tgz", + "integrity": "sha512-wE2v81i4C4Ol09RtsWFAqg3BUitWbHSpSlIo+bNdsCJijO9sjme+zm+73ZMCa/qMC8UEERxzGbvmr1cffo2SiQ==" }, "@types/glob": { "version": "7.1.3", @@ -24898,6 +24904,13 @@ "requires": { "@types/geojson": "^1.0.0", "terraformer": "~1.0.4" + }, + "dependencies": { + "@types/geojson": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-1.0.6.tgz", + "integrity": "sha512-Xqg/lIZMrUd0VRmSRbCAewtwGZiAk3mEUDvV4op1tGl+LvyPcb/MIOSxTl9z+9+J+R4/vpjiCAT4xeKzH9ji1w==" + } } }, "terser": { diff --git a/package.json b/package.json index c58b196..33f7f4c 100644 --- a/package.json +++ b/package.json @@ -5,15 +5,17 @@ "main": "dist/geoblaze.node.min.js", "browser": "./dist/geoblaze.web.min.js", "unpkg": "./dist/geoblaze.web.min.js", + "types": "dist/geoblaze.d.ts", "scripts": { "analyze": "webpack --config webpack.analyze.js", - "build": "npm run build:dev && npm run build:prod", + "build": "npm run build:dev && npm run build:prod && npm run build:types", "build:dev": "npm run build:dev:node && npm run build:dev:web", "build:dev:node": "webpack --mode development --target node", "build:dev:web": "webpack --mode development --target web", "build:prod": "npm run build:prod:node && npm run build:prod:web", "build:prod:node": "webpack --mode production --target node", "build:prod:web": "webpack --mode production --target web", + "build:types": "cp src/index.d.ts dist/geoblaze.d.ts", "dev": "webpack --mode development --target node --watch", "documentation": "./node_modules/.bin/documentation build src/** --config documentation.yml -f html -o docs && echo 'geoblaze.io' > docs/CNAME", "fix": "eslint src --fix", @@ -48,6 +50,7 @@ "homepage": "https://github.com/GeoTIFF/geoblaze#readme", "dependencies": { "@turf/combine": "^4.7.3", + "@types/geojson": "^7946.0.7", "georaster": "^1.0.3", "get-depth": "0.0.0", "mathjs": "^6.6.1", diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..7981243 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,108 @@ +import { Point, Polygon, Feature, BBox } from "geojson"; +import { Georaster } from "georaster"; + +// re-rexport for easy access by downstream user +export { Georaster } from "georaster" + +type GeoblazeBBox = { + xmin: number; + xmax: number; + ymin: number; + ymax: number; +}; + +interface HistogramOptions { + scaleType: "nominal" | "ratio"; + /** required for ratio scaleType */ + numClasses?: number; + /** required for ratio scaleType */ + classType?: "equal-interval" | "quantile"; +} + +interface Histogram { + [binKey: string]: number; +} + +// Some geoblaze methods accept a geometry, and its accepted in a variety of +// forms. These types group them for easy reuse +type InputPolygon = number[][][] | Polygon | Feature; +type InputPoint = number[] | Point | Feature; +type InputBBox = BBox | GeoblazeBBox; + +export const bandArithmetic: ( + raster: Georaster, + operation: string +) => Promise; + +export const get: ( + raster: Georaster, + geom: InputBBox | null | undefined, + flat: boolean +) => number[][] | number[][][]; + +export const histogram: ( + raster: Georaster, + geom: string | InputPolygon | null | undefined, + options: HistogramOptions +) => Histogram[]; + +export const identify: ( + raster: Georaster, + geom: string | InputPoint | null | undefined +) => number[]; + +export const load: (urlOrFile: object | string) => Promise; + +export const max: ( + raster: Georaster, + geom: string | InputPolygon | null | undefined +) => number[]; + +export const mean: ( + raster: Georaster, + geom: string | InputPolygon | null | undefined +) => number[]; + +export const median: ( + raster: Georaster, + geom: string | InputPolygon | null | undefined +) => number[]; + +export const min: ( + raster: Georaster, + geom: string | InputPolygon | null | undefined +) => number[]; + +export const mode: ( + raster: Georaster, + geom: string | InputPolygon | null | undefined +) => number[]; + +export const rasterCalculator: ( + raster: Georaster, + operation: ((...cellValuesPerBand: number[]) => number) | string +) => Promise; + +export const sum: ( + raster: Georaster, + geom: string | InputPolygon | null | undefined, + test?: (cellValue: number) => boolean, + debug?: boolean +) => number[]; + +// Create typed object matching default export in index.js +declare const defaultExports: { + bandArithmetic: typeof bandArithmetic; + get: typeof get; + histogram: typeof histogram; + identify: typeof identify; + load: typeof load; + max: typeof max; + mean: typeof mean; + median: typeof median; + min: typeof min; + mode: typeof mode; + rasterCalculator: typeof rasterCalculator; + sum: typeof sum; +}; +export default defaultExports;