How to use @turf/polygon-to-line - 7 common examples

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 ngageoint / geopackage-js / test / lib / features / user / testFeatureDao.js View on Github external
var distance = pointToLineDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'Polygon') {
          if (booleanPointInPolygon(centerPoint, geometry)) {
            if (closestDistance != 0) {
              closest = row;
              closestDistance = 0;
            }
          } else {
            var line = polygonToLine(geometry);
            var distance = pointToLineDistance(centerPoint, line);
            if (distance < closestDistance) {
              closest = row;
              closestDistance = distance;
            }
          }
        }
      }
      closest.values.name.should.be.equal('point');
      foundFeatures.should.be.deep.equal(['box1', 'box2', 'line', 'point']);
    });
github ngageoint / geopackage-js / test / lib / features / user / testFeatureDao.js View on Github external
var distance = pointToLineDistance(centerPoint, geometry);
          if (distance < closestDistance) {
            closest = row;
            closestDistance = distance;
          } else if (distance == closestDistance && closest.type != 'Point') {
            closest = row;
            closestDistance = distance;
          }
        } else if (geometry.type == 'Polygon') {
          if (booleanPointInPolygon(centerPoint, geometry)) {
            if (closestDistance != 0) {
              closest = row;
              closestDistance = 0;
            }
          } else {
            var line = polygonToLine(geometry);
            var distance = pointToLineDistance(centerPoint, line);
            if (distance < closestDistance) {
              closest = row;
              closestDistance = distance;
            }
          }
        }
      }
      closest.properties.Name.should.be.equal('Rio Grande');
    });
  });
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;
}
github ngageoint / geopackage-js / lib / tiles / features / index.js View on Github external
FeatureTiles.prototype.drawPolygon = function(path, geoJson, context, featureStyle) {
  context.save();
  context.beginPath();
  path(PolyToLine(geoJson).geometry);
  context.closePath();
  var fillPaint = this.getPolygonFillPaint(featureStyle);
  if (fillPaint !== undefined && fillPaint !== null) {
    context.fillStyle = fillPaint.getColorRGBA();
    context.fill();
  }
  var paint = this.getPolygonPaint(featureStyle);
  context.strokeStyle = paint.getColorRGBA();
  context.lineWidth = paint.getStrokeWidth();
  context.stroke();
  context.restore();
};
github Turfjs / turf / packages / turf-boolean-crosses / index.ts View on Github external
function doLineStringAndPolygonCross(lineString, polygon: Polygon) {
    const line: any = polygonToLine(polygon);
    const doLinesIntersect = lineIntersect(lineString, line);
    if (doLinesIntersect.features.length > 0) {
        return true;
    }
    return false;
}

@turf/polygon-to-line

turf polygon-to-line module

MIT
Latest version published 2 months ago

Package Health Score

96 / 100
Full package analysis