How to use @turf/clean-coords - 6 common examples

To help you get started, we’ve selected a few @turf/clean-coords 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-shortest-path / index.js View on Github external
path.push(endCoord);
    // ---------------------------------------


    // astar-andrea ------------------------
    // var result = aStar(matrix, [closestToStart.x, closestToStart.y], [closestToEnd.x, closestToEnd.y], 'DiagonalFree');
    // var path = [start.geometry.coordinates];
    // result.forEach(function (coord) {
    //     var coords = pointMatrix[coord[1]][coord[0]].split('|');
    //     path.push([+coords[0], +coords[1]]); // make sure coords are numbers
    // });
    // path.push(end.geometry.coordinates);
    // ---------------------------------------


    return cleanCoords(lineString(path));
}
github Turfjs / turf / packages / turf-simplify / index.js View on Github external
function simplifyGeom(geometry, tolerance, highQuality) {
    var type = geometry.type;

    // "unsimplyfiable" geometry types
    if (type === 'Point' || type === 'MultiPoint') return geometry;

    // Remove any extra coordinates
    cleanCoords(geometry, true);

    var coordinates = geometry.coordinates;
    switch (type) {
    case 'LineString':
        geometry['coordinates'] = simplifyLine(coordinates, tolerance, highQuality);
        break;
    case 'MultiLineString':
        geometry['coordinates'] = coordinates.map(function (lines) {
            return simplifyLine(lines, tolerance, highQuality);
        });
        break;
    case 'Polygon':
        geometry['coordinates'] = simplifyPolygon(coordinates, tolerance, highQuality);
        break;
    case 'MultiPolygon':
        geometry['coordinates'] = coordinates.map(function (rings) {
github Turfjs / turf / packages / turf-boolean-parallel / index.ts View on Github external
function booleanParallel(line1: Feature | LineString, line2: Feature | LineString): boolean {
    // validation
    if (!line1) throw new Error('line1 is required');
    if (!line2) throw new Error('line2 is required');
    var type1 = getType(line1, 'line1');
    if (type1 !== 'LineString') throw new Error('line1 must be a LineString');
    var type2 = getType(line2, 'line2');
    if (type2 !== 'LineString') throw new Error('line2 must be a LineString');

    var segments1 = lineSegment(cleanCoords(line1)).features;
    var segments2 = lineSegment(cleanCoords(line2)).features;

    for (var i = 0; i < segments1.length; i++) {
        var segment1 = segments1[i].geometry.coordinates;
        if (!segments2[i]) break;
        var segment2 = segments2[i].geometry.coordinates;
        if (!isParallel(segment1, segment2)) return false;
    }
    return true;
}
github Turfjs / turf / packages / turf-boolean-parallel / index.ts View on Github external
function booleanParallel(line1: Feature | LineString, line2: Feature | LineString): boolean {
    // validation
    if (!line1) throw new Error('line1 is required');
    if (!line2) throw new Error('line2 is required');
    var type1 = getType(line1, 'line1');
    if (type1 !== 'LineString') throw new Error('line1 must be a LineString');
    var type2 = getType(line2, 'line2');
    if (type2 !== 'LineString') throw new Error('line2 must be a LineString');

    var segments1 = lineSegment(cleanCoords(line1)).features;
    var segments2 = lineSegment(cleanCoords(line2)).features;

    for (var i = 0; i < segments1.length; i++) {
        var segment1 = segments1[i].geometry.coordinates;
        if (!segments2[i]) break;
        var segment2 = segments2[i].geometry.coordinates;
        if (!isParallel(segment1, segment2)) return false;
    }
    return true;
}
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));
}
github antvis / L7 / src / source / geojsonSource.js View on Github external
turfMeta.flattenEach(data, (currentFeature, featureIndex) => {
      const coord = getCoords(cleanCoords(currentFeature));
      this.geoData.push(this._coordProject(coord));
      currentFeature.properties._id = featureIndex + 1;
      this.propertiesData.push(currentFeature.properties);
    });
  }

@turf/clean-coords

turf clean-coords module

MIT
Latest version published 4 months ago

Package Health Score

94 / 100
Full package analysis

Popular @turf/clean-coords functions