Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer distance #1547

Closed
flightsurvey opened this issue Dec 8, 2018 · 4 comments
Closed

Buffer distance #1547

flightsurvey opened this issue Dec 8, 2018 · 4 comments

Comments

@flightsurvey
Copy link

flightsurvey commented Dec 8, 2018

I have created a buffer around a geojson object in Leaflet in the following way:

var geoJSON ={
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -4.491606,
              54.143007
            ],
            [
              -4.499331,
              54.139085
            ],
            [
              -4.497614,
              54.13828
            ],
            [
              -4.495983,
              54.139135
            ],
            [
              -4.495296,
              54.138783
            ],
            [
              -4.490061,
              54.141146
            ],
            [
              -4.491606,
              54.143007
            ]
          ]
        ]
      }
    }
  ]
};

var area = L.geoJSON(JSON.parse(geoJSON)), {
	color: 'green',
	weight: 2,
	onEachFeature: function (feature, layer) {
		layer.on("click", function (e) {
			map.fitBounds(layer.getBounds());
		});
	}
}).addTo(map);

var distance = 50;

var buffer = L.geoJSON(turf.buffer(JSON.parse(area), distance / 1000, {units:'kilometers'}), {
	color: 'orange',
	weight: 2,
	onEachFeature: function (feature, layer) {
		layer.on("click", function (e) {
			map.fitBounds(layer.getBounds());
		});
	}
}).addTo(map);

I then measured a perpendicular line between the area and the buffer - albeit freehand but it seems to be pretty true - and it appears to be around 44m.

To view the output paste the following into geojson.io:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -4.491008208047599,
              54.14317729554968
            ],
            [
              -4.4910793289379,
              54.14324457294276
            ],
            [
              -4.491172202002483,
              54.14330203846458
            ],
            [
              -4.491282991531243,
              54.14334731869702
            ],
            [
              -4.4914071217792,
              54.14337854349127
            ],
            [
              -4.4915394659636,
              54.14339442321583
            ],
            [
              -4.491674558029246,
              54.14339430202498
            ],
            [
              -4.4918068184314475,
              54.14337818494692
            ],
            [
              -4.491930784606396,
              54.14334673767213
            ],
            [
              -4.492041336604907,
              54.143301259052194
            ],
            [
              -4.499766330943429,
              54.139379210582064
            ],
            [
              -4.499855281221839,
              54.139324303903805
            ],
            [
              -4.499924414426821,
              54.13926035213715
            ],
            [
              -4.4999711175876955,
              54.139189772565246
            ],
            [
              -4.49999362558707,
              54.139115232965906
            ],
            [
              -4.499991087854817,
              54.139039550771095
            ],
            [
              -4.499963600490543,
              54.13896558657387
            ],
            [
              -4.499912202604401,
              54.138896136007745
            ],
            [
              -4.4998388370186895,
              54.13883382408492
            ],
            [
              -4.4997462768187315,
              54.13878100598601
            ],
            [
              -4.498029287924673,
              54.137976015172434
            ],
            [
              -4.497917507036294,
              54.137933615722105
            ],
            [
              -4.497793541787066,
              54.13790512215984
            ],
            [
              -4.497662368762999,
              54.137891678365825
            ],
            [
              -4.497529253887912,
              54.13789382405563
            ],
            [
              -4.497399541047021,
              54.13791147311333
            ],
            [
              -4.497278437580579,
              54.137943917044495
            ],
            [
              -4.497170805253291,
              54.1379898534117
            ],
            [
              -4.495977972533194,
              54.13861515582364
            ],
            [
              -4.495733558522022,
              54.138489923952314
            ],
            [
              -4.495627491604399,
              54.1384455270722
            ],
            [
              -4.495508672456908,
              54.138414112723275
            ],
            [
              -4.495381671944031,
              54.138396889388886
            ],
            [
              -4.495251375637127,
              54.138394519645125
            ],
            [
              -4.49512279589262,
              54.13840709467304
            ],
            [
              -4.495000879053287,
              54.138434130748365
            ],
            [
              -4.494890315185861,
              54.138474587844314
            ],
            [
              -4.4896553212314725,
              54.140837556173345
            ],
            [
              -4.4895608621765035,
              54.140889530204326
            ],
            [
              -4.489485414002924,
              54.14095125325352
            ],
            [
              -4.489431844752228,
              54.14102037914921
            ],
            [
              -4.489402190854689,
              54.1410942803016
            ],
            [
              -4.489397579698279,
              54.14117014757768
            ],
            [
              -4.489418186747154,
              54.14124509708067
            ],
            [
              -4.489463228844416,
              54.14131627977578
            ],
            [
              -4.491008208047599,
              54.14317729554968
            ]
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -4.491606,
              54.143007
            ],
            [
              -4.499331,
              54.139085
            ],
            [
              -4.497614,
              54.13828
            ],
            [
              -4.495983,
              54.139135
            ],
            [
              -4.495296,
              54.138783
            ],
            [
              -4.490061,
              54.141146
            ],
            [
              -4.491606,
              54.143007
            ]
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            -4.4956934452056885,
            54.14144647026728
          ],
          [
            -4.49527233839035,
            54.14114479855208
          ]
        ]
      }
    }
  ]
}

Would anyone like to comment on this? I am quite happy to accept that my implementation is wrong but at the moment it doesn't seem to be to me.

@flightsurvey flightsurvey mentioned this issue Jan 14, 2019
2 tasks
@rowanwins
Copy link
Member

Hi @flightsurvey

Sorry for the slow reply, in Australia this is our summer holiday period and so my contributions and support have slowed.

So are you wanting a buffer of 50m and you're saying that the result if 44m?

There are some known issues in the buffer module at the moment. #1470 outlines a breaking change that was made a while ago so you might be best of revert back to the version specified version in that issue.

Hope that helps,
Rowan

@flightsurvey
Copy link
Author

Hi Rowan,

Thank you very much for the insight. I'll have a look at your suggestion and, in the meantime, enjoy the sunshine.

Cheers,
Paddy

@chrispahm
Copy link
Contributor

Hi @flightsurvey @rowanwins @mfedderly ,

trying to help to clean up some older issues here: This bug has been resolved with Turf v6.2.0 (and later) as highlighted in the following notebook
https://observablehq.com/@chrispahm/turf-issue-1547

So I guess this issue can be closed?

@JamesLMilner
Copy link
Collaborator

Again thanks @chrispahm - as you have shown the fix we can close this out. Any related problems can be raised in a new issue.

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

No branches or pull requests

6 participants