geowarp
Super Low-Level Raster Reprojection and Resampling Library
install
npm install -S geowarp
usage
const geowarp = require("geowarp");
const proj4 = require("proj4-fully-loaded");
const result = geowarp({
debug_level: 2,
forward: proj4("EPSG:" + in_srs, "EPSG:3857").forward,
inverse: proj4("EPSG:" + in_srs, "EPSG:3857").inverse,
in_data: [
[0, 123, 123, 162, ...],
[213, 41, 62, 124, ...],
[84, 52, 124, 235, ...]
],
in_bbox: [ -122.51, 40.97, -122.34, 41.11 ],
in_layout: "[band][row,column]",
in_no_data: -99,
in_srs: 4326,
in_geotransform: [337934.48363, -0.142999, -0.576775, 7840518.4648, -0.57677, 0.14299],
in_width: 1032,
in_height: 1015,
out_array_types: ["Array", "Array", "Uint8Array"],
out_bands: [13, 12, 11],
out_bbox: [-13638811.83098057, 5028944.964938315, -13619243.951739563, 5028944.964938315],
out_data: [[[[],[],[],...],[[],[],[],...],[[],[],[],...],[[],[],[],...],...]],
out_no_data: -99,
out_layout: "[row][column][band]",
out_srs: 3857,
out_pixel_depth: 3,
out_height: 256,
out_width: 256,
out_resolution: [0.5, 0.5],
method: 'median',
round: true,
theoretical_min: 0,
theoretical_max: 255,
expr: ({ pixel }) => {
return pixel.map(value => Math.min(value, 100));
},
insert_null_strategy: "skip",
read_bands: [0, 1, 2],
cutline: geojson,
cutline_srs: 4326,
cutline_forward: proj4("EPSG:4326", "EPSG:3857").forward,
cutline_strategy: "inside",
turbo: true,
insert_pixel: ({ row, column, pixel }) => {
context.fillStyle = toColor(pixel);
context.fillRect(column, row, 1, 1);
},
insert_sample: ({ row, column, pixel }) => {
const [xmin, ymin, xmax, ymax] = scalePixel([column, row], [x_scale, y_scale]);
for (let y = ymin; y < ymax; y++) {
for (let x = xmin; x < xmax; x++) {
insert_pixel({ row: y, column: x, pixel });
}
}
},
skip_no_data_strategy: "any"
});
result is
{
data: [
[ [...], [...], [...] ],
]
}