pointToPolygonDistance failing if polygon contains redundant (consecutive duplicate) points
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 10.5k
- Forks
- 1k
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 4
Description
Please provide the following when reporting an issue:
- Description of the problem, and how it differs from what you expected.
- Version of Turf you are using, and of any other relevant software.
- GeoJSON data as a gist file or geojson.io (filename extension must be
.geojson). Simple reproducible examples are preferrable. - Snippet of source code for complex examples using jsfiddle.
- Confirmation this issue hasn't already been reported, or is resolved and just hasn't been released yet.
Problem
Version: 7.2.0
pointToPolygonDistance
When using the method pointToPolygonDistance I get an error that says coordinates must contain numbers. It definitely has something to do with the redundant points at the end of the polygon. (Look at the last 2 entries of the polygon in the GeoJSON section below, they are equal). If I remove one of them, the method works.
When debugging, I see that it is failing because coordinates seems to be NaN:
Code:
// point & polygon can be used from GeoJSON below
const distance = turf.pointToPolygonDistance(point, polygon, {
units: "meters",
});
Stacktrace:
at point (../node_modules/@turf/helpers/index.ts:269:11)
at ../node_modules/@turf/nearest-point-on-line/index.ts:113:25
at ../node_modules/@turf/meta/index.js:748:11
at geomEach (../node_modules/@turf/meta/index.js:597:13)
at flattenEach (../node_modules/@turf/meta/index.js:739:3)
at nearestPointOnLine (../node_modules/@turf/nearest-point-on-line/index.ts:70:3)
at distanceToSegment (../node_modules/@turf/point-to-line-distance/index.ts:113:3)
at ../node_modules/@turf/point-to-line-distance/index.ts:78:15
at ../node_modules/@turf/meta/index.js:941:13
at coordEach (../node_modules/@turf/meta/index.js:119:15)
at ../node_modules/@turf/meta/index.js:913:7
at ../node_modules/@turf/meta/index.js:748:11
at geomEach (../node_modules/@turf/meta/index.js:597:13)
at flattenEach (../node_modules/@turf/meta/index.js:739:3)
at segmentEach (../node_modules/@turf/meta/index.js:898:3)
at pointToLineDistance (../node_modules/@turf/point-to-line-distance/index.ts:73:3)
at ../node_modules/@turf/point-to-polygon-distance/index.ts:80:7
at ../node_modules/@turf/meta/index.js:748:11
at geomEach (../node_modules/@turf/meta/index.js:597:13)
at flattenEach (../node_modules/@turf/meta/index.js:739:3)
at Object.pointToPolygonDistance (../node_modules/@turf/point-to-polygon-distance/index.ts:77:3)
at pointToPolygonDistance (turf/turf.service.ts:128:35)
GeoJson:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"coordinates": [
[
[
9.717640356727232,
48.2907894548215
],
[
9.718316273398985,
48.289925696874604
],
[
9.719571547217955,
48.2903397314326
],
[
9.718884901710142,
48.29126058936186
],
[
9.717640356727232,
48.2907894548215
],
[
9.717640356727232,
48.2907894548215
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"coordinates": [
9.73541368510476,
48.28771763952804
],
"type": "Point"
}
}
]
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the GeoJSON and call shown in the issue, then trace the stack from point-to-polygon-distance/index.ts through point-to-line-distance/index.ts and nearest-point-on-line/index.ts. Compare behavior with and without the consecutive duplicate polygon point; done means pointToPolygonDistance handles the provided geometry without producing NaN or the coordinates error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100