Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Created June 23, 2023 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenLangbroek/3de4e7e67cf49c764edf449da319bf69 to your computer and use it in GitHub Desktop.
Save StevenLangbroek/3de4e7e67cf49c764edf449da319bf69 to your computer and use it in GitHub Desktop.
declare module 'geoblaze' {
import { Point, Polygon, Feature, BBox, MultiPolygon } from 'geojson';
import { Georaster } from 'georaster';
// re-rexport for easy access by downstream user
export { Georaster } from 'georaster';
export interface BlazeHistogram {
[key: string]: {
// count of pixels with this value
ct: number;
// the band value
n: number;
};
}
export type BlazeStats = {
name: string;
code: string;
count: number;
ratio: number;
histogram: BlazeHistogram;
};
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[][][]
| number[][][][]
| Polygon
| Feature<Polygon>
| MultiPolygon;
type InputPoint = number[] | Point | Feature<Point>;
type InputBBox = BBox | GeoblazeBBox;
export const bandArithmetic: (
raster: Georaster,
operation: string,
) => Promise<Georaster>;
export const get: (
raster: Georaster,
geom: InputBBox | null | undefined,
flat: boolean,
) => Promise<number[][] | number[][][]>;
export const histogram: (
raster: Georaster,
geom: string | InputPolygon | null | undefined,
options: HistogramOptions,
) => Promise<Histogram[]>;
export const identify: (
raster: Georaster,
geom: string | InputPoint | null | undefined,
) => Promise<number[]>;
export const load: (urlOrFile: object | string) => Promise<Georaster>;
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,
) => Promise<Georaster>;
export const sum: (
raster: Georaster,
geom: string | InputPolygon | null | undefined,
test?: (cellValue: number) => boolean,
debug?: boolean,
) => Promise<number[]>;
export const parse: (url: string) => Promise<Georaster>;
export const stats: (
raster: Georaster,
geom: string | InputPolygon | null | undefined,
) => Promise<BlazeStats[]>;
// Create constd 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;
parse: typeof parse;
stats: typeof stats;
};
export default defaultExports;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment