turfjs / turf-buffer Goto Github PK
View Code? Open in Web Editor NEWBuffers a point, linestring, or polygon Feature/FeatureCollection to a given radius. Units supported are miles, kilometers, and degrees.
License: MIT License
Buffers a point, linestring, or polygon Feature/FeatureCollection to a given radius. Units supported are miles, kilometers, and degrees.
License: MIT License
How do I get the coordinates of the selected elements?
now,I want to select a feature,and give it radius,so i asked everyone how i obtain the feature coordinates when my pointer select a feature,sorry ,it is my first time to ask question ,and i am a chinese
I tried using turf-buffer to get a buffer around a FeatureCollection of about 1800 points:
var buffered = turf.buffer(
points,
0.25,
"miles"
);
The buffer result only seems to have incorporated a fraction of the points.
If I manually buffer EACH point feature individually, and then merge all the resulting polygons, it does incorporate them all:
var individuallyBuffered = turf.merge({
"type": "FeatureCollection",
"features": points.features.map(function(feature){
return turf.buffer(feature,0.25,"miles").features[0];
})
});
Pink is the results from one-by-one buffering and green is the result from buffering the whole collection:
Something I'm missing about how this is supposed to work?
This is the original GeoJSON of points:
The following code shows a bug, where the original feature collection contains a multipolygon with two shapes, but the resulting buffered output only has one of those polygons
var pt = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[-122.28068729011625, 37.533846],
[-122.321643, 37.533846],
[-122.34964211167777, 37.533846],
[-122.3221531, 37.5477641],
[-122.3004556, 37.55875],
[-122.28068729011625, 37.533846]
]
],
[
[
[-122.39372234835123, 37.533846],
[-122.519032, 37.533846],
[-122.519464, 37.534918],
[-122.519755, 37.545632],
[-122.39372234835123, 37.533846]
]
]
]
}
}]
};
var unit = 'meters';
var buffered = turf.buffer(pt, 20, unit);
//=result
I have one 3d model Object
[
// Triangle A
-90.6714, 35.9641, 322.543, -94.6717, 38.9642, 325.51, -97.6717, 35.9639, 324.724,
// Triangle B
-94.6717, 30.9639, 324.717, -90.6717, 32.9639, 324.724, -94.6717, 34.9639, 324.719
]
I explain it and vertical points are below:
-90.6714, 35.9641, 322.543,
-94.6717, 38.9642, 325.51
-97.6717, 35.9639, 324.724
-94.6717, 30.9639, 324.717
-90.6717, 32.9639, 324.724
-94.6717, 34.9639, 324.719
Please tell me Great turf can handle with it ?(3d model buffer)
I am trying to check features drawn using OL 3 for intersections. Features are all lineStrings.
I use the following code where i get the Unknown GeoJSON type error:
lineStringdraw.on('drawend', function(e2) {
var featureEnd = e2.feature;
checkIntersection(featureEnd);
});
function checkIntersection(currentFeature){
var features = vectorLayer.getSource().getFeatures();
var geoJSON = new ol.format.GeoJSON();
geoJSON = geoJSON.writeFeature(currentFeature);
for (i=0; (features.length)>i;i++){
var feature = features[i];
geoJSON_i = geoJSON.writeFeature(feature);
var intersectionStatus = turf.intersect(geoJSON,geoJSON_i);
$('#infoList').append(intersectionStatus);
}
}
here is piece of the OL3 GeoJSON:
{"type":"Feature","geometry":{"type":"LineString","coordinates":[[-8236104.129670544,4977029.890789877],[-8236634.411554272,4974407.145256842]]},"properties":null}
comparing to the turf standard, they pretty much look the same except the turf uses single quotations instead. Shouldn't they be compatible as long as both follow the same standard as GeoJSON? Or am I missing something here?
Came across this issue when using dropchop and after discussing over there, discovered it was an underlying Turf issue.
In short: running a buffer on this geojson of point data, two of the cities don't receive a buffer when the distance is more than 82 miles.
You can see more details on the dropchop issue.
Hi,
I created a buffered polygon for a LineString segment using:
// featureGeoJson below is a LineString feature drawn on the map
const bufferedPolygon = turf.buffer(featureGeoJson, bufferVal, 'kilometers')
Is there any way I can process back LineString from the now available bufferedPolygon and bufferVal?
Note: featureGeoJson is not saved anywhere in our app now.
Hello,
I saw that somebody implemented a variable width buffer for QGIS and I thought it would be a cool addition to add to turf-buffer
and turf-line-offset
https://twitter.com/naturalgis/status/990976423539208193
Thanks!
Looks like it does not accept Number.MIN_VALUE as ratio...
My tests gives me 10^-9 as smallest value
I computing a 25km-75km buffer in eastern Europe. On a 75km buffer turf.distance calculates a point as 60km away but the buffer of 75km does not extend to include the point. I am supplying unit='kilometers' to both. My database which uses sloppyarc seems to agree more with turf.distance. Do these two methods use different distance calculations? It's not documented what buffer uses as an algorithm only that turf.distance uses haversine. I am more concerned about consistency (For UX presentation) than complete accuracy.
running turf.buffer(fc, 0, 'miles')
on this featurecollection
gives me this:
Removing the polygon to the far northeast seems to solve this problem; it's also the only poly with a hole, so that may have something to do with it.
cc/ @morganherlocker
var buffered = turf.buffer({
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-1.0052490234375,
38.248965760244644
],
[
-1.68365478515625,
38.06539235133249
],
[
-1.71112060546875,
37.57723579111111
],
[
-0.626220703125,
37.45741810262938
],
[
-0.70587158203125,
37.98966904403617
],
[
-1.0052490234375,
38.248965760244644
]
],
[
[
-1.10687255859375,
38.052416771864834
],
[
-1.329345703125,
38.037275688165614
],
[
-1.37054443359375,
37.79676317682161
],
[
-1.1700439453125,
37.785910776551354
],
[
-1.10687255859375,
38.052416771864834
]
],
[
[
-0.9365844726562499,
37.92686760148135
],
[
-1.03271484375,
37.83364941345968
],
[
-0.94482421875,
37.80327385185868
],
[
-0.9365844726562499,
37.92686760148135
]
]
]
}
},
2, 'miles');
Needs to be updated, since it's not inline with the code comments.
When trying to buffer on a FeatureCollection
of MultiPolygons
(this file), the current Buffer code (turf-buffer
v1.0.1
used by turf
v2.0.2
) prepares the data by running it through combine
. If the FeatureCollection
's first feature's geometry type (fc.features[0].geometry.type
) is "MultiPolygon"
, no geometry
property is appended to the FeatureCollection
during the combine
operation. When the bufferOp
later passes a stringified version of feature.geometry
(which is undefined
) to an instance of jsts.io.GeoJSONReader
, the error Uncaught TypeError: Cannot read property 'type' of undefined
is thrown. Based on my reading of the GeoJSON Feature Collection Objects spec, it is not invalid for a FeatureCollection
object to not have a geometry
property on the root of the object.
This bug appears to have been fixed with this committed change, so this issue can likely be tagged wont fix
. I'm more interested in created this issue so that:
turf
v2.0.2
and any other turf
versions relying on turf-buffer
v.1.0.1
.turf-combine
)turf-buffer
>v1.0.1
(the repo appears to be at v1.0.4
at this moment) will be rolled into a main version of turf
.First I found out the hard way that the default version of turf-buffer inside turf is an old one, which is buggy. After locally installing the latest version (1.1.0) of turf-buffer I'm getting much better results. But I spotted a bug around properties.
Line 75 of index.js has:
properties: {}
which should be:
properties: feature.properties
I'm using the CDN version of turf in my browser, and creating buffers for User provided points, and saving them in the db; I realized that the geojson created was not conforming to the GeoJSON standard, (section 3.16) specifically, which states that
A linear ring MUST follow the right-hand rule with respect to the
area it bounds, i.e., exterior rings are counterclockwise, and
holes are clockwise.
This can be replicated by running the following code:
var pt=turf.point([73,20]);
var buff=turf.buffer(pt, 2000, 'meters');
console.log(JSON.stringify(buff));
And then testing the output with http://geojsonlint.com/
Working with turf.buffer I notice that the buffering figure of a Polygon was not correct.
In particular, the radius (expressed in meter) wasn't respected during the dilatation.
I report below a test done for buffer a point.
(I know that there is turf.circle but i want to demonstrate the error for the radius).
point used -->"coordinates": [ 7.237860560417174, 45.12233909279541];
Code:
p = turf.buffer(point, 50, {units:'meters'});
console.log(turf.area(p));
Console:
3885.60
Check resultant area:
3885.60=* R² --> R=35.17m
So,the radius doesn't match the radius of the function.
(It was acceptable if the area was higher for the terrestrial curvature)
With other test, i find out that using radius=71.1 with 'meters', the area after buffer is 7857.98mq and R=50.01m with the formula used before.
Using [email protected]
thanks
Suggest you allow the non US specific spelling as an input unit 'metre' as well as 'meter'.
dissolve the results from a multi-geometry buffer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.