A modular geospatial engine written in JavaScript

Overview

turf

Version Badge Travis CI Gitter chat Backers on Open Collective Sponsors on Open Collective Coverage Status Greenkeeper badge

A modular geospatial engine written in JavaScript

turfjs.org


Turf is a JavaScript library for spatial analysis. It includes traditional spatial operations, helper functions for creating GeoJSON data, and data classification and statistics tools. Turf can be added to your website as a client-side plugin, or you can run Turf server-side with Node.js (see below).

Installation

In Node.js

npm install @turf/turf

In browser

Download the minified file, and include it in a script tag. This will expose a global variable named turf.

<script src="turf.min.js" charset="utf-8"></script>

You can also include it directly from a CDN:

<script src="https://cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>

You can create light-weight turf builds with only the functions you need using the turfjs-builder UI or using browserify as described below.

Browserify

All of Turf's functions can also be installed as separate modules. This works well with tools like browserify where you want to install only the code you need. It also allows you to mix and match modules. This is the recommended usage pattern for most production environments. For example, to install the point and buffer modules use:

npm install @turf/helpers @turf/buffer

Bower [NOTE: Bower support has been dropped Jan 1st 2017]

Not recommended. Please don't use Bower. Use Browserify, Webpack, or the CDN instead.

TypeScript

TypeScript is supported internally within each module, no installs required.

Other languages

Ports of Turf.js are available in:

Turf for Swift is experimental and its public API is subject to change. Please use with care.


Data in Turf

Turf uses GeoJSON for all geographic data. Turf expects the data to be standard WGS84 longitude, latitude coordinates. Check out geojson.io for a tool to easily create this data.

NOTE: Turf expects data in (longitude, latitude) order per the GeoJSON standard.

Most Turf functions work with GeoJSON features. These are pieces of data that represent a collection of properties (ie: population, elevation, zipcode, etc.) along with a geometry. GeoJSON has several geometry types such as:

  • Point
  • LineString
  • Polygon

Turf provides a few geometry functions of its own. These are nothing more than simple (and optional) wrappers that output plain old GeoJSON. For example, these two methods of creating a point are functionally equivalent:

// Note order: longitude, latitude.
var point1 = turf.point([-73.988214, 40.749128]);

var point2 = {
  type: 'Feature',
  geometry: {
    type: 'Point',
    // Note order: longitude, latitude.
    coordinates: [-73.988214, 40.749128]
  },
  properties: {}
};

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Comments
  • New @turf-isobands module with MarchingSquares

    New @turf-isobands module with MarchingSquares

    • [X] Use a meaningful title for the pull request. Include the name of the package modified.
    • [X] Have read How To Contribute.
    • [X] Run npm test at the sub modules where changes have occured.
    • [ ] Run npm run lint to ensure code style at the turf module level. --> not sure how/if it works
    new-module 
    opened by stebogit 50
  • Implement `@turf/clusters-dbscan` module

    Implement `@turf/clusters-dbscan` module

    First draft of @turf/clusters-dbscan Ref. #811

    Note: this module might be merged into clusters and support both distance & numberOfClusters params (still up in the air).

    Compared to the kmeans cluster this is roughly 5x-50x times faster (the kdbush index does help a lot -- The performance will most likely slow down as weighted clusters becomes implemented).

    To-Do

    • [x] Translate existing GeoJSON properties
    • [x] Weighted clusters based on distance (right now the first point from each new cluster is the "center")
    • [x] Not too sure if we should be adding centroid/points in the outputs (instead of simply a FeatureCollection<Point>). Using the cluster property param is already enough to be able to create a centroid/center/centerOfMass.
    • [x] Only supports kilometers as distance

    More To-Dos

    • [x] change library name to clusters-dbscan
    • [x] add a dbscan property
    • [x] drop the centroid
    • [x] Prevent input mutation

    Examples

    points1.geojson

    image

    points2.geojson

    image

    new-module 
    opened by DenisCarriere 38
  • Getting Turf back on track

    Getting Turf back on track

    The goal for Turf v3 was to create a system in which Turf could be coordinated as a set of modules, operating independently but uniform in style, management, and properly versioned together. Unfortunately, that's no longer the case: the current codebase is heterogenous, hard to contribute to, and the guidelines for releases are nonexistent.

    About half of the modules are in TypeScript, and about half of those modules have a tsconfig.json file. About 40% of modules name their main export main, and the rest call it index. Same with providing a module entry point, it's about 50%. 3 modules have a .mjs module file, the rest have .es.js.

    Basically, there are no real homogenous properties of Turf anymore. It's a worst-case scenario for a mono-repo: it makes Turf maintenance feel much more like 'maintaining 55 modules' than it does 'maintaining a mono-repo'.

    Turf modules summary

    | name | tsconfig | main | module | in ts | | ---------------------------- | -------- | ------- | ---------- | ----- | | turf | | turf | turf.mjs | ๐Ÿ‘ | | along | ๐Ÿ‘ | index | | ๐Ÿ‘ | | angle | ๐Ÿ‘ | index | | ๐Ÿ‘ | | area | ๐Ÿ‘ | index | | ๐Ÿ‘ | | bbox | ๐Ÿ‘ | index | | ๐Ÿ‘ | | bbox-clip | ๐Ÿ‘ | index | | ๐Ÿ‘ | | bbox-polygon | ๐Ÿ‘ | index | | ๐Ÿ‘ | | bearing | ๐Ÿ‘ | index | | ๐Ÿ‘ | | bezier-spline | ๐Ÿ‘ | index | | ๐Ÿ‘ | | boolean-clockwise | ๐Ÿ‘ | index | | ๐Ÿ‘ | | boolean-concave | ๐Ÿ‘ | index | | ๐Ÿ‘ | | boolean-contains | ๐Ÿ‘ | index | | ๐Ÿ‘ | | boolean-crosses | | index | | ๐Ÿ‘ | | boolean-disjoint | ๐Ÿ‘ | index | | ๐Ÿ‘ | | boolean-equal | | index | | ๐Ÿ‘ | | boolean-intersects | ๐Ÿ‘ | index | | ๐Ÿ‘ | | boolean-overlap | | index | | ๐Ÿ‘ | | boolean-parallel | | index | | ๐Ÿ‘ | | boolean-point-in-polygon | ๐Ÿ‘ | index | | ๐Ÿ‘ | | boolean-point-on-line | ๐Ÿ‘ | index | | ๐Ÿ‘ | | boolean-touches | | index | | ๐Ÿ‘ | | boolean-valid | | index | | ๐Ÿ‘ | | boolean-within | | index | | ๐Ÿ‘ | | buffer | | main.js | main.es.js | | | center | | index | | ๐Ÿ‘ | | center-mean | | index | | ๐Ÿ‘ | | center-median | | index | | ๐Ÿ‘ | | center-of-mass | | index | | ๐Ÿ‘ | | centroid | | index | | ๐Ÿ‘ | | circle | | index | | ๐Ÿ‘ | | clean-coords | | index | | ๐Ÿ‘ | | clone | ๐Ÿ‘ | index | | ๐Ÿ‘ | | clusters | | index | | ๐Ÿ‘ | | clusters-dbscan | | index | | ๐Ÿ‘ | | clusters-kmeans | | index | | ๐Ÿ‘ | | collect | | index | | ๐Ÿ‘ | | combine | | index | | ๐Ÿ‘ | | concave | ๐Ÿ‘ | index | | ๐Ÿ‘ | | convex | ๐Ÿ‘ | index | | ๐Ÿ‘ | | destination | ๐Ÿ‘ | index | | ๐Ÿ‘ | | difference | | index | index.mjs | | | directional-mean | ๐Ÿ‘ | index | | ๐Ÿ‘ | | dissolve | | main.js | main.es.js | | | distance | | index | | ๐Ÿ‘ | | distance-weight | ๐Ÿ‘ | index | | ๐Ÿ‘ | | ellipse | | main.js | main.es.js | | | envelope | | main.js | main.es.js | | | explode | | main.js | main.es.js | | | flatten | | main.js | main.es.js | | | flip | | main.js | main.es.js | | | great-circle | | main.js | main.es.js | | | helpers | ๐Ÿ‘ | index | | ๐Ÿ‘ | | hex-grid | | index | | ๐Ÿ‘ | | interpolate | | main.js | main.es.js | | | intersect | ๐Ÿ‘ | index | | ๐Ÿ‘ | | invariant | ๐Ÿ‘ | index | | ๐Ÿ‘ | | isobands | | main.js | main.es.js | | | isolines | | main.js | main.es.js | | | kinks | ๐Ÿ‘ | index | | ๐Ÿ‘ | | length | ๐Ÿ‘ | index | | ๐Ÿ‘ | | line-arc | ๐Ÿ‘ | index | | ๐Ÿ‘ | | line-chunk | | main.js | main.es.js | | | line-intersect | ๐Ÿ‘ | index | | ๐Ÿ‘ | | line-offset | | main.js | main.es.js | | | line-overlap | | index | | ๐Ÿ‘ | | line-segment | ๐Ÿ‘ | index | | ๐Ÿ‘ | | line-slice | | main.js | main.es.js | | | line-slice-along | | main.js | main.es.js | | | line-split | | main.js | main.es.js | | | line-to-polygon | | index | | ๐Ÿ‘ | | mask | | main.js | main.es.js | | | meta | | index | index.mjs | | | midpoint | | main.js | main.es.js | | | moran-index | ๐Ÿ‘ | index | | ๐Ÿ‘ | | nearest-neighbor-analysis | ๐Ÿ‘ | index | | ๐Ÿ‘ | | nearest-point | ๐Ÿ‘ | index | | ๐Ÿ‘ | | nearest-point-on-line | | index | | ๐Ÿ‘ | | nearest-point-to-line | ๐Ÿ‘ | index | | ๐Ÿ‘ | | planepoint | | main.js | main.es.js | | | point-grid | | index | | ๐Ÿ‘ | | point-on-feature | | main.js | main.es.js | | | point-to-line-distance | ๐Ÿ‘ | index | | ๐Ÿ‘ | | points-within-polygon | | main.js | main.es.js | | | polygon-smooth | | main.js | main.es.js | | | polygon-tangents | | main.js | main.es.js | | | polygon-to-line | ๐Ÿ‘ | index | | ๐Ÿ‘ | | polygonize | | main.js | main.es.js | | | projection | | index | | ๐Ÿ‘ | | quadrat-analysis | ๐Ÿ‘ | index | | ๐Ÿ‘ | | random | ๐Ÿ‘ | index | | ๐Ÿ‘ | | rectangle-grid | | index | | ๐Ÿ‘ | | rewind | | main.js | main.es.js | | | rhumb-bearing | ๐Ÿ‘ | index | | ๐Ÿ‘ | | rhumb-destination | ๐Ÿ‘ | index | | ๐Ÿ‘ | | rhumb-distance | ๐Ÿ‘ | index | | ๐Ÿ‘ | | sample | | main.js | main.es.js | | | sector | | main.js | main.es.js | | | shortest-path | | main.js | main.es.js | | | simplify | | main.js | main.es.js | | | square | | main.js | main.es.js | | | square-grid | ๐Ÿ‘ | index | | ๐Ÿ‘ | | standard-deviational-ellipse | | main.js | main.es.js | | | tag | | main.js | main.es.js | | | tesselate | | main.js | main.es.js | | | tin | ๐Ÿ‘ | index | | ๐Ÿ‘ | | transform-rotate | | main.js | main.es.js | | | transform-scale | | main.js | main.es.js | | | transform-translate | | main.js | main.es.js | | | triangle-grid | | index | | ๐Ÿ‘ | | truncate | | index | | ๐Ÿ‘ | | union | | index | | ๐Ÿ‘ | | unkink-polygon | | main.js | main.es.js | | | voronoi | | main.js | main.es.js | |


    Organizationally, Turf currently has a small chunk of cash, a much much smaller number of long-term maintainers, and zero institutional/company code contributors. This is pretty common for open source projects.

    To propose a few ways forward:

    Remove TypeScript

    The TypeScript transition, while a very nice contribution, is unfinished and offers little to the project. We didn't have many bugs caused by type mismatches before, and the resulting addition of complexity outweighs the benefit.

    Would this be unpopular? Probably! But it'd be better to re-achieve stability and releasability, and make the project fit its actual contributors, than to perpetually be in a half-deployable state.

    If this is the option, we could do it by basically configuring tsc to generate ES modules.

    Move lerna.js back to fixed/locked mode

    Per https://github.com/Turfjs/turf/pull/1247 the lerna config was switched to independent versioning. This makes collaboration harder: the intent of lerna was and is to make versioning automatic so that the project can be released always with lerna publish. There should not be a thought process for which modules need updating and releases.

    Move releases/ back into changelog

    This releases directory is the same as a central changelog. Let's move these back to the changelog.

    Use standard commits

    Again, a common collaboration point - this will automate changelog generation and version more accurately

    Write these contribution tips into CONTRIBUTING.md

    And probably create a strong process for changing them. This stuff shouldn't become wobbly; Turf should stay in a deployable, simple state that all the maintainers have a grasp on.

    (Extreme solution) just move to a singular ES6 module

    This would probably be even less popular than removing TypeScript: create one turf module (again), now that tree-shaking means that people using Rollup/Webpack/Parcel can efficiently import a subsection of a module without including all of the code. This would drastically reduce complexity and let advanced users continue to get the performance advantages of the current mini-modules, but it would leave people using old-fashioned require etc out in the cold.

    Honestly I'm also in favor of this extreme solution: it'd be a huge decrease in complexity, and it'd do this for existing users:

    1. Script-tag or browserify users: yep, would be slower
    2. Node users: probably don't mind the startup time or install size that much
    3. Webpack/Rollup users: would work great
    4. Future native-js module users: would easily be able to sub-import

    This is intended to be a bit of a jumping-off point, none of these ways to victory are quick-fixes and we'd want to attain some consensus before embarking on them. Dividing this work up would also be useful, given that there are few maintainers, or if there is an institutional/company contributor who wants to take on some of this, it'd be more than welcome - Turf is definitely generating a lot of value out there in the world, much more than it captures.

    typescript 
    opened by tmcw 34
  • New module @turf/transform-scale

    New module @turf/transform-scale

    Ref: #747

    @DenisCarriere @dpmcmlxxvi The output is currently not correct: it is scaled successfully, but for some reason it does not reflect the factor value. I implemented my proposal for the origin; I look forward to knowing your opinion. Also, the scaling along the z-coordinate is not along a Rhumb line, but a simple multiplication by 'factor'. Is there a way, if it make sense at all, to perform such a scaling on z?

    For the moment I'd keep it simple and consider only uniform scalings, i.e. scaling factor equal in all directions.

    new-module 
    opened by stebogit 34
  • Turf Transform

    Turf Transform

    Implemented first module @turf/transform-translate Note: I used @turf/rhumb-destination to create the translation vector, which defines the motion; needs to be checked if the length of the resulting translation matches the provided distance.

    Please feel free to comment, suggest, correct, add tests.

    (Ref: #747)

    new-module 
    opened by stebogit 30
  • New module @turf/line-offset

    New module @turf/line-offset

    New Module @turf/line-offset

    Adds a new lineOffset module as per this issue. Basically takes an input line and returns a new line offset by the distance.

    Geometry Support

    • [x] LineString => LineString
    • [x] MultiLineString => MultiLineString

    Geometry NOT supported

    • Point => LineString (alternative @turf/circle?)
    • MultiPoint => MultiLineString (alternative @turf/circle?)
    • Polygon => LineString (alternative @turf/buffer / @turf/transform-scale)
    • MultiPolygon => MultiLineString (alternative @turf/buffer / @turf/transform-scale)
    • FeatureCollection/GeometryCollection (might contain mixed geometries and cause errors)

    To-Do

    • [x] Start and end points of the resulting line shall not be connected.
    • [ ] Equidistance offset (similar to issue https://github.com/Turfjs/turf/issues/660 / https://github.com/Turfjs/turf/pull/718)

    JSDocs

    /**
     * Takes a {@link LineString|line} and returns a {@link LineString|line} at offset by the specified distance.
     *
     * @name lineOffset
     * @param {Geometry|Feature<LineString>} line input line
     * @param {number} offset distance to offset the line (can be of negative value)
     * @param {string} [units=kilometers] can be degrees, radians, miles, kilometers, inches, yards, meters
     * @returns {Feature<LineString>} Line offset from the input line
     * @example
     * var line = {
     *   "type": "Feature",
     *   "properties": {},
     *   "geometry": {
     *     "type": "LineString",
     *     "coordinates": [[-83, 30], [-84, 36], [-78, 41]]
     *   }
     * };
     *
     * var offsetLine = turf.lineOffset(line, 2, 'miles');
     *
     * //addToMap
     * var addToMap = [offsetLine, line]
     */
    

    Examples

    image

    • [x] Use a meaningful title for the pull request. Include the name of the package modified.
    • [x] Have read How To Contribute.
    • [x] Run npm test at the sub modules where changes have occurred.
    • [x] Run npm run lint to ensure code style at the turf module level.
    new-module 
    opened by rowanwins 29
  • Update lerna to the latest version ๐Ÿš€

    Update lerna to the latest version ๐Ÿš€

    The devDependency lerna was updated from 2.8.0 to 3.4.2.

    This version is not covered by your current version range.

    If you donโ€™t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.


    Release Notes for v3.4.2

    Bug Fixes

    • publish: Prevent retries during access validation so third-party registries are skipped faster (a89ae62)
    • publish: Use modern auth resolution (7ba41a6)
    Commits

    The new version differs by 660 commits ahead by 660, behind by 8.

    • 6afcde7 chore(release): publish v3.4.2
    • bef9a83 chore: bump transitive dependencies
    • 3d68d87 chore: bump dev dependencies
    • a89ae62 fix(publish): Prevent retries during access validation so third-party registries are skipped faster
    • 7ba41a6 fix(publish): Use modern auth resolution
    • ef47f2a docs(version): document the โ€”yes option (#1715)
    • 05a27a6 chore(release): publish v3.4.1
    • f7fdc77 fix(publish): Overwrite Yarn registry proxy when encountered
    • 06a9479 fix(publish): Set token on npm config, allow third-party registries to remain non-compliant
    • 987fd26 fix(bootstrap): Constrain npm-conf argument object to options.registry only
    • 597606c fix(add): Allow --registry option
    • 25af71d fix(npm-conf): Do not overwrite defaults with undefined cli keys
    • 159a0b0 fix(conventional-commits): Upgrade angular preset, ensure header is not duplicated
    • 9752f3e fix(conventional-commits): Upgrade dependencies
    • a60a0c3 docs: Add 'lerna create' command to README.md (#1680)

    There are 250 commits in total.

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those donโ€™t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    opened by greenkeeper[bot] 25
  • Turf does not work with Webpack 4

    Turf does not work with Webpack 4

    I upgraded my project to Angular 6 which migrated to Webpack 4. I have a dependency on mapbox which uses turf. After the upgrade I started getting build errors like the following.

    ERROR in ./node_modules/@turf/meta/index.mjs
    997:15-25 Can't import the named export 'lineString' from non EcmaScript module (only default export is available)
     @ ./node_modules/@turf/meta/index.mjs
     @ ./src/index.js
    

    It appears to be failing because @turf/meta uses mjs and @turf/helpers is a non mjs module. I am not sure if this is just a build configuration in Webpack that needs to be tweaked or if a correction needs to be made to turf. I looked around the Webpack issues and didn't really see anything to help along with a fix.

    Here is a repo to easily reproduce this issue.

    https://github.com/adamduren/webpack4-turf-issue

    awaiting feedback 
    opened by adamduren 25
  • Major release pre-announcement (TurfJS v5.0)

    Major release pre-announcement (TurfJS v5.0)

    Major release pre-announcement (TurfJS v5.0) โญ๏ธ ๐Ÿ“ข

    Due to some drastic changes coming up, the next TurfJS release will be v5.0 (Major release).

    If anyone has any suggestions for breaking changes, the time would be now to do it.

    Timeline

    Approximately a 1-2 weeks (end of September/ early October, 2017).

    Major To-Dos before publish

    • [ ] Finish adding new optional parameters (options) (PR https://github.com/Turfjs/turf/pull/953)
    • [x] Convert to ES6 modules using Rollup (PR https://github.com/Turfjs/turf/pull/960)
    • [ ] v5.0 issues

    Not happening for next publish

    • [x] jsts won't be entirely removed

    @stebogit @rowanwins Any additional suggestions for v5.0 changes?

    Don't hesitate to send some breaking PR changes (within reason & approved).

    CC: @Turfjs/ownership

    major-release 
    opened by DenisCarriere 25
  • ringEach Proposal

    ringEach Proposal

    So just wanted to continue the discussion from this pull request.

    I'd find it quite handy to have a module that looped through interior and exterior rings of polys easily.

    turf.ringEach(feature, function (ringCoords, ringIndex, isExterior) {
      //=ringCoords = [[0,0], [1,1], [1, 0], [0, 0]]
      //=ringIndex = 0
      //=isExterior = true
    });
    

    @DenisCarriere you proposed splitting the module into interior and exterior versions, I'm just trying to think through whether it would be better to have them together in a single module and how I'd use them....

    In an ideal world I'd then love to be able to pass a coord array into one of the other meta functions, eg coordEach without having to first turn into a geojson feature or geometry.

    Anyway just starting the discussion rolling in a more trackable place than a vaguely related pull request :)

    new-module proposal 
    opened by rowanwins 24
  • New module @turf/sector

    New module @turf/sector

    @DenisCarriere I implemented the turf-sector module (related to #155 and #649). However I did not create the README file cause I thought it was created automatically from the documentation in the index.js, but it didn't. Should I create it manually? Not sure if the index.d.ts and bench.js are correct, as I'm not familiar with them.

    Is that ok if I created the branch in this repo or should I work on my forked one?

    new-module 
    opened by stebogit 24
  • Self-intersecting polygon has wrong area

    Self-intersecting polygon has wrong area

    Self-intersecting polygon has wrong area. It cannot be zero:

    • [x] Version: @turf/[email protected].
    • [x] GeoJSON data as a gist file: https://gist.github.com/sigorilla/e0f97a91e579bc1f27e4a950352a29ae
    • [x] Snippet of source code: https://runkit.com/sigorilla/turf-area-self-intersecting
    @turf/area 
    opened by sigorilla 1
  • Fix typo in @turf/boolean-intersects README

    Fix typo in @turf/boolean-intersects README

    Please fill in this template.

    • [x] Use a meaningful title for the pull request. Include the name of the package modified.
    • [x] Have read How To Contribute.
    • [x] Run npm test at the sub modules where changes have occurred.
    • [x] Run npm run lint to ensure code style at the turf module level.

    This is a minor PR to fix what I thought might be a typo in the @turf/boolean-intersects docs. The example has two geometries that don't intersect, but says it returns true. Thank you!

    opened by rbrtmrtn 0
  • Projection problem with buffer function

    Projection problem with buffer function

    I use @turf/turf 6.5.0.

    Features of the screenshot :

    {
      type: 'Feature',
      geometry: { type: 'LineString', coordinates: Array.from({ length: 27 }, (_, i) => [20, i * 5 - 65]) },
      properties: {}
    },
    ...Array.from({ length: 27 }, (_, i) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [0, i * 5 - 65] } as GeometryPoint, properties: {} } as GeoJsonFeature<GeometryPoint>))
    

    When I create a 140 miles buffer with the turf buffer function, here's what happened :

    image

    (For rendering the map, I use OpenLayer 7.1.0 in projection EPSG:4326)

    The buffer of each point is correct, but every time I try to buffering an other king of Geometry, such as LineString or Polygon, the buffer is not correct : it doesn't respect the projection and the distances.

    @turf/buffer 
    opened by KyllianGautier 0
  • Simplify creates invalid polygons with 3 points because cleanCoords removes too many points

    Simplify creates invalid polygons with 3 points because cleanCoords removes too many points

    Please provide the following when reporting an issue:

    • [x] The version of Turf you are using, and any other relevant versions (6.5.0)
    • [x] GeoJSON data as a https://gist.github.com/Kilowhisky/5f3a5e3b7c3467a7913a19785c702cc3
    • [x] Snippet of source code or for complex examples use jsfiddle.
    simplify(feature, {
                tolerance: 0.01,
                highQuality: true,
                mutate: true
    });
    
    Error: invalid polygon
        at file:///C://node_modules/@turf/simplify/dist/es/index.js:257:13
        at Array.map (<anonymous>)
        at simplifyPolygon (file:///C://node_modules/@turf/simplify/dist/es/index.js:252:22)
        at file:///C://node_modules/@turf/simplify/dist/es/index.js:215:16
        at Array.map (<anonymous>)
        at simplifyGeom (file:///C://node_modules/@turf/simplify/dist/es/index.js:214:45)
        at file:///C://node_modules/@turf/simplify/dist/es/index.js:169:5
        at geomEach (file:///C://node_modules/@turf/meta/dist/es/index.js:590:13)
        at simplify$1 (file:///C://node_modules/@turf/simplify/dist/es/index.js:168:3)
        at _getAlertFeatureCollection (file:///C://handler.js:113:9)   
    

    It seems that internally turf.simplify calls cleanCoords. It appears that cleanCoords will remove duplicates so much that it will make polygons invalid by reducing them below the 4 point minimum.

    As a bonus here is the raw GeoJSON that the above Gist was constructed out of by the truncate and union function. What I was attempting to do was combine all polygons and simplify to make the object easier to render. https://gist.github.com/Kilowhisky/bd1b46f162aac622c5a77dfebb709d5e

    @turf/simplify 
    opened by Kilowhisky 0
  • Union of multiple Features/polygons yet in version 6

    Union of multiple Features/polygons yet in version 6

    turf-union in all its docs mentions the union of only two (multi)polygons or geojson's

    https://www.npmjs.com/package/@turf/union

    It would be nice and useful if we could unite several (multi)polygons or geojson's

    let union
    union = turf.union(poly1, poly2)
    union = turf.union(poly1, poly2, poly3)
    union = turf.union(poly1, poly2, poly3, ..., polyn)
    
    const polygons = [poly1, poly2, poly3, ..., polyn]
    union = turf.union(...polygons)
    
    opened by jfoclpf 10
  • Clarify that coordsMap mutates input

    Clarify that coordsMap mutates input

    I was looking for a way to transform each coordinate of a GeoJSON object and was about to propose .coordMap() (similar to #1438).

    It was only by reading through the comments that I realised that .coordEach() can be used to do in-place transformation.

    I'd suggest updating the description from:

    Iterate over coordinates in any GeoJSON object, similar to Array.forEach()

    to:

    Iterate over coordinates in any GeoJSON object, analogous to Array.forEach(). Modifications to currentCoord mutate the input object.

    (IMHO "analogous" is a better word here than "similar" because of the different arguments and input type)

    Also, if possible, clarify what coordIndex is, because it's not that obvious to me in the case of a (Multi)Polygon.

    opened by stevage 0
Releases(v6.5.0)
  • v6.5.0(Jul 10, 2021)

    6.5.0

    ๐Ÿ… New Features/Enhancements

    ๐Ÿ› Bug Fixes

    • @turf/dissolve Complete rewrite of the dissolve module to resolve many bugs (PR https://github.com/Turfjs/turf/pull/2110 - Author @rowanwins)

    • @turf/mask Complete rewrite of the mask module to resolve many bugs (PR https://github.com/Turfjs/turf/pull/2130 - Author @rowanwins)

    • @turf/boolean-valid Add missing dependency to (PR https://github.com/Turfjs/turf/pull/2094 - Author @rycgar)

    ๐Ÿ“– Documentation

    • @turf/boolean-overlap Improve clarity (PR https://github.com/Turfjs/turf/pull/2133 - Author @patrickbrett)

    ๐Ÿ”” Misc

    • Enable TS Strict Mode (PR https://github.com/Turfjs/turf/pull/2126 - Author @mfedderly)
    Source code(tar.gz)
    Source code(zip)
  • v3.0.11(Jun 17, 2016)

    • removes vendored point-on-line implementation in favor of a local dependency
    • add test fixture for vertical linestrings passed to turf-line-slice
    Source code(tar.gz)
    Source code(zip)
  • v3.0.3(May 17, 2016)

  • v3.0.1(May 17, 2016)

    This is a big change in Turf! 3.0.0 is a release that targets the development cycle of Turf, letting us work on it more and release more often.

    Monorepo

    Turf 3.x and forward is a monorepo project. We publish lots of little modules as usual, but there's one repo - turfjs/turf - that contains all the code and the issues for the Turf source code. We use lerna to link these packages together and make sure they work.

    Why? We already had internal turf modules, like turf-meta, and development was harder and harder - we had a bunch of custom scripts to do releases and tests, and these were just written for Turf. Lerna is from the very popular and very well-maintained babel project, and it works really well, and reduces maintainer sadness.

    Simplicity

    Turf grew a bunch of modules that weren't totally necessary, or were expressing only a line or two of JavaScript. We want to make things easier, but these modules didn't make code more expressive and they hid complexity where it didn't need to be hidden. Turf 3.x focuses on the core functionalities we need, making sure they're tested and performant.

    Removed modules: merge, sum, min, max, average, median, variance, deviation, filter, remove, jenks, quantile. See the upgrade guide below for replacements.

    Upgrading from v2

    If you were using turf-merge

    turf-merge repeatedly called turf-union on an array of polygons. Here's how to implement the same thing without the special module

    var clone = require('clone');
    var union = require('turf-union');
    function merge(polygons) {
      var merged = clone(polygons.features[0]), features = polygons.features;
      for (var i = 0, len = features.length; i < len; i++) {
        var poly = features[i];
        if (poly.geometry) merged = union(merged, poly);
      }
      return merged;
    }
    

    If you were using turf-sum, min, max, average, median, variance, deviation

    The turf-collect method provides the core of these statistical methods and lets you bring your own statistical library, like simple-statistics, science.js, or others.

    If you were using turf-filter, turf-remove

    These modules were thin wrappers around native JavaScript methods: use Array.filter instead:

    var filteredFeatures = features.filter(function(feature) {
      return feature.properties.value > 10;
    });
    

    If you were using turf-jenks, turf-quantile

    Use Array.map to get values, and then bring your own statistical calculation, like simple-statistics or science.js.

    var values = features.map(function(feature) {
      return feature.properties.value;
    });
    
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Feb 24, 2015)

    • turf-grid renamed turf-point-grid (turf.grid => turf.pointGrid)
    • turf-hex renamed turf-hex-grid (turf.hex => turf.hexGrid)
    • turf-hex-grid now has a required unit parameter
    • remove turf-isobands; use turf-isolines instead
    • added turf-square-grid (turf.squareGrid)
    • added turf-triangle-grid (turf.triangleGrid)
    • constrain turf-point-grid to the bbox
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Feb 6, 2015)

    1.4.0

    • update all module dependencies to master
    • add support for features in turf.intersection
    • fix issues with turf.polygon coordinate wrapping inconsistencies
    • add unit parameter to turf.concave
    Source code(tar.gz)
    Source code(zip)
  • v1.3.5(Feb 4, 2015)

  • v1.3.4(Jan 29, 2015)

  • v1.3.3(Jan 26, 2015)

    • added turf-line-slice for segmenting LineStrings with Points
    • turf-point-on-line for calculating the closest Point from a Point to a LineString
    Source code(tar.gz)
    Source code(zip)
Owner
turf
a fast and fully featured open gis engine written in javascript
turf
๐Ÿค– GPU accelerated Neural networks in JavaScript for Browsers and Node.js

brain.js GPU accelerated Neural networks in JavaScript for Browsers and Node.js About brain.js is a GPU accelerated library for Neural Networks writte

brain.js 13.4k Jan 7, 2023
A JavaScript PDF generation library for Node and the browser

PDFKit A JavaScript PDF generation library for Node and the browser. Description PDFKit is a PDF document generation library for Node and the browser

null 8.5k Jan 2, 2023
A pure JavaScript implementation of git for node and browsers!

isomorphic-git isomorphic-git is a pure JavaScript reimplementation of git that works in both Node.js and browser JavaScript environments. It can read

isomorphic-git 6.7k Jan 4, 2023
IPFS implementation in JavaScript

The JavaScript implementation of the IPFS protocol Upgrading from <=0.40 to 0.48? See the release notes for the list of API changes and the migration

IPFS 7.2k Jan 8, 2023
A javascript Bitcoin library for node.js and browsers.

BitcoinJS (bitcoinjs-lib) A javascript Bitcoin library for node.js and browsers. Written in TypeScript, but committing the JS files to verify. Release

bitcoinjs 4.8k Jan 1, 2023
A JavaScript implementation of Git.

JS-Git This project is a collection of modules that helps in implementing git powered applications in JavaScript. The original purpose for this is to

Tim Caswell 3.8k Dec 31, 2022
Bertin.js is a JavaScript library for visualizing geospatial data and make thematic maps for the web.

Bertin.js is a JavaScript library for visualizing geospatial data and make thematic maps for the web. The project is under active development. Some of

Nicolas LAMBERT 229 Dec 20, 2022
WebGL2 powered geospatial visualization layers

deck.gl | Website WebGL2-powered, highly performant large-scale data visualization deck.gl is designed to simplify high-performance, WebGL-based visua

Vis.gl 10.5k Jan 9, 2023
A very fast geospatial point clustering library for browsers and Node.

supercluster A very fast JavaScript library for geospatial point clustering for browsers and Node. <script src="https://unpkg.com/[email protected]/d

Mapbox 1.6k Jan 7, 2023
App for displaying geospatial data on queues on the Polish-Ukrainian border.

Live app embedded here. App helps coordinate volunteer work with refugees from Ukraine on Polish-Belarusian Border. Data comes from Grupa Granica โ€“ a

null 3 Mar 10, 2022
Low-Level GeoSpatial Masking Functions

geomask Low-Level GeoSpatial Masking Functions features calculate raster pixels inside and outside a geometry mask built-in reprojection support for a

Daniel J. Dufour 4 Jul 22, 2022
Dashboards-maps is a frontend plugin that helps you in uploading custom GeoJSON to OpenSearch and communicates with the geospatial backend plugin for the same.

Welcome! Project Resources Code of Conduct License Copyright Dashboards-Maps Dashboards-maps is a frontend plugin that helps you in uploading custom G

null 9 Dec 28, 2022
๐Ÿ’ฐThe Shopify-like Digital Commerce engine provides an Open-Source ๐Ÿ†“ and Headless/Modular Architecture โšก

?? The Shopify-like Digital Commerce โšก ?? The Shopify-like Digital Commerce engine provides an Open-Source ?? and Serverless Architecture โšก ?? The Sho

OceanSoft 7 Nov 7, 2022
The one DAO to rule them all. A modular DAO written in Clarity for the Stacks blockchain.

ExecutorDAO The one DAO to rule them all. ExecutorDAO is designed to be completely modular and flexible, leveraging Clarity to the fullest extent. The

Marvin 31 Oct 5, 2022
This is my to-do list website built with html, css and JavaScript. In this project I used Webpack to bundle JavaScript and ES6 modules to write modular JavaScript.

To-Do-List App This is my to-do list website built with html, css and JavaScript. In this project I used Webpack to bundle JavaScript and ES6 modules

Samuel Mwape 18 Sep 20, 2022
The 2D Game Engine written on JavaScript.

CherryEngine The 2D Game Engine written in JavaScript. NEW UPDATE Version 1.2 Added: TypeObjectError.js Changed: static methods are not static now, yo

> sazix 4 Oct 26, 2022
The project integrates workflow engine, report engine and organization authority management background, which can be applied to the development of OA, HR, CRM, PM and other systems. With tlv8 IDE, business system development, testing and deployment can be realized quickly.

ไป‹็ป ้กน็›ฎ้›†ๆˆไบ†ๅทฅไฝœๆตๅผ•ๆ“Žใ€ๆŠฅ่กจๅผ•ๆ“Žๅ’Œ็ป„็ป‡ๆœบๆž„ๆƒ้™็ฎก็†ๅŽๅฐ๏ผŒๅฏไปฅๅบ”็”จไบŽOAใ€HRใ€CRMใ€PM็ญ‰็ณป็ปŸๅผ€ๅ‘ใ€‚้…ๅˆไฝฟ็”จtlv8 ideๅฏไปฅๅฟซ้€Ÿๅฎž็ŽฐไธšๅŠก็ณป็ปŸๅผ€ๅ‘ใ€ๆต‹่ฏ•ใ€้ƒจ็ฝฒใ€‚ ๅŽๅฐ้‡‡็”จSpring MVCๆžถๆž„็ฎ€ๅ•ๆ–นไพฟ๏ผŒๅ‰็ซฏไฝฟ็”จๆต่กŒ็š„layui็•Œ้ข็พŽ่ง‚ๅคงๆ–นใ€‚ ้‡‡็”จ็ป„ไปถๅผ€ๅ‘ๆŠ€ๆœฏ๏ผŒๆ้ซ˜็ณป็ปŸ็š„็ตๆดปๆ€งๅ’Œๅฏๆ‰ฉๅฑ•ๆ€ง;้‡‡

Qian Chen 38 Dec 27, 2022
Engine editor for the engine-sim

Enginette An engine maker/editor for the engine-sim by AngeTheGreat. Warning: Code is still in development, thus it will change frequently Another War

null 39 Dec 15, 2022
Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript โ›บ

squirrelly Documentation - Chat - RunKit Demo - Playground Summary Squirrelly is a modern, configurable, and blazing fast template engine implemented

Squirrelly 451 Jan 2, 2023
Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript

eta (ฮท) Documentation - Chat - RunKit Demo - Playground Summary Eta is a lightweight and blazing fast embedded JS templating engine that works inside

Eta 682 Dec 29, 2022