Questions tagged [turfjs]

Turf is a collection of independent Javascript modules providing common geospatial capabilites, against geometries encoded in GeoJSON format. It can be run in a Nodejs environment or included in a minified form in a script tag. It draws heavily on the JSTS (Javascript Topology Suite) library under the hood.

289 questions
23
votes
3 answers

mapbox-gl-js: Adjust visible area & bearing to a given line, for a given pitch

I'm trying to optimize a Mapbox view for long-distance hiking trails, like the Appalachian Trail or the Pacific Crest Trail. Here's an example, which I've oriented by hand, showing the Senda Pirenáica in Spain: The area of interest, the viewport,…
Herb Caudill
  • 50,043
  • 39
  • 124
  • 173
11
votes
0 answers

Uncaught Error: coordinates must only contain numbers(Turf and Mapbox)

It produces an error when i use turf on my mapbox specifically this line: var nearestBuilding = turf.nearest(currentLocation, geoJson);. I use mapbox-gl and the turf to get the nearest building. It works when i input the data manually without…
Merida
  • 368
  • 1
  • 3
  • 13
10
votes
1 answer

Difference between centroid and centerOfMass in turf

I need to find the geospatial coordinates of point which is the mean of the distances between all the Features in my GeoJSON dataset. In turf.js both centroid and centerOfMass are presented. The explanation for centerOfMass is that it "takes any…
Yarycka
  • 165
  • 1
  • 10
9
votes
1 answer

How to fix geojson to satisfy the needs of a mongodb 2dsphere index

I have ~400K documents in a mongo collection, all with geometry of type:Polygon. It is not possible to add a 2dsphere index to the data as it currently stands because the geometry apparently has self-intersections. In the past we had a hacky…
dan-man
  • 2,949
  • 2
  • 25
  • 44
8
votes
1 answer

How to reliably generate hexagonal grid over a world map

Goal I'm attempting to build an application whereby the whole world map is split into a large number of hexagons. These hexagons, once generated would always cover the same area on the map. Then, given certain geographical coordinates, a hexagon…
Maciej Gurban
  • 5,615
  • 4
  • 40
  • 55
7
votes
1 answer

How to change icon-size in mapbox gl on click?

I want to change the icon-size on map click based on the turf-nearest. How do i accomplish this? nearestBuilding.properties['icon-size'] = 0.2; does not work. var retail = { type: 'FeatureCollection', features: [ { …
Merida
  • 368
  • 1
  • 3
  • 13
7
votes
2 answers

How to get bounding box based on distance from given point?

I need restrict map area to 5km radius around given point. How can I get appropriate bounding box using mapbox-gl-js or turf?
Rantiev
  • 2,121
  • 2
  • 32
  • 56
6
votes
1 answer

Trying to use turf js in angular 5

I'm an angular 5 (and turfjs) noob trying to use the turfjs along(). I've got a pretty simple working angular 5 project (built with angular-cli). To add turf I ran: npm install @turf/along --save and I see @turf/along in my node modules directory. …
eze
  • 2,332
  • 3
  • 19
  • 30
5
votes
1 answer

Cant remove area intersection between polygons

I have two polygons with invisible and unremovable intersection. I tried to find difference between them by removing area of second from first, and find intersection again - result intersection still present and have common area. Why this is…
Max Max
  • 389
  • 1
  • 2
  • 12
5
votes
1 answer

3D Extrusion with mapbox based on local geojson file

I have seen this example online which does data-driven building extrusion but doesn't provide the code at all. I would very much like to achieve the same thing. I have a geojson file with some kind of attribute that I would like to map onto the…
LBes
  • 3,366
  • 1
  • 32
  • 66
5
votes
1 answer

turf.nearestPoint only returning the same point

I am making a Leaflet map. I am loading some geoJSON data. I have an on click function for the map. When I click I simply want to alert the nearest point from the loaded geoJSON. The problem is that only one point is returned no matter where I click…
Worm
  • 1,313
  • 2
  • 11
  • 28
5
votes
1 answer

How to feed JSON data of coordinates to turf.polygon?

How to feed JSON data of coordinates to turf.polygon? Example: turf.polygon(); var polygon = turf.polygon([[ [-2.275543, 53.464547], [-2.275543, 53.489271], [-2.215118, 53.489271], [-2.215118, 53.464547], [-2.275543, 53.464547] ]], { name:…
JinD
  • 53
  • 1
  • 4
5
votes
1 answer

Can turf.js be used to find and repair bad geojson geometry?

Methods: I'm currently using turf.js for geoprocessing as part of a broader mapping project; my workflow looks like this: Pull geojson of census tracts for an entire county Pull geojson tiles of water polygons from OSM for the county…
Bill Morris
  • 589
  • 8
  • 16
5
votes
1 answer

How to merge adjacent polygons

I'm using a Javascript implementation of Fortune's algorithm to compute voronoi cells (https://github.com/gorhill/Javascript-Voronoi). My sites to compute are points on a map (so (lat,lng)). I first made the projection (lat,lng) -> (x,y), I then…
kwn
  • 909
  • 2
  • 13
  • 25
4
votes
1 answer

Turf.js and PostGIS 'difference' function giving unexpected result

I have a polygon and a multipolygon. I want to create a geometry that is the area where the 2 geometries do not intersect. The result I get (red outline in the example) seems to have something like an extra point in the southmost and northmost…
A. Mort
  • 278
  • 4
  • 12
1
2 3
19 20