Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typescript definitions #183

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/geoblaze.d.ts dist/geoblaze.d.ts",
DanielJDufour marked this conversation as resolved.
Show resolved Hide resolved
"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",
Expand Down Expand Up @@ -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",
Expand Down
111 changes: 111 additions & 0 deletions src/geoblaze.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { Point, Polygon, Feature, BBox } from "geojson";

export interface Georaster {
twelch marked this conversation as resolved.
Show resolved Hide resolved
/** 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;
twelch marked this conversation as resolved.
Show resolved Hide resolved
/** 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 = {
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<Polygon>;
export type InputPoint = number[] | Point | Feature<Point>;
export type InputBBox = BBox | GeoblazeBBox;

export function bandArithmetic(
raster: Georaster,
operation: string
): Promise<Georaster>;

export function get(
raster: Georaster,
geom: InputBBox | null | undefined,
flat: boolean
): Promise<Georaster>;

// 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<Georaster>;

export function max(
raster: Georaster,
geom: string | InputPolygon | null
): Promise<Georaster>;

export function mean(
raster: Georaster,
geom: string | InputPolygon | null
): Promise<Georaster>;

export function median(
raster: Georaster,
geom: string | InputPolygon | null
): Promise<Georaster>;

export function min(
raster: Georaster,
geom: string | InputPolygon | null
): Promise<Georaster>;

export function mode(
raster: Georaster,
geom: string | InputPolygon | null
): Promise<Georaster>;

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<Array<unknown>>;