How to use the @turf/helpers.featureCollection 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 Turfjs / turf / packages / turf-meta / types.ts View on Github external
segmentEach,
    lineReduce,
    lineEach
} from './'

// Fixtures
const pt = helpers.point([0, 0])
const line = helpers.lineString([[0, 0], [1, 1]])
const poly = helpers.polygon([[[0, 0], [1, 1], [0, 1], [0, 0]]])
const multiPoly = helpers.multiPolygon([[[[0, 0], [1, 1], [0, 1], [0, 0]]]])
const multiLine = helpers.multiLineString([[[0, 0], [1, 1], [0, 1], [0, 0]], [[2, 2], [3, 3]]])
const geomCollection = helpers.geometryCollection([pt.geometry, line.geometry])
const features = helpers.featureCollection([pt, line])

const customPoint = point([10, 20], {foo: 'abc', bar: 123})
const customPoints = featureCollection([customPoint])
const customLineString = lineString([[0, 0], [10, 20]], {foo: 'abc', bar: 123})
const customLineStrings = featureCollection([customLineString])

/**
 * meta.coordEach
 */
const coordEachValue: void = meta.coordEach(pt, coords => coords)
coordEach(pt, (coords, index) => coords)
meta.coordEach(pt, (coords, index) => coords)
meta.coordEach(pt.geometry, coords => { const equal: number[] = coords })
meta.coordEach(line, coords => { const equal: number[] = coords })
meta.coordEach(poly, coords => { const equal: number[] = coords })
meta.coordEach(multiPoly, coords => { const equal: number[] = coords })
meta.coordEach(geomCollection, coords => coords)

/**
github terrestris / ol-util / src / GeometryUtil / GeometryUtil.js View on Github external
geometries.forEach(geometry => {
      // Convert the polygon to turf.js/GeoJSON geometry while
      // reprojecting them to the internal turf.js projection 'EPSG:4326'.
      const turfPolygon = geoJsonFormat.writeGeometryObject(geometry);
      const turfPolygonCoordinates = turfPolygon.coordinates;
      // outer lines of the given polygon
      const outer = lineString(turfPolygonCoordinates[0]);
      // polygonized outer polygon
      const outerPolygon = lineToPolygon(outer);
      // holes in the polygon
      const inners = [];
      turfPolygonCoordinates.slice(1, turfPolygonCoordinates.length).forEach(function (coord) {
        inners.push(lineString(coord));
      });
      // Polygonize the holes in the polygon
      const innerPolygon = polygonize(featureCollection(inners));
      // make a lineString from the spliting line and the outer of the polygon
      let unionGeom = union(outer, turfLine);
      // Polygonize the combined lines.
      const polygonizedUnionGeom = polygonize(unionGeom);
      // Array of the split polygons within the geometry
      const splitedPolygons = [];
      // Iterate over each feature in the combined feature and remove sections that are outside the initial polygon and
      // remove the parts from the cutted polygons that are in polygon holes.
      featureEach(polygonizedUnionGeom, cuttedSection => {
        // checks to see if segment is in polygon
        const segmentInPolygon = intersect(cuttedSection, outerPolygon);
        if (segmentInPolygon && segmentInPolygon.geometry.type === 'Polygon') {
          let polygonWithoutHoles = [];
          if (innerPolygon.features.length > 0) {
            // iterates over all the holes and removes their intersection with the cutted polygon
            innerPolygon.features.forEach(holes => {
github simonepri / geojson-geometries-lookup / test / point-in-point.js View on Github external
test('GeoJsonGeometriesLookup.getContainers() searches correctly.', t => {
  const geojson = featureCollection([
    point([4, 6], {id: 1}),
    point([4, 1], {id: 2}),
    point([9, 6], {id: 3})
  ]);

  const glookup = new M(geojson);

  const testCases = [
    point([1, 5]),
    point([6, 3]),
    point([4, 6], {id: 1}),
    point([5.5, 3.5]),
    point([4, 1], {id: 2}),
    point([9, 6], {id: 3}),
    point([9.7, 6.7]),
    point([10, 11]),
github hotosm / MapCampaigner / lambda_functions / process / make_pdf_grid / index.js View on Github external
const c = centerOfMass(poly);
        const maxY = destination(c,(50 + h + hDiff)/2, 0, options).geometry.coordinates[1];
        const minY = destination(c,(50 +h + hDiff)/2, 180,options).geometry.coordinates[1];
        const maxX = destination(c,(50 + w + wDiff)/2, 90,options).geometry.coordinates[0];
        const minX = destination(c,(50 + w + wDiff)/2, -90,options).geometry.coordinates[0];
        const grid = rectangleGrid([minX, minY, maxX, maxY], 1000, 706, {units:"meters"});
        for (let j=0; j
github kepta / idly / packages / idly-worker / src / operations / getMoveNode / worker.ts View on Github external
let qState = state.osmState;
    if (param.id) {
      qState = stateAddModified(qState, [
        ...nodeMove(qState, param.id, {
          lat: param.loc.lat,
          lon: param.loc.lng,
        }),
      ]);
    }

    const features = entityToGeoJson(stateGetVisibles(qState, param.quadkeys));

    console.timeEnd('workerGetMoveNode');

    return {
      response: featureCollection(features),
      state: {
        ...state,
        osmState: qState,
      },
    };
  };
}
github sharedstreets / sharedstreets-js / src / commands / match.ts View on Github external
if(bestMatch && bestMatch.matchedPath) {      
        bestMatch.matchedPath.properties['segments'] =  bestMatch.segments;
        bestMatch.matchedPath.properties['score'] = bestMatch.score;
        bestMatch.matchedPath.properties['matchType'] = bestMatch.matchType;
        mapOgProperties(line.properties, bestMatch.matchedPath.properties);
        matchedLines.push(bestMatch.matchedPath);
    }
    else {
      unmatchedLines.push(line);
    }
  }

  if(matchedLines && matchedLines.length) {
    console.log(chalk.bold.keyword('blue')('  ✏️  Writing ' + matchedLines.length + ' matched lines: ' + outFile + ".matched.geojson"));
    var matchedFeatureCollection:turfHelpers.FeatureCollection = turfHelpers.featureCollection(matchedLines);
    var matchedJsonOut = JSON.stringify(matchedFeatureCollection);
    writeFileSync(outFile + ".matched.geojson", matchedJsonOut);
  }

  if(unmatchedLines && unmatchedLines.length ) {
    console.log(chalk.bold.keyword('blue')('  ✏️  Writing ' + unmatchedLines.length + ' unmatched lines: ' + outFile + ".unmatched.geojson"));
    var unmatchedFeatureCollection:turfHelpers.FeatureCollection = turfHelpers.featureCollection(unmatchedLines);
    var unmatchedJsonOut = JSON.stringify(unmatchedFeatureCollection);
    writeFileSync(outFile + ".unmatched.geojson", unmatchedJsonOut);
  }

  if(cleanedlines.invalid && cleanedlines.invalid.length ) {
    console.log(chalk.bold.keyword('blue')('  ✏️  Writing ' + cleanedlines.invalid + ' in lines: ' + outFile + ".invalid.geojson"));
    var invalidFeatureCollection:turfHelpers.FeatureCollection = turfHelpers.featureCollection(cleanedlines.invalid);
    var invalidJsonOut = JSON.stringify(invalidFeatureCollection);
    writeFileSync(outFile + ".unmatched.geojson", invalidJsonOut);
github uber / nebula.gl / examples / website / examples.js View on Github external
response.json().then(json => {
          this.setState({
            data: featureCollection(json.map(({ coordinates }) => point(coordinates)))
          });
        });
      });
github Turfjs / turf / packages / turf-rectangle-grid / index.js View on Github external
[currentX + cellWidthDeg, currentY],
                    [currentX, currentY],
                ]], options.properties);
            if (options.mask) {
                if (boolean_intersects_1.default(options.mask, cellPoly)) {
                    results.push(cellPoly);
                }
            }
            else {
                results.push(cellPoly);
            }
            currentY += cellHeightDeg;
        }
        currentX += cellWidthDeg;
    }
    return helpers_1.featureCollection(results);
}
exports.default = rectangleGrid;
github Turfjs / turf / packages / turf-concave / index.ts View on Github external
function removeDuplicates(points: FeatureCollection): FeatureCollection {
    const cleaned: Array> = [];
    const existing: {[key: string]: boolean} = {};

    featureEach(points, (pt) => {
        if (!pt.geometry) { return; }
        const key = pt.geometry.coordinates.join("-");
        if (!existing.hasOwnProperty(key)) {
            cleaned.push(pt);
            existing[key] = true;
        }
    });
    return featureCollection(cleaned);
}
github osmlab / to-fix / src / components / task / index.js View on Github external
getBoundingBox(geojson) {
    const [ minX, minY, maxX, maxY ] = turfBbox(geojson);
    const padX = Math.max((maxX - minX) / 5, 0.0001);
    const padY = Math.max((maxY - minY) / 5, 0.0001);
    const bboxWithPadding = [
      minX - padX,
      minY - padY,
      maxX + padX,
      maxY + padY,
    ];
    const bboxPolygon = turfBboxPolygon(bboxWithPadding);
    return featureCollection([bboxPolygon]);
  }