How to use @turf/center-of-mass - 5 common examples

To help you get started, we’ve selected a few @turf/center-of-mass 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 WorldBank-Transport / ram-backend / app / routes / scenarios--poi.js View on Github external
poi.features.forEach((feat, idx) => {
    let coords = feat.geometry.type !== 'Point'
      ? centerOfMass(feat).geometry.coordinates
      : feat.geometry.coordinates;

    // The response will be converted to a feature on the client.
    // This way we reduce the response size by a lot.
    response.push({
      // feature id.
      i: idx,
      // Coordinates.
      c: [parseInt(coords[0] * 1e5) / 1e5, parseInt(coords[1] * 1e5) / 1e5]
    });
  });
github WorldBank-Transport / ram-backend / app / services / project-setup / origins.js View on Github external
const origins = features.map(feat => {
    const coordinates = feat.geometry.type === 'Point'
      ? feat.geometry.coordinates
      : centerOfMass(feat).geometry.coordinates;

    // Will be flattened later.
    // The array is constructed in this way so we can match the index of the
    // results array and attribute the correct id.
    const featureIndicators = indicators.map(ind => ({
      key: ind.key,
      label: ind.label,
      value: parseInt(feat.properties[ind.key])
    }));
    originsIndicators.push(featureIndicators);

    return {
      project_id: projId,
      name: feat.properties[getPropInsensitive(feat.properties, 'name')] || 'N/A',
      coordinates: JSON.stringify(coordinates)
    };
github hackoregon / civic / packages / component-library / src / MapOverlay / MapOverlay.js View on Github external
? data.map(d =>
        centerOfMass(d.geometry, { properties: { ...d.properties } })
      )
github WorldBank-Transport / ram-backend / app / services / project-setup / poi.js View on Github external
const features = poisData[key].features.map(feat => {
          return {
            ...feat,
            properties: {
              ...feat.properties,
              ram_poi_type: key
            },
            geometry: feat.geometry.type !== 'Point'
              ? centerOfMass(feat).geometry
              : feat.geometry
          };
        });
        return acc.concat(features);
github hotosm / MapCampaigner / lambda_functions / process / make_pdf_grid / index.js View on Github external
async function main(event) {
    const response = await getS3File(event.campaign_uuid);
    const f = JSON.parse(response).features
    const options = {units:"meters"}
    const features = []
    for (let i = 0; i < f.length; i++) {
        const box = bbox(f[i]);
        const w = distance([box[0], box[1]],[box[2],box[1]],{units:"meters"})
        const h = distance([box[0], box[1]],[box[0],box[3]],{units:"meters"})
        const wDiff = 1000 - (w % 1000);
        const hDiff = 706 - (h % 706);
        const poly = bboxPolygon(box);
        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

@turf/center-of-mass

turf center-of-mass module

MIT
Latest version published 3 months ago

Package Health Score

98 / 100
Full package analysis

Popular @turf/center-of-mass functions