question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling negative buffer with NaN coordinates

See original GitHub issue

Based on https://github.com/Turfjs/turf/pull/736#issuecomment-301937747, I wanted to add this morphological closing behavior to the test cases, however I noticed when entering a radius which is greater than the polygon, the geometry’s coordinates will result in NaN values.

Question: Is this expected output correct? Or should we return undefined or an empty FeatureCollection?

Example

https://jsfiddle.net/pvLx12n1/

const poly = turf.polygon([[[11, 0], [22, 4], [31, 0], [31, 11], [21, 15], [11, 11], [11, 0]]]);
turf.buffer(poly, -500, 'miles').geometry.coordinates;
//=[ [ NaN, NaN ] ]

Output Geometry

Seems like this output would be an invalid GeoJSON Polygon

{
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[null, null]]
  }
}

CC: @rafaelalmeida

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rafaelalmeidacommented, May 18, 2017

Agreed. If there’s an easy mechanism to return error details along with response, maybe it could be used if the cost to implement is low enough. Otherwise, a quick note in the docs would suffice, like:

“When using a negative radius, the resulting geometry may be invalid if it’s too small compared to the radius magnitude. If the input is a FeatureCollection, only valid members will be returned in the output FeatureCollection - i.e., the output collection may have fewer members than the input, or even be empty.”

While this does not say exactly what failed, should give devs a hint on where to look.

On Thu, May 18, 2017 at 2:37 PM, Denis notifications@github.com wrote:

Yes, if a feature collection of 2 polygons is the input and only 1 of them has valid geometry, then the FeatureCollection will only contain 1 polygon.

Returning a “bad” geometry would most likely cause things to break by having NaN in the coordinates.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Turfjs/turf/issues/745#issuecomment-302485783, or mute the thread https://github.com/notifications/unsubscribe-auth/AA23X61mfpX89C6pgOIVXkcGslw8pi2-ks5r7IHOgaJpZM4NdP9o .

0reactions
DenisCarrierecommented, May 18, 2017

Yes, if a feature collection of 2 polygons is the input and only 1 of them has valid geometry, then the FeatureCollection will only contain 1 polygon.

Returning a “bad” geometry would most likely cause things to break by having NaN in the coordinates.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shapely Documentation - Read the Docs
Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects. It is using.
Read more >
The Shapely User Manual — Shapely 2.0.0 documentation
Shapely is a Python package for set-theoretic analysis and manipulation of planar ... this manual will make a distinction between constructive ( buffer...
Read more >
Buffer (Analysis)—ArcGIS Pro | Documentation
ArcGIS geoprocessing tool that creates buffer polygons around input features to a specified distance.
Read more >
Metal Shading Language Specification - Apple Developer
A vertex shader generates positions in clip-space coordinates. ... Texture buffers handle type conversion more efficiently than other ...
Read more >
Spatial Data — Geographic Data Science with Python
In xarray , these indices are called coordinates, and they can be ... in surfaces not as a class of its own (e.g.,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found