Skip to content

Commit 2e4f100

Browse files
committed
fixed bug in near resampling
1 parent 9f3a83e commit 2e4f100

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

geowarp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ const geowarp = function geowarp({
304304
const x = out_xmin + out_pixel_width * c;
305305
const pt_out_srs = [x, y];
306306
const [x_in_srs, y_in_srs] = same_srs ? pt_out_srs : inverse(pt_out_srs);
307-
const xInRasterPixels = Math.round((x_in_srs - in_xmin) / in_pixel_width);
308-
const yInRasterPixels = Math.round((in_ymax - y_in_srs) / in_pixel_height);
307+
const xInRasterPixels = Math.floor((x_in_srs - in_xmin) / in_pixel_width);
308+
const yInRasterPixels = Math.floor((in_ymax - y_in_srs) / in_pixel_height);
309309
let pixel = [];
310310
for (let i = 0; i < read_bands.length; i++) {
311311
const read_band = read_bands[i];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"fast-counter": "^0.1.0",
4747
"find-and-read": "^1.2.0",
4848
"flug": "^2.3.1",
49-
"geotiff": "^1.0.9",
49+
"geotiff": "^2.0.7",
5050
"geotiff-read-bbox": "*",
5151
"pngjs": "^6.0.0",
5252
"proj4-fully-loaded": "^0.2.0",

test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import reprojectBoundingBox from "reproject-bbox";
1717
// @ts-ignore
1818
import tilebelt from "@mapbox/tilebelt";
1919
// @ts-ignore
20+
import { transform } from "xdim";
21+
// @ts-ignore
2022
import writeImage from "write-image";
2123

2224
import geowarp from "./geowarp";
@@ -301,6 +303,8 @@ const runTileTests = async ({
301303

302304
[
303305
{
306+
// note: the left edge of the tile is actually west of the left edge of the geotiff,
307+
// thus the resulting image should appear to have a black stripe on the left edge
304308
x: 40,
305309
y: 96,
306310
z: 8,
@@ -422,3 +426,34 @@ const runTileTests = async ({
422426
eq(result.read_bands, [0, 1]);
423427
});
424428
});
429+
430+
test("georaster-layer-for-leaflet v3 issues", async ({ eq }) => {
431+
const filename = "example_4326.tif";
432+
const filepath = resolve(__dirname, "./test-data", filename);
433+
const geotiff = await fromFile(filepath);
434+
const image = await geotiff.getImage(0);
435+
const rasters = await image.readRasters();
436+
const { inverse, forward } = proj4("EPSG:4326", "EPSG:3857");
437+
const in_height = image.getHeight();
438+
const in_width = image.getWidth();
439+
const in_data = transform({ data: rasters, from: "[band][row,column]", to: "[band][row][column]", sizes: { band: rasters.length, row: in_height, column: in_width } }).data;
440+
geowarp({
441+
debug_level: 0,
442+
forward,
443+
inverse,
444+
in_data,
445+
in_bbox: image.getBoundingBox(),
446+
in_layout: "[band][row][column]",
447+
in_srs: 4326,
448+
in_width,
449+
in_height,
450+
out_array_types: ["Array", "Array", "Array"],
451+
out_bbox: [149.99999998948465, 49.99999988790859, 309.99999995583534, 159.99999987996836],
452+
out_layout: "[band][row][column]",
453+
out_srs: 3857,
454+
out_height: 256,
455+
out_width: 256,
456+
method: "near",
457+
round: false
458+
});
459+
});

0 commit comments

Comments
 (0)