How to use the @turf/polygon-to-line function in @turf/polygon-to-line

To help you get started, we’ve selected a few @turf/polygon-to-line 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 uber / nebula.gl / modules / layers / src / mode-handlers / split-polygon-handler.js View on Github external
calculateGroundCoords(clickSequence: any, groundCoords: any) {
    const modeConfig = this.getModeConfig();
    if (!modeConfig || !modeConfig.lock90Degree || !clickSequence.length) {
      return groundCoords;
    }
    if (clickSequence.length === 1) {
      // if first point is clicked, then find closest polygon point and build ~90deg vector
      const firstPoint = clickSequence[0];
      const selectedGeometry = this.getSelectedGeometry();
      const feature = turfPolygonToLine(selectedGeometry);

      const lines = feature.type === 'FeatureCollection' ? feature.features : [feature];
      let minDistance = Number.MAX_SAFE_INTEGER;
      let closestPoint = null;
      // If Multipolygon, then we should find nearest polygon line and stick split to it.
      lines.forEach(line => {
        const snapPoint = nearestPointOnLine(line, firstPoint);
        const distanceFromOrigin = turfDistance(snapPoint, firstPoint);
        if (minDistance > distanceFromOrigin) {
          minDistance = distanceFromOrigin;
          closestPoint = snapPoint;
        }
      });

      if (closestPoint) {
        // closest point is used as 90degree entry to the polygon
github Turfjs / turf / packages / turf-boolean-disjoint / index.ts View on Github external
function isPolyInPoly(feature1: Polygon, feature2: Polygon) {
    for (const coord1 of feature1.coordinates[0]) {
        if (booleanPointInPolygon(coord1, feature2)) {
            return true;
        }
    }
    for (const coord2 of feature2.coordinates[0]) {
        if (booleanPointInPolygon(coord2, feature1)) {
            return true;
        }
    }
    const doLinesIntersect = lineIntersect(polygonToLine(feature1), polygonToLine(feature2));
    if (doLinesIntersect.features.length > 0) {
        return true;
    }
    return false;
}
github Turfjs / turf / packages / turf-boolean-disjoint / index.ts View on Github external
function isLineInPoly(polygon: Polygon, lineString: LineString) {
    for (const coord of lineString.coordinates) {
        if (booleanPointInPolygon(coord, polygon)) {
            return true;
        }
    }
    const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));
    if (doLinesIntersect.features.length > 0) {
        return true;
    }
    return false;
}

@turf/polygon-to-line

turf polygon-to-line module

MIT
Latest version published 3 months ago

Package Health Score

96 / 100
Full package analysis