turf
turf copied to clipboard
@turf/[email protected] - Unable to clone FeatureCollection containing features with null geometry
When trying to clone a GeoJSON FeatureCollection that contains null geometries, @turf/clone (v. 6.5.0) throws "Cannot read properties of null (reading 'type')".
The error originates from the cloneGeometry function https://github.com/Turfjs/turf/blob/2dd2ef88c44d847989fa0b82089f3f81fe433b83/packages/turf-clone/index.ts#L61
which could be changed to something like the following
if (geojson.geometry == null) {
cloned.geometry = null;
} else {
cloned.geometry = cloneGeometry(geojson.geometry);
}
in order to resolve the bug. I can create a PR if desired!
Here's an Observable notebook reproducing the behaviour: https://observablehq.com/@chrispahm/turf-clone-unable-to-clone-featurecollection-containing-f
Thanks for the detailed report - I think because null geometries are valid in the GeoJSON spec this is a bug. Feel free to raise a PR or perhaps one of us can look into it if we get a moment.