Skip to content

Clarify geomEach behavior and add a test - #3112

Merged
mfedderly merged 1 commit into
masterfrom
mf/geomEach-behavior
Jul 27, 2026
Merged

Clarify geomEach behavior and add a test#3112
mfedderly merged 1 commit into
masterfrom
mf/geomEach-behavior

Conversation

@mfedderly

Copy link
Copy Markdown
Collaborator

geomEach actually has some strange behavior when operating on nested GeometryCollections. It will unwrap twice (root GeometryCollection with a nested GeometryCollection) or just once (Feature containing a GeometryCollection). It does not infinitely recurse.

The RFC states:

  To maximize interoperability, implementations SHOULD avoid nested
   GeometryCollections.  Furthermore, GeometryCollections composed of a
   single part or a number of parts of a single type SHOULD be avoided
   when that single part or a single object of multipart type
   (MultiPoint, MultiLineString, or MultiPolygon) could be used instead.

So I'm not sure if anyone is really expecting this to work in practice, but for now lets just add a warning to the docs and add a test demonstrating the behavior so we don't accidentally break things here.

I'd be open to changing the functionality in the future if someone feels like this should be improved. In general the methods in meta seem like they require a lot of focus to work on and make sure that performance isn't regressed. A lot of the rest of Turf depends on them to be as fast as possible. I'm not sure we've visited the benchmarks with modern JS engines though, and I'd like the typings to get more strict to help in other packages.

@mfedderly
mfedderly merged commit 73b2589 into master Jul 27, 2026
5 checks passed
@mfedderly
mfedderly deleted the mf/geomEach-behavior branch July 27, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant