How to use the @turf/invariant.getGeom function in @turf/invariant

To help you get started, we’ve selected a few @turf/invariant 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 Turfjs / turf / packages / turf-intersect / index.ts View on Github external
if (intersection === null || intersection.length === 0) { return null; }
      if (intersection.length === 1) {
          const start = intersection[0][0][0];
          const end = intersection[0][0][intersection[0][0].length - 1];
          if (start[0] === end[0] && start[1] === end[1]) { return polygon(intersection[0], options.properties); }
          return null;
      }
      return multiPolygon(intersection, options.properties);

    } else if (geom1.type === "MultiPolygon") {
      let resultCoords: any[] = [];

      // iterate through the polygon and run intersect with each part, adding to the resultCoords.
      for (const coords of geom1.coordinates) {
        const subGeom = getGeom(polygon(coords));
        const subIntersection = intersect(subGeom, geom2);

        if (subIntersection) {
          const subIntGeom = getGeom(subIntersection);

          if (subIntGeom.type === "Polygon") { resultCoords.push(subIntGeom.coordinates);
          } else if (subIntGeom.type === "MultiPolygon") { resultCoords = resultCoords.concat(subIntGeom.coordinates);
          } else { throw new Error("intersection is invalid"); }
        }
      }

      // Make a polygon with the result
      if (resultCoords.length === 0) { return null; }
      if (resultCoords.length === 1) { return polygon(resultCoords[0], options.properties);
      } else { return multiPolygon(resultCoords, options.properties); }
github Turfjs / turf / packages / turf-boolean-overlap / index.ts View on Github external
export default function booleanOverlap(
    feature1: Feature | Geometry,
    feature2: Feature | Geometry,
): boolean {
    const geom1 = getGeom(feature1);
    const geom2 = getGeom(feature2);
    const type1 = geom1.type;
    const type2 = geom2.type;
    if (type1 !== type2) throw new Error('features must be of the same type');
    if (type1 === 'Point') throw new Error('Point geometry not supported');

    // features must be not equal
    const equality = new GeojsonEquality({precision: 6});
    if (equality.compare(feature1, feature2)) return false;

    let overlap = 0;

    switch (type1) {
    case 'MultiPoint':
        const coords1 = coordAll(feature1);
        const coords2 = coordAll(feature2);
github Turfjs / turf / packages / turf-difference / index.js View on Github external
function difference(polygon1, polygon2) {
    var geom1 = getGeom(polygon1);
    var geom2 = getGeom(polygon2);
    var properties = polygon1.properties || {};

    // Issue #721 - JSTS/Martinez can't handle empty polygons
    geom1 = removeEmptyPolygon(geom1);
    geom2 = removeEmptyPolygon(geom2);
    if (!geom1) return null;
    if (!geom2) return feature(geom1, properties);

    var differenced = martinez.diff(geom1.coordinates, geom2.coordinates);
    if (differenced.length === 0) return null;
    if (differenced.length === 1) return polygon(differenced[0], properties);
    else return multiPolygon(differenced, properties);
}
github Turfjs / turf / packages / turf-boolean-contains / index.ts View on Github external
export default function booleanContains(feature1: Feature | Geometry, feature2: Feature | Geometry) {
    const geom1 = getGeom(feature1);
    const geom2 = getGeom(feature2);
    const type1 = geom1.type;
    const type2 = geom2.type;
    const coords1 = geom1.coordinates;
    const coords2 = geom2.coordinates;

    switch (type1) {
    case "Point":
        switch (type2) {
        case "Point":
            return compareCoords(coords1, coords2);
        default:
            throw new Error("feature2 " + type2 + " geometry not supported");
        }
    case "MultiPoint":
        switch (type2) {
github Turfjs / turf / packages / turf-intersect / index.ts View on Github external
export default function intersect<p>(
    poly1: Feature</p>
github Turfjs / turf / packages / turf-boolean-equal / index.ts View on Github external
function booleanEqual(feature1: Feature | Geometry, feature2: Feature | Geometry): boolean {
    const type1 = getGeom(feature1).type;
    const type2 = getGeom(feature2).type;
    if (type1 !== type2) return false;

    const equality = new GeojsonEquality({precision: 6});
    return equality.compare(cleanCoords(feature1), cleanCoords(feature2));
}

@turf/invariant

turf invariant module

MIT
Latest version published 1 month ago

Package Health Score

98 / 100
Full package analysis