Skip to content

Commit

Permalink
Fix convex function ignoring given properties (Turfjs#2762)
Browse files Browse the repository at this point in the history
  • Loading branch information
kareemjeiroudi committed Dec 10, 2024
1 parent 42ad7b8 commit 51adb21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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) => {
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();
});

0 comments on commit 51adb21

Please sign in to comment.