Questions tagged [turf]

Turf.js is an open-source JavaScript library for spatial analysis.

Filter by
Sorted by
Tagged with
1 vote
1 answer
18 views

Leaflet create GeoJSON polygon layer from Turf buffer on GeoJSON point layer while keeping the attributes

I have Leaflet GeoJSON point layer that I buffer with turf and add to the map. The code works well but I want to add the point attributes to the polygon layer but I am unsure of how to do to that. ...
user avatar
  • 4,065
2 votes
1 answer
25 views

How to insert a coordinate into an LineString at a specific index

I have a LineString: [ [ -122.263923, 37.87459 ], [ -122.263942, 37.874587 ], [ -122.264151, 37.874534 ], [ -122.264231, 37.874511 ], [ -122.264285, 37.874495 ],...
user avatar
  • 23
2 votes
0 answers
64 views

GIS operations to create a union from a polyline plus a polygon [closed]

I've got access to JS geospatial library (turf.js), which has a full suite of GIS operations available. But, I'm stuck on the terms for what I'm trying to do. In laymans terms, I wish to extend the ...
user avatar
  • 195
2 votes
1 answer
111 views

Turf.js lineIntersect() not giving intersection of lineString and feature?

I'm displaying some polygons in Leaflet, and using Turf JS to do some calculating. After drawing a line between the centroids of two neighboring polygons, I want to find the intersection of the line ...
user avatar
  • 155
1 vote
1 answer
93 views

Leaflet turf.buffer: projection problem

I'm trying to make a buffer with Leafler, Turf, work out of the drawnItems of Leaflet Draw; but the result isn't right. It's too high but not large enough. Could you help me fix it? I'm using this ...
user avatar
1 vote
1 answer
67 views

Getting attributes of polygons that line overlaps using Leaflet and Turf

I have a Leaflet Polyline: var polyline = L.Polyline(polylineData).addTo(map); and a Leaflet GeoJSON of Polygons: var countries = L.geoJson(countries, {style:{color:'darkgrey', opacity:1,fillColor:'...
user avatar
  • 352
3 votes
1 answer
185 views

How to create a global hex grid

I asked this question on SO, but now I realize that perhaps this is a more suitable forum. I need to generate a hex grid for the entire world and store it in my db. Background: I have more than 300K ...
user avatar
  • 223
1 vote
1 answer
142 views

Turf.js dissolve features not adding to Leaflet map

Trying to dissolve features with boundaries that touch with Turf.js. They all have a common attribute that is specific in the Turf option example. Console loge console.log(regionsDissolved) results in ...
user avatar
1 vote
1 answer
85 views

Bind tooltip to a marker as a result of turf.js distance method in Leaflet

I'm trying to simply put the results of the distance variable in the tooltip but keep getting undefined. I don't understand what's happening. function findDistanceToCentroid(countyPolygon, ...
user avatar
2 votes
1 answer
199 views

Buffering GeoJSON with custom CRS in Leaflet

We are using a custom CRS for our map in order to use the British National Grid (EPSG:27700), however we have realised now that turf.buffer will not work with it, and appears to only work with Lat/...
user avatar
  • 143
0 votes
1 answer
120 views

GeoServer find all features within a certain radius [closed]

I use a external GeoServer that contains routes (LineString). I'm creating a Node JS backend in order to find and manipulate those routes. In order to find the routes I thought to first send a WFS ...
user avatar
  • 225
0 votes
1 answer
175 views

Turf.js length gives incorrect result

I'm trying to calculate the distance between 2 points given by GPS coordinates using the turf.js library. My code looks like this: const s1 = { lat: 48.60538779779193, lng: 18.887075288025212 }...
user avatar
  • 103
0 votes
0 answers
223 views

Why do I get a circle when I try to buffer a squared polygon with turf.js?

I have created the following node.js code with turf.js: const turf = require('@turf/turf') let polygon = [ [ [ -46.70527960466082, -23.515693805007327 ], [ -46.70525061354379, -23....
user avatar
  • 1,021
0 votes
1 answer
170 views

Leaflet Turf.buffer projection

I successfully created a buffer on Leaflet with Turf.JS . I had to change the map CRS to WGS84 (epsg:4326) to make it work. But the problem is that I need to go back to the default CRS of Leaflet ...
user avatar
0 votes
1 answer
186 views

Custom sized buffer , Turf.js and Leaflet Draw

I'm looking forward to buffering an object drawed with Leaflet Draw , and with a custom width in kilometers in a div. First Name: <input type="text" id="myText" value="...
user avatar
-1 votes
1 answer
92 views

Difference between interpolated map using IDW in ArcGIS and turfjs

I did the interpolation from the same map using arcgis and the turf.js library, using the same parameters and points. Could anyone say why the difference? ArcGIS params ArcGIS Map Turf.js params ...
user avatar
1 vote
0 answers
177 views

How to convert a multipolygon to multiple single polygons

I have a polygon clipping function in my OpenLayers app which may return me a multipolygon. Unfortunately, my app does not support multipolygons by design. So I need to convert a multipolygon to ...
user avatar
  • 391
0 votes
1 answer
186 views

Splitting / Highlighting area in filled in turf polygon in leaflet.js based on input 1-100%

In my previous questions, how to split a polygon into rectangles of a specific length, this is the code i arrived at in the end with the help of a fellow programmer. Splitting polygon with turf....
user avatar
2 votes
1 answer
598 views

Splitting polygon with turf.rectangleGrid in vue.js Leaflet map

The turf.rectangleGrid function from turf.js (https://www.npmjs.com/package/@turf/rectangle-grid) makes rectangles inside a bbox, but I want them in a polygon. The options take in a mask: Polygon not ...
user avatar
4 votes
2 answers
424 views

Closest point on 5km line

Given a point and a line, I am trying to determine the point on the line that is closest to the given point. The given point is always at least fairly close to the line (3-4 meters max) Originally I ...
user avatar
  • 275
3 votes
0 answers
194 views

Smart way of finding the polygon intersection of a huge GeoJSON file with a small GeoJSON file without looping through all polygons

I have a huge GeoJSON file (over 300MB) which has multiple different polygons. Also, I have a very small GeoJSON file with only one polygon that doesn't have more than ten points. Using the ...
user avatar
  • 1,021
1 vote
0 answers
26 views

Intersection using turf js [duplicate]

I am giving this for intersection of a polyline using Leaflet draw plugin with polygons feature class. Here is my code function intersectPolyByPolyFC(poly,fcPoly){ var fgp=[];//variable for ...
user avatar
1 vote
1 answer
114 views

Plotting polygon with hole as two separate polygons using Leaflet

I've a polygon with a hole which I created using turf.difference method. Now, I need to plot that GeoJSON on another screen and make both the inner polygon as well as outer polygon editable. Since I'm ...
user avatar
  • 21
2 votes
0 answers
444 views

Polygon intersection using turf js

I have given this code for intersection: function intersectPolyByPolyFC(poly,fcPoly){ var fgp=[];//variable for feature group var bbPoly=turf.bboxPolygon(turf.bbox(poly));//polygon ...
user avatar
1 vote
0 answers
30 views

Spheroid distance to sphere distance

I have linestring that is calculated on a spheroid. Shpere distance of where the point should be on the linestring Distance spheroid / sphare. On one lib, its all calculated in spheroid (Normal map)....
user avatar
  • 111
0 votes
0 answers
59 views

Returning polygon attributes intersecting a buffer

I am trying to return attributes of polygons (from the SAC feature) that intersect the buffer created around the route, but I keep getting: Uncaught Error: geojson must be a valid Feature or Geometry ...
user avatar
  • 148
1 vote
0 answers
118 views

Find nearest boundary of inner feature (Turf.js)

Imagine a GeoJSON FeatureCollection that contains a boundary and a feature. The feature should be thought of as a Building and the boundary as a plot of land. When rendered this shows the follow https:...
user avatar
  • 11
1 vote
1 answer
1k views

Add polygon (buffered line) created by turf.js to map in Leaflet?

I am trying to create a buffered line layer by creating GeoJSON line string from routing line and buffering it with turf.js and then show it on the map. Here is my code: route.on('routeselected', ...
user avatar
1 vote
1 answer
440 views

Calculate Rhumb-bearing applicable for showing directly pointing arrow in EPSG:3067?

In short: A pointer from one point towards another, angle calculated with any Bearing tool / formula in hand, did not show correctly, but some degrees wrong. Calculate made in lat / lon values and ...
user avatar
  • 137
0 votes
1 answer
66 views

How to contract geojson polygon

I'd like to convert the big red area to a smaller one (blue) by shifting their borders parallelly by a certain distance to inner direction. This is not equivalent to scale as the result shape will ...
user avatar
2 votes
0 answers
110 views

How to get a segment between two points

I have a map made of two layers, the first is a list of trails (path) and the second is a point based layer (different intersection between the trails). I am looking for a way to select a segment ...
user avatar
2 votes
1 answer
329 views

How to intersect more than 2 polygons using Turf.js?

We use Mapbox GL JS 1.12.0 in our Vue.js project. I need to create intersection objects if I have 2 or more polygons. But, I'm able to do it with 2 polygons only. The code looks as following: import * ...
user avatar
  • 219
1 vote
1 answer
261 views

Combine multiple points to polygons by property

I'm working on a website with a Cesium map, and I'm using turf.js for geo calculations. I need to find a way to merge a large set of points on the map (with a fixed distance between them) to polygons, ...
user avatar
  • 29
1 vote
1 answer
365 views

Create a rectangle with specific height from two points

I need to be able to create a rectangle with height x from two points. This is probably not clear enough so I tried to draw it: The two points that I have are the centroids of those circles, and what ...
user avatar
  • 13
1 vote
0 answers
172 views

Determine if two geometries are similar in shape and location

Suppose I have two geometries that have almost identical location and shape. I say almost on purpose here, since one or the other might have an extra node, or the order of coordinates in GeoJSON might ...
user avatar
  • 287
0 votes
0 answers
111 views

@turf/boolean-contains reports false, even though one geometry is fully contained in another

I have the following FeatureCollection: { "type": "FeatureCollection", "features": [ { "id": 47306, "type": "Feature", ...
user avatar
  • 287
1 vote
1 answer
164 views

Finding node on polyline immediately after given point using Turf

I have 2 polylines, A and B. My objective is to Find closest point on B from a given node on A Find tangent on that point So I use function nearestPointOnLine to find point on B closest to a node on ...
user avatar
  • 153
3 votes
1 answer
198 views

Python shapely unary_union in JavaScript

I have seen turf.js has union() but this isn't equal to the unary_union. Or does anyone know what the unary_union actually does? Maybe I can try to recreate it, I have seen the source code in python ...
user avatar
  • 151
1 vote
1 answer
772 views

OpenLayers drawing curves

I'm trying to draw a Bezier curve in OpenLayers (geometryFunction2) but there is something wrong with my approach I don't get. The first line seems fine but I can't place the next one. It work's fine ...
user avatar
  • 391
2 votes
1 answer
408 views

TurfJS dissolve not working as expected

Why are these two overlapping polygons not dissolving? I would expect the smaller polygon to dissolve into the larger but instead two individual features remain. See fiddle for code example. http://...
user avatar
  • 687
0 votes
1 answer
590 views

Detecting line intersections between MultiPolygon and LineString in Turf.js

I am trying to write a section of JavaScript code that allows a user to analyse a route they have plotted on a map. After the user has finished plotting their route, I want to determine if the route ...
user avatar
1 vote
1 answer
778 views

Leaflet GeoJSON Polygon Label Remaining in Frame when Zooming

I have a polygon layer being loaded into Leaflet in GeoJson format. When using the code below I'm able to get labels for each feature to appear at the center but they remain fixed there. I'd like for ...
user avatar
3 votes
1 answer
2k views

Turf intersect doesn't always work with polygons

I have a GeoJSON of two obvious colliding polygons but turf.intersect doesn't seem to detect it. Here the GeoJSON: { "type": "FeatureCollection", "name": "invalid_import", "features": [ ...
user avatar
  • 31
1 vote
0 answers
62 views

Method to determine of coordinates in GeoJSON feature are Lat/Lng or UTM?

Is there a @turf or any other helper method to quickly determine if coordinates in GeoJSON feature are Lat/Lng or UTM?
user avatar
  • 287
2 votes
1 answer
390 views

How to perform spatial computation in a Mercator projection in turf?

TL;DR: Spatial computation with turfjs does not work well in a EPSG:3857 map. In a OpenLayers map, I use turf for transforming a line into a polygon by computing the offset line (aka side-buffer for ...
user avatar
  • 1,185
3 votes
1 answer
1k views

Turf.js buffer distance not accurate

I'm facing a strange behavior using buffers in Turf.js. When trying to do a 50m buffer around a point, the result is actually closer to 35m. On the screenshot below, the smaller circle is a turf....
user avatar
  • 580
2 votes
0 answers
412 views

Turf difference function and coincident polygon boundaries [closed]

I've been wrestling with this issue for a few days. The tool I'm creating takes one polygon and essentially minuses/subtracts another from it. A perfect use of the difference command in Turf. ...
user avatar
  • 29
1 vote
0 answers
361 views

Trying to find percentage of overlap using turf intersect returns 'found non-noded intersection between LINESTRING'

This worked just the other day and now it's throwing an error for every call. The original code (before adding the try/catch) is this: var cbgShape = turf.polygon(shapeData.geometry.coordinates....
user avatar
1 vote
1 answer
3k views

Splitting a polygon by multiple linestrings leaflet and turf.js

I am trying to implement an utility for land subdivision using leaflet and turf. I am not sure if these tools are the right ones for the task. I've got it right for most of the scenarios but sometimes ...
user avatar
2 votes
1 answer
1k views

Do Leaflet and turfjs have different projections?

I am trying to use turfjs with leaflet for splitting a polygon by a number of linestrings(using my own algorithm that uses turf.lineIntersect()). It works most of the time ok. but sometimes produces ...
user avatar