coordEach indexing bug
See original GitHub issueI noticed this evening that when using coordEach
that it doesn’t really deal with holes properly.
So for example I pass in a poly with a hole like
[ [ [ 100, 0 ], [ 101, 0 ], [ 101, 1 ], [ 100, 1 ], [ 100, 0 ] ],
[ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ],[ 100.2, 0.8 ],[ 100.2, 0.2 ] ]
]
if I do something like
coordEach(poly, function (currentCoord, currentIndex, featureIndex, featureSubIndex) {
console.log(currentCoord)
console.log(currentIndex, featureIndex, featureSubIndex)
I get
[ 100, 0 ]
0 0 0
[ 101, 0 ]
1 0 0
[ 101, 1 ]
2 0 0
[ 100, 1 ]
3 0 0
[ 100.2, 0.2 ]
4 0 0
So the hole get’s the same featureIndex and featureSubIndex as the rest of the poly which means I can’t detect that the coord belongs to a hole.
Would be great to add some polys with holes to the test fixtures to those meta
modules.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
meta package - github.com/tomchavakis/turf-go/meta/coordEach ...
CoordEach iterate over coordinates in any Geojson object and apply the callbackFn geojson can be a FeatureCollection | Feature | Geometry callbackFn is...
Read more >Top 5 @turf/helpers Code Examples - Snyk
Learn more about how to use @turf/helpers, based on @turf/helpers code examples created from the most popular ways it is used in public...
Read more >@turf/meta | Yarn - Package Manager
coordIndex number The current index of the coordinate being processed. Starts at index 0, if an initialValue is provided, and at index 1...
Read more >Advanced geospatial analysis - Turf.js
Error - if it encounters an unknown geometry type ... The properties object will contain three values: index : closest point was found...
Read more >JavaScript @turf/meta coordEach Examples
coordEach extracted from open source projects. ... File: index.js Project: OlympicsORG/turf ... 'object') throw new Error('options must be an object'); ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
👍 Agreed, I’ve added a 3rd index (
geometryIndex
) which indicates the index when iterating over the geometry (used in Polygon & MultiPolygon geometries).There are 3 major index tiers which are broken down like so:
featureIndex
=>multiFeatureIndex
=>geometryIndex
Using those 3 indexes you should be able to find your way back to the exact geometry part of the feature.
@rowanwins Have a go at it and let me know if you are having any issues with the new update. (Close issue whenever you confirm it’s 👍 )
I know… Handling Polygons with holes is brutal! Don’t hesitate to test the other
@turf/meta
modules, we can do another big revamp at the next major release to make it easier to work with by returning Objects in the callbacks.