How to use the @turf/centroid.default function in @turf/centroid

To help you get started, we’ve selected a few @turf/centroid 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 PieceMaker / max-inscribed-circle / test / max-inscribed-circle.spec.js View on Github external
it('should return the centroid when no Voronoi vertices are inside polygon', function()
    {
        expect(maxCircle(this.inputTinyPolygon).geometry).to.eql(centroid(this.inputTinyPolygon).geometry);
    });
});
github mapstertech / mapbox-gl-draw-rotate-mode / index.js View on Github external
onMouseDown: function(state, e) {
      if(e.featureTarget) {
        if(this._ctx.api.get(e.featureTarget.properties.id)) {
          e.target['dragPan'].disable();
          state.selectedFeature = this._ctx.api.get(e.featureTarget.properties.id);
          state.originalCenter = centroid(e.featureTarget);
          state.originalFeature = e.featureTarget;
          emitter.emit('rotatestart');
        }
      }
      return state;
    },
github koopjs / winnow / src / sql.js View on Github external
sql.fn.geohash = function (geometry = {}, precision) {
  if (!geometry || !geometry.type || !geometry.coordinates) return
  precision = precision || 8
  if (geometry.type !== 'Point') geometry = centroid(geometry).geometry
  const pnt = geometry.coordinates
  return geohash.encode(pnt[1], pnt[0], precision)
}
github noncomputable / AgentMaps / src / agents.js View on Github external
function seqUnitAgentMaker(id){
	let index = this.agents.count();

	if (index > this.units.getLayers().length - 1) {
		throw new Error("seqUnitAgentMaker cannot accommodate more agents than there are units.");
	}
	
	let unit = this.units.getLayers()[index],
	unit_id = this.units.getLayerId(unit),
	center_point = centroid(unit.feature);
	center_point.properties.place = {"type": "unit", "id": unit_id},
	center_point.properties.layer_options = {radius: .5, color: "red", fillColor: "red"}; 
	
	return center_point;
}
github PieceMaker / max-inscribed-circle / max-inscribed-circle.js View on Github external
const vertices = {
        type: "FeatureCollection",
        features: []
    };
    //construct GeoJSON object of voronoi vertices
    for(let i = 0; i < diagram.vertices.length; i++) {
        vertices.features.push({
            type: "Feature",
            properties: {},
            geometry: {
                type: "Point",
                coordinates: [diagram.vertices[i].x, diagram.vertices[i].y]
            }
        })
    }
    vertices.features.push(centroid(polygon));
    //within requires a FeatureCollection for input polygons
    const polygonFeatureCollection = {
        type: "FeatureCollection",
        features: [polygon]
    };
    const ptsWithin = within(vertices, polygonFeatureCollection); //remove any vertices that are not inside the polygon
    if(ptsWithin.features.length === 0) {
        throw new NoPointsInShapeError('Neither the centroid nor any Voronoi vertices intersect the shape.');
    }
    const labelLocation = {
        coordinates: [0,0],
        maxDist: 0
    };
    const polygonBoundaries = {
        type: "FeatureCollection",
        features: []

@turf/centroid

turf centroid module

MIT
Latest version published 3 months ago

Package Health Score

98 / 100
Full package analysis

Popular @turf/centroid functions