Skip to content

Apply equidistance @turf/buffer to polygons #660

Closed

Description

@flightsurvey

Please see attached screen shot of a buffer created around a polygon. It appears that the north and south extents are further away than they should be.
buffer

Activity

  1. DenisCarriere commented on Apr 11, 2017

    @DenisCarriere
    Contributor

    Please provide a GeoJSON of the input & output.

    Have you tried measuring the buffer distances using http://geojson.io?

    Also there might be some distance distortions the higher/lower you are in latitudes since the buffer distance units are calculated in Degrees and not in metric/imperial units.

    An example of two points up north (Resolute Bay).
    image

    Ref: #283 #88 #656

  2. flightsurvey commented on Apr 11, 2017

    @flightsurvey
    Author

    Thanks for getting back.

    I put the following into geojson.io:

    [http://bl.ocks.org/anonymous/raw/a8a2f66eb676b01a40676077d8ebd7fe/]

    and it appears that the problem is with the other way around:

    Zipped geoJSON: map.zip

    Code:

    var definedAreaCoordinates = {"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-0.16513824462890625,51.14605198694671],[-0.1667207479476929,51.14550680517377],[-0.16554594039916992,51.14412026449063],[-0.16442477703094482,51.144598154575476],[-0.16513824462890625,51.14605198694671]]]}};
    
    definedAreaBuffer = turf.buffer(definedAreaCoordinates, 0.05, 'kilometers');
    
  3. DenisCarriere commented on Apr 11, 2017

    @DenisCarriere
    Contributor

    Note: Instead of zipping, you could simply share your URL as a Gist:

    https://gist.github.com/f66c382ee9ee9d8e0894b9e61f2af3d1

  4. flightsurvey commented on Apr 11, 2017

    @flightsurvey
    Author

    Good tip (took me a while to absorb it).

  5. added this to the 5.0.0 milestone on Apr 16, 2017
  6. DenisCarriere commented on Apr 16, 2017

    @DenisCarriere
    Contributor

    @flightsurvey To extend my answer, the issue is because the radius param is being converted from degrees to distance (miles/kilometers).

    Solution:
    Looks like we would need to apply the @turf/buffer operations on coordinates using the Mercator projection (then converted back to degrees WGS84), this would create an equi-distance buffer around the geometry (left, right, top & bottom should all have the same buffer distance).

    Issue - Polygon in northern latitude

    • Red: Input Polygon
    • Blue: Buffer with 15 miles radius
    • Top & Bottom buffer distance (~15 miles)
    • Left & Right buffer distance (~4 miles)
      image
  7. changed the title [-]How accurate is buffer?[/-] [+]Apply equi-distance @turf/buffer to polygons[/+] on Apr 16, 2017
  8. flightsurvey commented on Apr 16, 2017

    @flightsurvey
    Author

    Thanks for taking time to look at it

  9. changed the title [-]Apply equi-distance @turf/buffer to polygons[/-] [+]Apply equidistance @turf/buffer to polygons[/+] on Apr 16, 2017
  10. w8r commented on May 2, 2017

    @w8r

    I took this challenge before here https://github.com/w8r/moscow-rings, maybe you'll find it useful.
    Basically, I extracted the equidistant projection calculation from d3, and adjusted it to have its center in the middle of the buffered shape. It doesn't completely remove the distortions, but at least makes sense in practical cases.

  11. DenisCarriere commented on May 2, 2017

    @DenisCarriere
    Contributor

    👍 Awesome stuff! The visual map looks are pretty darn good!

    Useful reference from moscow-rings:

    Any reason why you didn't use your polygon-offset library vs. jsts?

    I've briefly discussed this in other posts, however i'll go over the ideal buffer workflow:

    • Reproject GeoJSON from degrees to EPSG:3857 (Web Mercator) using BBox/Center of GeoJSON (can be done with d3-geo using projection.center)
    • Apply buffer operations using jsts or polygon-offset (helpers would need a conversation table for units > meters).
    • Unproject GeoJSON (EPGS:3857 to EPSG:4326 "WGS84")

    @w8r Sounds about right? Correct me if anything seems off.

    @mourner @morganherlocker : By no means we should support reprojections (only internally). This seems like this is the only accurate option for equi-distance buffers. As for performance, I believe the heavy lifting is the buffer operations and not the reprojection.

  12. w8r commented on May 2, 2017

    @w8r

    Oh, I forgot how shitty that code is)) Didn't use polygon offset, cause it was a very naive implementation before I stumbled upon martinez algorithm, and there was no proper settings to make the contour smooth, nor did it support holes in polygons.

    As for the algorithm outline - why to mercator? The most important point is that you have to do the geometrical calculations in the R2 space where they make sense, so abstract equidistant does the trick. This is what I do there, EPSG:3857 is only used to get the distances in meters and project back onto the leaflet map.

    Useful parts are actually here and here

    Your note about performance is right, offsetting is much heavier than reprojection

  13. DenisCarriere commented on May 2, 2017

    @DenisCarriere
    Contributor

    👍 Thanks @w8r for the feedback, I'll have a look at it further and i'll CC you whenever I do a PR on Turf.

  14. modified the milestones: 4.3.0, 5.0.0 on May 7, 2017
  15. DenisCarriere commented on May 7, 2017

    @DenisCarriere
    Contributor

    This is fixed in PR #718
    Thanks @w8r & @flightsurvey for the feedback

  16. YanCallier commented on Oct 2, 2023

    @YanCallier

    Hi, I experienced the same issue in the 6.5 version :
    image

    The circle has the same diameter used on :
    const test = buffer(poly, 50, { units: 'kilometers' });

    Yan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions