How to use the @turf/helpers.polygon function in @turf/helpers

To help you get started, we’ve selected a few @turf/helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CityOfPhiladelphia / mapboard / src / controller / data-manager.js View on Github external
}

    const featuresSorted = this.sortDorParcelFeatures(features);
    let feature;

    if (!multipleAllowed) {
      feature = features[0];
    // dor
    } else {
      feature = featuresSorted[0];
    }

    // use turf to get area and perimeter of all parcels returned
    for (let featureSorted of featuresSorted) {
      // const turfPolygon = polygon(featureSorted.geometry.coordinates);
      const turfPolygon = polygon(featureSorted.geometry.coordinates);
      let turfCoordinates = []
      for (let coordinate of featureSorted.geometry.coordinates[0]) {
        // console.log('coordinate:', coordinate);
        turfCoordinates.push(point(coordinate));
      }

      let distances = []
      for (let i=0; i
github Turfjs / turf / src / combine / bench.js View on Github external
var pt2 = point(100, 101)

// MultiLineString
var l1 = lineString([
[102.0,
-10.0],
[130.0,
4.0]])
var l2 = lineString([
[40.0,
-20.0],
[150.0,
18.0]])

// MultiPolygon
var p1 = polygon( [
  [
    [20.0,0.0],
    [101.0,0.0],
    [101.0,1.0],
    [100.0,1.0],
    [100.0,0.0]
  ]
])
var p2 = polygon([
  [
    [30.0,0.0],
    [102.0,0.0],
    [103.0,1.0]
  ]
])
github Turfjs / turf / packages / turf-isobands / index.js View on Github external
function groupNestedRings(orderedLinearRings) {
    // create a list of the (coordinates of) LinearRings
    var lrList = orderedLinearRings.map(function (lr) {
        return {lrCoordinates: lr, grouped: false};
    });
    var groupedLinearRingsCoords = [];
    while (!allGrouped(lrList)) {
        for (var i = 0; i < lrList.length; i++) {
            if (!lrList[i].grouped) {
                // create new group starting with the larger not already grouped ring
                var group = [];
                group.push(lrList[i].lrCoordinates);
                lrList[i].grouped = true;
                var outerMostPoly = polygon([lrList[i].lrCoordinates]);
                // group all the rings contained by the outermost ring
                for (var j = i + 1; j < lrList.length; j++) {
                    if (!lrList[j].grouped) {
                        var lrPoly = polygon([lrList[j].lrCoordinates]);
                        if (isInside(lrPoly, outerMostPoly)) {
                            group.push(lrList[j].lrCoordinates);
                            lrList[j].grouped = true;
                        }
                    }
                }
                // insert the new group
                groupedLinearRingsCoords.push(group);
            }
        }
    }
    return groupedLinearRingsCoords;
github heremaps / here-cli / src / hexbin.ts View on Github external
function hexagon(center:number[], rx:number, ry:number, properties:any, cosines:number[], sines:number[]): any {
    const vertices = [];
    for (let i = 0; i < 6; i++) {
        const x = round(center[0] + rx * cosines[i],6);
        const y = round(center[1] + ry * sines[i],6);
        vertices.push([x, y]);
    }
    //first and last vertex must be the same
    vertices.push(vertices[0].slice());
    let feature = turf.polygon([vertices], properties);
    feature.properties.centroid = center;
    return feature;
}
github Turfjs / turf / packages / turf-union / types.ts View on Github external
import { polygon } from '@turf/helpers';
import union from './';

const poly1 = polygon([[[0, 0], [10, 10], [20, 20], [0, 0]]]);
const poly2 = polygon([[[20, 30], [10, 10], [20, 20], [20, 30]]]);
union(poly1, poly2);
github kepta / idly / packages / idly-common / src / geojson / entityToGeojson.ts View on Github external
export function wayToLineString(
  geom: OsmGeometry,
  nodeCoords: number[][]
): Feature
github Turfjs / turf / packages / turf-polygonize / lib / EdgeRing.js View on Github external
toPolygon() {
        if (this.polygon)
            return this.polygon;
        const coordinates = this.edges.map(edge => edge.from.coordinates);
        coordinates.push(this.edges[0].from.coordinates);
        return (this.polygon = polygon([coordinates]));
    }
github Turfjs / turf / packages / turf-mask / types.ts View on Github external
import {polygon} from '@turf/helpers';
import mask from './';

const poly1 = polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
const poly2 = polygon([[[30, 5], [-40, -10], [-50, -10], [-40, 5], [30, 5]]]);

mask(poly1)
mask(poly1, poly2)
github alex3165 / react-mapbox-gl / src / cluster.tsx View on Github external
private mapChange = (forceSetState: boolean = false) => {
    const { map } = this.props;
    const { superC, clusterPoints } = this.state;

    const zoom = map.getZoom();
    const canvas = map.getCanvas();
    const w = canvas.width;
    const h = canvas.height;
    const upLeft = map.unproject([0, 0]).toArray();
    const upRight = map.unproject([w, 0]).toArray();
    const downRight = map.unproject([w, h]).toArray();
    const downLeft = map.unproject([0, h]).toArray();
    const newPoints = superC.getClusters(
      bbox(polygon([[upLeft, upRight, downRight, downLeft, upLeft]])),
      Math.round(zoom)
    );
    if (newPoints.length !== clusterPoints.length || forceSetState) {
      this.setState({ clusterPoints: newPoints });
    }
  };