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 all 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/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",
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
108 changes: 108 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { Point, Polygon, Feature, BBox } from "geojson";
import { Georaster } from "georaster";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's super picky (and annoying), but could we use GeoRaster instead of Georaster? We've used Georaster before, but I'd like to migrate over to the new spelling. Sorry!


// re-rexport for easy access by downstream user
export { Georaster } from "georaster"

type GeoblazeBBox = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, could we use GeoBlaze... instead of Geoblaze? I know I've done a bad job of standardizing spelling, but would like to use GeoBlaze moving forward. Sorry again!

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<Polygon>;
type InputPoint = number[] | Point | Feature<Point>;
Comment on lines +28 to +29
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like FeatureCollection is also supported according to https://github.com/GeoTIFF/geoblaze/blob/master/src/utils/utils.module.js#L236. Not documented clearly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

type InputBBox = BBox | GeoblazeBBox;

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

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

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

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;