Skip to content

Commit

Permalink
added include_null_class_rows
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Apr 4, 2022
1 parent faedece commit 8a70a87
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 89 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ const results = calculate({
// deletes zonal features that have no overlap with the classes
// examples include districts not covered by a hurricane
// or cities that can't feel an earthquake
remove_features_with_no_overlap: true
remove_features_with_no_overlap: true,

// default is true
// set to false to filter out table rows for
// parts of zones that don't intersect a class
include_null_class_rows: true
});
```
result is the following object:
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function calculate({
class_geometry_type,
include_zero_count = false,
include_zero_area = false,
include_null_class_rows = true,
class_properties_delimiter = ",",
preserve_features = true,
remove_features_with_no_overlap = false,
Expand Down Expand Up @@ -249,6 +250,10 @@ function calculate({
// convert class id from string to array
class_id = JSON.parse(class_id);

if (include_null_class_rows === false && class_id === null) {
continue;
}

const row = {};
zone_id.map((it, i) => {
const key = Array.isArray(zone_properties) ? zone_properties[i] : "index";
Expand Down
11 changes: 9 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,23 @@ test("percentage within range when using class property", ({ eq }) => {
});
});

test("delete zone features that don't overlap classes", ({ eq }) => {
test("ignore parts of zones that don't overlap classes", ({ eq }) => {
const result = calculate({
zones: louisiana_parishes,
zone_properties: ["ParishName"],
classes: cone_120km,
class_properties: ["wind_speed"],
preserve_features: false,
remove_features_with_no_overlap: true
remove_features_with_no_overlap: true,
include_null_class_rows: false
});
eq(louisiana_parishes.features.length > result.geojson.features.length, true);
eq(louisiana_parishes.features.length, 64);
eq(result.geojson.features.length, 22);
eq(result.table.columns, ["zone:ParishName", "class:wind_speed", "stat:area", "stat:percentage"]);
eq(result.table.rows.length, 22);
eq(
result.table.rows.every(row => row["stat:area"] > 0),
true
);
});
Loading

0 comments on commit 8a70a87

Please sign in to comment.