Skip to content

Commit

Permalink
added insert_null_strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Dec 22, 2023
1 parent 1a1f97f commit 1b29584
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ const result = geowarp({
return pixel.map(value => Math.min(value, 100));
},

// optional
// whether to insert or skip null values
// "skip" - default, don't insert null values
// "insert" - try to insert null values into output data
insert_null_strategy: "skip",

// optional
// array of band indexes to read from
// use this if your expr function only uses select bands
Expand Down
1 change: 1 addition & 0 deletions geowarp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function geowarp(options: {
cutline_srs?: number | string | undefined;
cutline_forward?: reproject | undefined;
cutline_strategy?: "inside" | "outside" | string | undefined;
insert_null_strategy?: "skip" | "insert" | undefined;
skip_no_data_strategy?: "any" | "all" | undefined;
cache_process?: true | false | boolean | undefined;
turbo?: boolean | undefined;
Expand Down
49 changes: 29 additions & 20 deletions geowarp.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const geowarp = function geowarp({
turbo = false, // enable experimental turbocharging via proj-turbo
insert_pixel, // over-ride function that inserts data into output multi-dimensional array
insert_sample, // over-ride function that inserts each sample into the output multi-dimensional array (calls insert)
insert_null_strategy = "skip", // whether to insert or skip null values
skip_no_data_strategy, // skip processing pixels if "any" or "all" values are "no data"
cache_process = false // whether to try to cache the processing step
// cache_functions // this really helps if functions are asynchronous and require posting to a web worker
Expand Down Expand Up @@ -669,18 +670,20 @@ const geowarp = function geowarp({
// apply band math expression, no-data mapping, and rounding when applicable
const pixel = process({ pixel: raw_values });

if (cutline) {
intersect_options.per_pixel = ({ row, column }) => {
if (segments_by_row[row].some(([start, end]) => column >= start && column <= end)) {
if (pixel !== null || insert_null_strategy === "insert") {
if (cutline) {
intersect_options.per_pixel = ({ row, column }) => {
if (segments_by_row[row].some(([start, end]) => column >= start && column <= end)) {
insert_sample({ raw: raw_values, pixel, row, column });
}
};
} else {
intersect_options.per_pixel = ({ row, column }) => {
insert_sample({ raw: raw_values, pixel, row, column });
}
};
} else {
intersect_options.per_pixel = ({ row, column }) => {
insert_sample({ raw: raw_values, pixel, row, column });
};
};
}
dufour_peyton_intersection.calculate(intersect_options);
}
dufour_peyton_intersection.calculate(intersect_options);
}
}
}
Expand Down Expand Up @@ -710,14 +713,16 @@ const geowarp = function geowarp({

if (should_skip(raw_values)) continue;
const pixel = process({ pixel: raw_values });
insert_sample({
row: r,
column: c,
pixel,
raw: raw_values,
x_in_raster_pixels,
y_in_raster_pixels
});
if (pixel !== null || insert_null_strategy === "insert") {
insert_sample({
row: r,
column: c,
pixel,
raw: raw_values,
x_in_raster_pixels,
y_in_raster_pixels
});
}
}
}
}
Expand Down Expand Up @@ -815,7 +820,9 @@ const geowarp = function geowarp({
}
if (should_skip(raw_values)) continue;
const pixel = process({ pixel: raw_values });
insert_sample({ row: r, column: c, pixel, raw: raw_values });
if (pixel !== null || insert_null_strategy === "insert") {
insert_sample({ row: r, column: c, pixel, raw: raw_values });
}
}
}
}
Expand Down Expand Up @@ -923,7 +930,9 @@ const geowarp = function geowarp({

if (should_skip(raw_values)) continue;
const pixel = process({ pixel: raw_values });
insert_sample({ row: r, column: c, pixel, raw: raw_values });
if (pixel !== null || insert_null_strategy === "insert") {
insert_sample({ row: r, column: c, pixel, raw: raw_values });
}
}
}
}
Expand Down

0 comments on commit 1b29584

Please sign in to comment.