Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix convex function ignoring given properties #2765

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/turf-convex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function convex<P extends GeoJsonProperties = GeoJsonProperties>(

// Convex hull should have at least 3 different vertices in order to create a valid polygon
if (convexHull.length > 3) {
return polygon([convexHull]);
return polygon<P>([convexHull], options.properties);
}
return null;
}
Expand Down
15 changes: 15 additions & 0 deletions packages/turf-convex/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { writeJsonFileSync } from "write-json-file";
import { loadJsonFileSync } from "load-json-file";
import { featureCollection } from "@turf/helpers";
import { convex } from "./index.js";
import { FeatureCollection } from "geojson";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand All @@ -32,3 +33,17 @@ test("turf-convex -- empty", (t) => {
t.deepEqual(convex(featureCollection([])), null, "corner case: null hull");
t.end();
});

test("turf-convex -- properties are returned", (t) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make the test name more descriptive? Maybe "properties are transferred to result polygon" instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Thanks for the feedback. I'll get back to this as soon as back from holidays.

const geoJson = loadJsonFileSync<FeatureCollection>(
"./test/in/elevation2.geojson"
);
const expectedProperties = { cadastralData: [1220, 1290, 1440, 1943] };
const actualPolygon = convex(geoJson, { properties: expectedProperties });
t.deepEqual(
actualPolygon?.properties,
expectedProperties,
"properties do not match"
);
t.end();
});