From 5666191de2162cd4cd6b58d3909d5e3caf3baa9d Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sat, 26 Jun 2021 20:48:28 -0700 Subject: [PATCH 01/18] initial declaration file push --- package-lock.json | 25 +++++++++---- package.json | 2 ++ src/index.d.ts | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 src/index.d.ts 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..185824c 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "dist/geoblaze.node.min.js", "browser": "./dist/geoblaze.web.min.js", "unpkg": "./dist/geoblaze.web.min.js", + "types": "src/index.d.ts", "scripts": { "analyze": "webpack --config webpack.analyze.js", "build": "npm run build:dev && npm run build:prod", @@ -48,6 +49,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..feccafb --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,92 @@ +import { Point, Polygon, Feature, BBox } from "geojson"; + +export declare type GeoblazeBBox = { + xmin: number; + xmax: number; + ymin: number; + ymax: number; +}; + +export interface HistogramOptions { + scaleType: "nominal" | "ratio"; + numClasses: number; + classType: "equal-interval" | "quantile"; +} + +export interface Histogram { + [binKey: string]: number[]; +} + +export class GeoRaster { + constructor( + data: object | string | Buffer | ArrayBuffer | number[][], + metadata: any, + debug: any + ); +} + +export type InputPolygon = number[][][] | Polygon | Feature; +export type InputPoint = number[] | Point | Feature; +export type InputBBox = BBox | GeoblazeBBox; + +export function bandArithmetic( + raster: GeoRaster, + arithmetic: any +): Promise; + +export function get( + raster: GeoRaster, + geom: any, + flat: boolean +): Promise; + +// Done +export function histogram( + raster: GeoRaster, + geom: string | InputPolygon | null | undefined, + options: HistogramOptions +): Histogram[]; + +export function identify( + raster: GeoRaster, + geom?: string | InputPoint | null +): number[]; + +export function load(urlOrFile: object | string): Promise; + +export function max( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function mean( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function median( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function min( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function mode( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function rasterCalculator( + raster: GeoRaster, + operation: string +): GeoRaster; + +export function sum( + raster: GeoRaster, + geom: string | InputPolygon | null, + test?: any, + debug?: boolean +): Promise>; From 9156484fb5a4fcdf1c4f0640b81b33533bfff58b Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sat, 26 Jun 2021 21:16:41 -0700 Subject: [PATCH 02/18] bandArithmetic --- src/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index feccafb..107e262 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -31,12 +31,12 @@ export type InputBBox = BBox | GeoblazeBBox; export function bandArithmetic( raster: GeoRaster, - arithmetic: any + operation: string ): Promise; export function get( raster: GeoRaster, - geom: any, + geom: InputBBox | null | undefined, flat: boolean ): Promise; From eda21e5800b46f47583c61735c211739d6a38d5f Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 07:39:42 -0700 Subject: [PATCH 03/18] change dec filename, add test, migrate to unknown cell value --- package.json | 5 ++- src/geoblaze.d.ts | 94 +++++++++++++++++++++++++++++++++++++++++++++++ src/index.d.ts | 92 ---------------------------------------------- 3 files changed, 97 insertions(+), 94 deletions(-) create mode 100644 src/geoblaze.d.ts delete mode 100644 src/index.d.ts diff --git a/package.json b/package.json index 185824c..9d6ff75 100644 --- a/package.json +++ b/package.json @@ -5,16 +5,17 @@ "main": "dist/geoblaze.node.min.js", "browser": "./dist/geoblaze.web.min.js", "unpkg": "./dist/geoblaze.web.min.js", - "types": "src/index.d.ts", + "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/geoblaze.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", diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts new file mode 100644 index 0000000..3a02280 --- /dev/null +++ b/src/geoblaze.d.ts @@ -0,0 +1,94 @@ +import { Point, Polygon, Feature, BBox } from "geojson"; + +declare module 'geoblaze' { + export declare type GeoblazeBBox = { + xmin: number; + xmax: number; + ymin: number; + ymax: number; + }; + + export interface HistogramOptions { + scaleType: "nominal" | "ratio"; + numClasses: number; + classType: "equal-interval" | "quantile"; + } + + export interface Histogram { + [binKey: string]: number[]; + } + + export class GeoRaster { + constructor( + data: object | string | Buffer | ArrayBuffer | number[][], + metadata: any, + debug: any + ); + } + + export type InputPolygon = number[][][] | Polygon | Feature; + export type InputPoint = number[] | Point | Feature; + export type InputBBox = BBox | GeoblazeBBox; + + export function bandArithmetic( + raster: GeoRaster, + operation: string + ): Promise; + + export function get( + raster: GeoRaster, + geom: InputBBox | null | undefined, + flat: boolean + ): Promise; + + // Done + export function histogram( + raster: GeoRaster, + geom: string | InputPolygon | null | undefined, + options: HistogramOptions + ): Histogram[]; + + export function identify( + raster: GeoRaster, + geom?: string | InputPoint | null + ): unknown[]; + + export function load(urlOrFile: object | string): Promise; + + export function max( + raster: GeoRaster, + geom: string | InputPolygon | null + ): Promise; + + export function mean( + raster: GeoRaster, + geom: string | InputPolygon | null + ): Promise; + + export function median( + raster: GeoRaster, + geom: string | InputPolygon | null + ): Promise; + + export function min( + raster: GeoRaster, + geom: string | InputPolygon | null + ): Promise; + + export function mode( + raster: GeoRaster, + geom: string | InputPolygon | null + ): Promise; + + export function rasterCalculator( + raster: GeoRaster, + operation: string + ): GeoRaster; + + export function sum( + raster: GeoRaster, + geom: string | InputPolygon | null, + test?: (cellValue: unknown) => boolean, + debug?: boolean + ): Promise>; +} \ No newline at end of file diff --git a/src/index.d.ts b/src/index.d.ts deleted file mode 100644 index 107e262..0000000 --- a/src/index.d.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { Point, Polygon, Feature, BBox } from "geojson"; - -export declare type GeoblazeBBox = { - xmin: number; - xmax: number; - ymin: number; - ymax: number; -}; - -export interface HistogramOptions { - scaleType: "nominal" | "ratio"; - numClasses: number; - classType: "equal-interval" | "quantile"; -} - -export interface Histogram { - [binKey: string]: number[]; -} - -export class GeoRaster { - constructor( - data: object | string | Buffer | ArrayBuffer | number[][], - metadata: any, - debug: any - ); -} - -export type InputPolygon = number[][][] | Polygon | Feature; -export type InputPoint = number[] | Point | Feature; -export type InputBBox = BBox | GeoblazeBBox; - -export function bandArithmetic( - raster: GeoRaster, - operation: string -): Promise; - -export function get( - raster: GeoRaster, - geom: InputBBox | null | undefined, - flat: boolean -): Promise; - -// Done -export function histogram( - raster: GeoRaster, - geom: string | InputPolygon | null | undefined, - options: HistogramOptions -): Histogram[]; - -export function identify( - raster: GeoRaster, - geom?: string | InputPoint | null -): number[]; - -export function load(urlOrFile: object | string): Promise; - -export function max( - raster: GeoRaster, - geom: string | InputPolygon | null -): Promise; - -export function mean( - raster: GeoRaster, - geom: string | InputPolygon | null -): Promise; - -export function median( - raster: GeoRaster, - geom: string | InputPolygon | null -): Promise; - -export function min( - raster: GeoRaster, - geom: string | InputPolygon | null -): Promise; - -export function mode( - raster: GeoRaster, - geom: string | InputPolygon | null -): Promise; - -export function rasterCalculator( - raster: GeoRaster, - operation: string -): GeoRaster; - -export function sum( - raster: GeoRaster, - geom: string | InputPolygon | null, - test?: any, - debug?: boolean -): Promise>; From 26993aef43602b8a8d08ce5818ab0db921a8f871 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 07:55:08 -0700 Subject: [PATCH 04/18] rasterCalc, georaster note --- src/geoblaze.d.ts | 183 +++++++++++++++++++++++----------------------- 1 file changed, 91 insertions(+), 92 deletions(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 3a02280..395754e 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -1,94 +1,93 @@ import { Point, Polygon, Feature, BBox } from "geojson"; -declare module 'geoblaze' { - export declare type GeoblazeBBox = { - xmin: number; - xmax: number; - ymin: number; - ymax: number; - }; - - export interface HistogramOptions { - scaleType: "nominal" | "ratio"; - numClasses: number; - classType: "equal-interval" | "quantile"; - } - - export interface Histogram { - [binKey: string]: number[]; - } - - export class GeoRaster { - constructor( - data: object | string | Buffer | ArrayBuffer | number[][], - metadata: any, - debug: any - ); - } - - export type InputPolygon = number[][][] | Polygon | Feature; - export type InputPoint = number[] | Point | Feature; - export type InputBBox = BBox | GeoblazeBBox; - - export function bandArithmetic( - raster: GeoRaster, - operation: string - ): Promise; - - export function get( - raster: GeoRaster, - geom: InputBBox | null | undefined, - flat: boolean - ): Promise; - - // Done - export function histogram( - raster: GeoRaster, - geom: string | InputPolygon | null | undefined, - options: HistogramOptions - ): Histogram[]; - - export function identify( - raster: GeoRaster, - geom?: string | InputPoint | null - ): unknown[]; - - export function load(urlOrFile: object | string): Promise; - - export function max( - raster: GeoRaster, - geom: string | InputPolygon | null - ): Promise; - - export function mean( - raster: GeoRaster, - geom: string | InputPolygon | null - ): Promise; - - export function median( - raster: GeoRaster, - geom: string | InputPolygon | null - ): Promise; - - export function min( - raster: GeoRaster, - geom: string | InputPolygon | null - ): Promise; - - export function mode( - raster: GeoRaster, - geom: string | InputPolygon | null - ): Promise; - - export function rasterCalculator( - raster: GeoRaster, - operation: string - ): GeoRaster; - - export function sum( - raster: GeoRaster, - geom: string | InputPolygon | null, - test?: (cellValue: unknown) => boolean, - debug?: boolean - ): Promise>; -} \ No newline at end of file +/** Migrate to georaster library */ +export class GeoRaster { + constructor( + data: object | string | Buffer | ArrayBuffer | number[][], + metadata: any, + debug: any + ); +} + +export type GeoblazeBBox = { + xmin: number; + xmax: number; + ymin: number; + ymax: number; +}; + +export interface HistogramOptions { + scaleType: "nominal" | "ratio"; + numClasses: number; + classType: "equal-interval" | "quantile"; +} + +export interface Histogram { + [binKey: string]: number[]; +} + +export type InputPolygon = number[][][] | Polygon | Feature; +export type InputPoint = number[] | Point | Feature; +export type InputBBox = BBox | GeoblazeBBox; + +export function bandArithmetic( + raster: GeoRaster, + operation: string +): Promise; + +export function get( + raster: GeoRaster, + geom: InputBBox | null | undefined, + flat: boolean +): Promise; + +// Done +export function histogram( + raster: GeoRaster, + geom: string | InputPolygon | null | undefined, + options: HistogramOptions +): Histogram[]; + +export function identify( + raster: GeoRaster, + geom?: string | InputPoint | null +): unknown[]; + +export function load(urlOrFile: object | string): Promise; + +export function max( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function mean( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function median( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function min( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function mode( + raster: GeoRaster, + geom: string | InputPolygon | null +): Promise; + +export function rasterCalculator( + raster: GeoRaster, + operation: (() => unknown) | string +): GeoRaster; + +export function sum( + raster: GeoRaster, + geom: string | InputPolygon | null, + test?: (cellValue: unknown) => boolean, + debug?: boolean +): Promise>; From 9207c1c6d8706a34a443120708266aa887b36dc7 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 08:17:16 -0700 Subject: [PATCH 05/18] identify return number --- src/geoblaze.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 395754e..9443fe0 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -51,7 +51,7 @@ export function histogram( export function identify( raster: GeoRaster, geom?: string | InputPoint | null -): unknown[]; +): number[]; export function load(urlOrFile: object | string): Promise; From 45e1d031347e760309776a0e6d6269faddac0c63 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 09:09:12 -0700 Subject: [PATCH 06/18] Rework Georaster interface --- src/geoblaze.d.ts | 72 +++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 9443fe0..339fc79 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -1,12 +1,30 @@ import { Point, Polygon, Feature, BBox } from "geojson"; -/** Migrate to georaster library */ -export class GeoRaster { - constructor( - data: object | string | Buffer | ArrayBuffer | number[][], - metadata: any, - debug: any - ); +export interface Georaster { + /** array of raster bands, each of which is a 2D array of cell values */ + values: number[][][]; + /** raster height in units of projection */ + height: number; + /** raster width in units of projection */ + width: number; + /** raster height in pixels */ + pixelHeight: number; + /** raster width in pixels */ + pixelWidth: number; + /** Projection identifier */ + projection: unknown; + /** left boundary, in units of projection*/ + xmin: number; + /** right boundary, in units of projection */ + xmax: number; + /** top boundary (image y-axis is inverse of cartesian), in units of projection */ + ymin: number; + /** bottom boundary (image y-axis is inverse of cartesian), in units of projection */ + ymax: number; + /** cell value representing "no data" in raster */ + noDataValue: number; + /** number of bands in raster */ + numberOfRasters: number; } export type GeoblazeBBox = { @@ -31,62 +49,62 @@ export type InputPoint = number[] | Point | Feature; export type InputBBox = BBox | GeoblazeBBox; export function bandArithmetic( - raster: GeoRaster, + raster: Georaster, operation: string -): Promise; +): Promise; export function get( - raster: GeoRaster, + raster: Georaster, geom: InputBBox | null | undefined, flat: boolean -): Promise; +): Promise; // Done export function histogram( - raster: GeoRaster, + raster: Georaster, geom: string | InputPolygon | null | undefined, options: HistogramOptions ): Histogram[]; export function identify( - raster: GeoRaster, + raster: Georaster, geom?: string | InputPoint | null ): number[]; -export function load(urlOrFile: object | string): Promise; +export function load(urlOrFile: object | string): Promise; export function max( - raster: GeoRaster, + raster: Georaster, geom: string | InputPolygon | null -): Promise; +): Promise; export function mean( - raster: GeoRaster, + raster: Georaster, geom: string | InputPolygon | null -): Promise; +): Promise; export function median( - raster: GeoRaster, + raster: Georaster, geom: string | InputPolygon | null -): Promise; +): Promise; export function min( - raster: GeoRaster, + raster: Georaster, geom: string | InputPolygon | null -): Promise; +): Promise; export function mode( - raster: GeoRaster, + raster: Georaster, geom: string | InputPolygon | null -): Promise; +): Promise; export function rasterCalculator( - raster: GeoRaster, + raster: Georaster, operation: (() => unknown) | string -): GeoRaster; +): Georaster; export function sum( - raster: GeoRaster, + raster: Georaster, geom: string | InputPolygon | null, test?: (cellValue: unknown) => boolean, debug?: boolean From 664af2e8dd89a804eccdae7642de6a89d8b56ea1 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 09:32:58 -0700 Subject: [PATCH 07/18] improve rasterCalculator operation --- src/geoblaze.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 339fc79..20aafbd 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -100,7 +100,7 @@ export function mode( export function rasterCalculator( raster: Georaster, - operation: (() => unknown) | string + operation: ((...cellValuesPerBand: number[]) => number) | string ): Georaster; export function sum( From 9dd5fb8119ba13937c1953d2c0d67a7c698b094d Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 10:27:50 -0700 Subject: [PATCH 08/18] add mins, maxs, ranges --- src/geoblaze.d.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 20aafbd..874ea70 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -1,7 +1,7 @@ import { Point, Polygon, Feature, BBox } from "geojson"; export interface Georaster { - /** array of raster bands, each of which is a 2D array of cell values */ + /** raster values. first dimension is raster band, remainder is 2D array of cell values */ values: number[][][]; /** raster height in units of projection */ height: number; @@ -23,8 +23,14 @@ export interface Georaster { ymax: number; /** cell value representing "no data" in raster */ noDataValue: number; - /** number of bands in raster */ + /** number of raster bands */ numberOfRasters: number; + /** Minimum cell value for each raster band. Indexed by band number */ + mins: number[] + /** Maximum cell value for each raster band. Indexed by band number */ + maxs: number[] + /** difference between max and min for each raster band. Indexed by band number */ + ranges: number[] } export type GeoblazeBBox = { From c180a9a7efaf0fb3c7117ce36dd8d058c44d454a Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 10:29:27 -0700 Subject: [PATCH 09/18] sum improve --- src/geoblaze.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 874ea70..05683e7 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -112,6 +112,6 @@ export function rasterCalculator( export function sum( raster: Georaster, geom: string | InputPolygon | null, - test?: (cellValue: unknown) => boolean, + test?: (cellValue: number) => boolean, debug?: boolean -): Promise>; +): Promise>; From b89cde940660c53dbd3b024d783b9b4405db3807 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 10:35:42 -0700 Subject: [PATCH 10/18] Make geom optional for all --- src/geoblaze.d.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 05683e7..44df77c 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -65,7 +65,6 @@ export function get( flat: boolean ): Promise; -// Done export function histogram( raster: Georaster, geom: string | InputPolygon | null | undefined, @@ -74,34 +73,34 @@ export function histogram( export function identify( raster: Georaster, - geom?: string | InputPoint | null + geom: string | InputPoint | null | undefined ): number[]; export function load(urlOrFile: object | string): Promise; export function max( raster: Georaster, - geom: string | InputPolygon | null + geom: string | InputPolygon | null | undefined ): Promise; export function mean( raster: Georaster, - geom: string | InputPolygon | null + geom: string | InputPolygon | null | undefined ): Promise; export function median( raster: Georaster, - geom: string | InputPolygon | null + geom: string | InputPolygon | null | undefined ): Promise; export function min( raster: Georaster, - geom: string | InputPolygon | null + geom: string | InputPolygon | null | undefined ): Promise; export function mode( raster: Georaster, - geom: string | InputPolygon | null + geom: string | InputPolygon | null | undefined ): Promise; export function rasterCalculator( @@ -111,7 +110,7 @@ export function rasterCalculator( export function sum( raster: Georaster, - geom: string | InputPolygon | null, + geom: string | InputPolygon | null | undefined, test?: (cellValue: number) => boolean, debug?: boolean ): Promise>; From a1f5b369f2caf9fcadd452319c6541d42c6edd99 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 15:50:59 -0700 Subject: [PATCH 11/18] migrate georaster bits upstream and refactor function signatures --- src/geoblaze.d.ts | 80 ++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 56 deletions(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 44df77c..5e35ac4 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -1,37 +1,5 @@ import { Point, Polygon, Feature, BBox } from "geojson"; - -export interface Georaster { - /** raster values. first dimension is raster band, remainder is 2D array of cell values */ - values: number[][][]; - /** raster height in units of projection */ - height: number; - /** raster width in units of projection */ - width: number; - /** raster height in pixels */ - pixelHeight: number; - /** raster width in pixels */ - pixelWidth: number; - /** Projection identifier */ - projection: unknown; - /** left boundary, in units of projection*/ - xmin: number; - /** right boundary, in units of projection */ - xmax: number; - /** top boundary (image y-axis is inverse of cartesian), in units of projection */ - ymin: number; - /** bottom boundary (image y-axis is inverse of cartesian), in units of projection */ - ymax: number; - /** cell value representing "no data" in raster */ - noDataValue: number; - /** number of raster bands */ - numberOfRasters: number; - /** Minimum cell value for each raster band. Indexed by band number */ - mins: number[] - /** Maximum cell value for each raster band. Indexed by band number */ - maxs: number[] - /** difference between max and min for each raster band. Indexed by band number */ - ranges: number[] -} +import { Georaster } from "georaster" export type GeoblazeBBox = { xmin: number; @@ -54,63 +22,63 @@ export type InputPolygon = number[][][] | Polygon | Feature; export type InputPoint = number[] | Point | Feature; export type InputBBox = BBox | GeoblazeBBox; -export function bandArithmetic( +export const bandArithmetic: ( raster: Georaster, operation: string -): Promise; +) => Promise; -export function get( +export const get: ( raster: Georaster, geom: InputBBox | null | undefined, flat: boolean -): Promise; +) => Promise; -export function histogram( +export const histogram: ( raster: Georaster, geom: string | InputPolygon | null | undefined, options: HistogramOptions -): Histogram[]; +) => Histogram[]; -export function identify( +export const identify: ( raster: Georaster, geom: string | InputPoint | null | undefined -): number[]; +) => number[]; -export function load(urlOrFile: object | string): Promise; +export const load: (urlOrFile: object | string) => Promise; -export function max( +export const max: ( raster: Georaster, geom: string | InputPolygon | null | undefined -): Promise; +) => Promise; -export function mean( +export const mean: ( raster: Georaster, geom: string | InputPolygon | null | undefined -): Promise; +) => Promise; -export function median( +export const median: ( raster: Georaster, geom: string | InputPolygon | null | undefined -): Promise; +) => Promise; -export function min( +export const min: ( raster: Georaster, geom: string | InputPolygon | null | undefined -): Promise; +) => Promise; -export function mode( +export const mode: ( raster: Georaster, geom: string | InputPolygon | null | undefined -): Promise; +) => Promise; -export function rasterCalculator( +export const rasterCalculator: ( raster: Georaster, operation: ((...cellValuesPerBand: number[]) => number) | string -): Georaster; +) => Georaster; -export function sum( +export const sum: ( raster: Georaster, geom: string | InputPolygon | null | undefined, test?: (cellValue: number) => boolean, debug?: boolean -): Promise>; +) => Promise>; From f82a53169f5121208283c65e5c113ad63bd53dc8 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 17:17:45 -0700 Subject: [PATCH 12/18] solve default export object --- src/geoblaze.d.ts | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 5e35ac4..aa60f52 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -1,26 +1,29 @@ import { Point, Polygon, Feature, BBox } from "geojson"; -import { Georaster } from "georaster" +import { Georaster } from "georaster"; -export type GeoblazeBBox = { +// re-rexport so that downstream user doesn't need to track it down +export { Georaster } from "georaster" + +type GeoblazeBBox = { xmin: number; xmax: number; ymin: number; ymax: number; }; -export interface HistogramOptions { +interface HistogramOptions { scaleType: "nominal" | "ratio"; numClasses: number; classType: "equal-interval" | "quantile"; } -export interface Histogram { +interface Histogram { [binKey: string]: number[]; } -export type InputPolygon = number[][][] | Polygon | Feature; -export type InputPoint = number[] | Point | Feature; -export type InputBBox = BBox | GeoblazeBBox; +type InputPolygon = number[][][] | Polygon | Feature; +type InputPoint = number[] | Point | Feature; +type InputBBox = BBox | GeoblazeBBox; export const bandArithmetic: ( raster: Georaster, @@ -82,3 +85,20 @@ export const sum: ( test?: (cellValue: number) => boolean, debug?: boolean ) => Promise>; + +// 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; From 5fc1962b40db4869b94178bc815b9c9db1b412a5 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Sun, 27 Jun 2021 17:31:06 -0700 Subject: [PATCH 13/18] comments --- src/geoblaze.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index aa60f52..5fe8510 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -1,7 +1,7 @@ import { Point, Polygon, Feature, BBox } from "geojson"; import { Georaster } from "georaster"; -// re-rexport so that downstream user doesn't need to track it down +// re-rexport for easy access by downstream user export { Georaster } from "georaster" type GeoblazeBBox = { @@ -21,6 +21,8 @@ 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; From 958810c37f81fafa64f7468098bbf1a4f75d496d Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Mon, 28 Jun 2021 09:22:51 -0700 Subject: [PATCH 14/18] type fixes --- src/geoblaze.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 5fe8510..264aa55 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -36,7 +36,7 @@ export const get: ( raster: Georaster, geom: InputBBox | null | undefined, flat: boolean -) => Promise; +) => number[] | number[][]; export const histogram: ( raster: Georaster, @@ -54,39 +54,39 @@ export const load: (urlOrFile: object | string) => Promise; export const max: ( raster: Georaster, geom: string | InputPolygon | null | undefined -) => Promise; +) => number[]; export const mean: ( raster: Georaster, geom: string | InputPolygon | null | undefined -) => Promise; +) => number[]; export const median: ( raster: Georaster, geom: string | InputPolygon | null | undefined -) => Promise; +) => number[]; export const min: ( raster: Georaster, geom: string | InputPolygon | null | undefined -) => Promise; +) => number[]; export const mode: ( raster: Georaster, geom: string | InputPolygon | null | undefined -) => Promise; +) => number[]; export const rasterCalculator: ( raster: Georaster, operation: ((...cellValuesPerBand: number[]) => number) | string -) => Georaster; +) => Promise; export const sum: ( raster: Georaster, geom: string | InputPolygon | null | undefined, test?: (cellValue: number) => boolean, debug?: boolean -) => Promise>; +) => number[]; // Create typed object matching default export in index.js declare const defaultExports: { From 77146d72e0651093d3eac536a53190776971d5a7 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Mon, 28 Jun 2021 09:27:03 -0700 Subject: [PATCH 15/18] get - add missing dimension --- src/geoblaze.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index 264aa55..c2388b2 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -36,7 +36,7 @@ export const get: ( raster: Georaster, geom: InputBBox | null | undefined, flat: boolean -) => number[] | number[][]; +) => number[] | number[][][]; export const histogram: ( raster: Georaster, From dd695a5a4ed8a05c38944029bdfbf779e068be86 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Mon, 28 Jun 2021 09:35:14 -0700 Subject: [PATCH 16/18] get - add missing dimension for flat --- src/geoblaze.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index c2388b2..a81a619 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -36,7 +36,7 @@ export const get: ( raster: Georaster, geom: InputBBox | null | undefined, flat: boolean -) => number[] | number[][][]; +) => number[][] | number[][][]; export const histogram: ( raster: Georaster, From 033c9d12f2f06fc300f506766d83ef5ceb250cec Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Wed, 14 Jul 2021 10:32:54 -0700 Subject: [PATCH 17/18] fix histogram --- src/geoblaze.d.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/geoblaze.d.ts b/src/geoblaze.d.ts index a81a619..7981243 100644 --- a/src/geoblaze.d.ts +++ b/src/geoblaze.d.ts @@ -13,12 +13,14 @@ type GeoblazeBBox = { interface HistogramOptions { scaleType: "nominal" | "ratio"; - numClasses: number; - classType: "equal-interval" | "quantile"; + /** required for ratio scaleType */ + numClasses?: number; + /** required for ratio scaleType */ + classType?: "equal-interval" | "quantile"; } interface Histogram { - [binKey: string]: number[]; + [binKey: string]: number; } // Some geoblaze methods accept a geometry, and its accepted in a variety of From cfb07714ee31b136adc924a7f7cf10409a9343b2 Mon Sep 17 00:00:00 2001 From: Tim Welch Date: Tue, 20 Jul 2021 08:46:26 -0700 Subject: [PATCH 18/18] change declaration file name to support automatic type import when using index.js internally --- package.json | 2 +- src/{geoblaze.d.ts => index.d.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{geoblaze.d.ts => index.d.ts} (100%) diff --git a/package.json b/package.json index 9d6ff75..33f7f4c 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "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/geoblaze.d.ts dist/geoblaze.d.ts", + "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", diff --git a/src/geoblaze.d.ts b/src/index.d.ts similarity index 100% rename from src/geoblaze.d.ts rename to src/index.d.ts