Skip to content
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 { type 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 transferred to result polygon", (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();
});