Skip to content
Open
Show file tree
Hide file tree
Changes from 14 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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/georaster.bundle.min.js",
"browser": "./dist/georaster.browser.bundle.min.js",
"unpkg": "./dist/georaster.browser.bundle.min.js",
"types": "dist/georaster.d.ts",
"scripts": {
"analyze": "ANALYZE_GEORASTER_BUNDLE=true npm run build",
"clean": "rm -f ./dist/*",
Expand All @@ -16,10 +17,11 @@
"test-dev": "npm run dev && GEORASTER_TEST_BUNDLE_NAME='georaster.bundle.js' node ./node_modules/.bin/mocha --reporter spec",
"test-prod": "npm run build && GEORASTER_TEST_BUNDLE_NAME='georaster.bundle.min.js' node ./node_modules/.bin/mocha --reporter spec",
"dev": "webpack --mode development --target node && webpack --mode development --target web",
"build": "npm run build:prod",
"build": "npm run build:prod && npm run build:types",
"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:prod:web": "webpack --mode production --target web",
"build:types": "cp src/georaster.d.ts dist/georaster.d.ts"
},
"repository": {
"type": "git",
Expand Down
83 changes: 83 additions & 0 deletions src/georaster.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
declare function parseGeoraster(
data: object | string | Buffer | ArrayBuffer | number[][][],
/** the raster metadata */
metadata?: parseGeoraster.GeorasterMetadata,
/** whether or not to print debug statements */
debug?: boolean
): Promise<parseGeoraster.Georaster>;

// Match default CJS export in index.js
export = parseGeoraster;

// A namespace with the same name as the default export is needed to define additional type exports
// https://stackoverflow.com/a/51238234/4159809
declare namespace parseGeoraster {
/** defines the new raster image to generate as a window in the source raster image. Resolution (cell size) is determined from this */
export interface WindowOptions {
/** left side of the image window in pixel coordinates */
left: number
/** top of the image window in pixel coordinates */
top: number
/** right of the image window in pixel coordinates. Should be greater than left */
right: number
/** bottom of the image window in pixel coordinates. Should be greater than top */
bottom: number
/** width in pixels to make the resulting raster. Will resample and/or use overview if not same as right - left */
width: number
/** height in pixels to make the resulting raster. Will resample and/or use overview if not same as bottom - top */
height: number
/** method to map src raster values to result raster. Supports 'nearest' neighbor, defaults to 'bilinear' */
resampleMethod?: string
}

export interface Georaster {
/** raster values. first dimension is raster band, remainder is 2D array of cell values */
values: number[][][];
Comment thread
twelch marked this conversation as resolved.
Outdated
/** 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: number;
/** left boundary, in units of projection*/
xmin: number;
/** right boundary, in units of projection */
xmax: number;
/** bottom boundary, in units of projection */
ymin: number;
/** top boundary, 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[];
/** if raster initialized with a URL, this method is available to fetch a
* specific subset or 'window' without reading the entire raster into memory.
* If the window options do not align exactly with the source image then a new
* one is generated using the resampleMethod. The best available overview will
* also be used if they are available. */
getValues?: (options: WindowOptions) => Promise<number[][][]>;
/** experimental! returns a canvas picture of the data. */
toCanvas: (options: { height?: number; width?: number }) => ImageData
}

export type GeorasterMetadata = Pick<
Georaster,
| "noDataValue"
| "projection"
| "xmin"
| "ymax"
| "pixelWidth"
| "pixelHeight"
>;
}