How to use circle-to-polygon - 4 common examples

To help you get started, we’ve selected a few circle-to-polygon 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 openmobilityfoundation / mds-core / packages / mds-utils / utils.ts View on Github external
function pointInShape(
  pt: [number, number] | { lat: number; lng: number },
  shape: Geometry | FeatureCollection
): boolean {
  const point: [number, number] = Array.isArray(pt) ? pt : [pt.lng, pt.lat]
  console.log('pointinshape')
  console.log(point)
  console.log(shape)
  console.log('')
  if (shape.type === 'Point') {
    if (pointInPolygon(point, circleToPolygon(shape.coordinates, RADIUS, NUMBER_OF_EDGES))) {
      return true
    }
    return false
  }
  if (shape.type === 'MultiPolygon') {
    return pointInMultiPolygon(point, shape)
  }
  if (shape.type === 'Polygon') {
    return pointInPolygon(point, shape)
  }
  if (shape.type === 'FeatureCollection') {
    return pointInFeatureCollection(point, shape)
  }
  return pointInGeometry(point, shape)
}
github openmobilityfoundation / mds-core / packages / mds-utils / utils.ts View on Github external
function makePointInShape(shape: Geometry): { lat: number; lng: number } {
  if (!shape) {
    throw new Error('no shape')
  }

  const shapeToCreate = shape.type === 'Point' ? circleToPolygon(shape.coordinates, RADIUS, NUMBER_OF_EDGES) : shape

  const bbox = calcBBox(shapeToCreate)
  let tries = 0
  while (tries < 1000) {
    const pt: [number, number] = [rangeRandom(bbox.lngMin, bbox.lngMax), rangeRandom(bbox.latMin, bbox.latMax)]
    console.log('make point in shape: ***')
    console.log('is pointInShape?', pointInShape(pt, shape))
    console.log(pt, shape)
    console.log('*******')
    if (pointInShape(pt, shape)) {
      return {
        lng: pt[0],
        lat: pt[1]
      }
    }
    tries += 1
github lianetoolkit / liane-toolkit / imports / ui / components / mapLayers / AudienceLayer.jsx View on Github external
audience.geolocations.forEach(geolocation => {
      if (geolocation.geojson) {
        geojson.features.push({
          ...geolocation.geojson,
          properties: {
            _id: geolocation._id
          }
        });
      } else if (geolocation.center) {
        const geometry = circleToPolygon(
          [geolocation.center.center[1], geolocation.center.center[0]],
          geolocation.center.radius * 1000,
          32
        );
        geojson.features.push({
          type: "Feature",
          properties: {
            _id: geolocation._id,
            radius: geolocation.center.radius
          },
          geometry
        });
      }
    });
    return geojson;
github openmobilityfoundation / mds-core / packages / mds-utils / utils.ts View on Github external
function pointInGeometry(pt: [number, number], shape: Geometry): boolean {
  if (shape.type === 'MultiPolygon') {
    return pointInMultiPolygon(pt, shape)
  }
  if (shape.type === 'Polygon') {
    return pointInPolygon(pt, shape)
  }
  if (shape.type === 'Point') {
    if (pointInPolygon(pt, circleToPolygon(shape.coordinates, RADIUS, NUMBER_OF_EDGES))) {
      return true
    }
    return false
  }
  throw new Error(`cannot check point in shape for type ${shape.type}`)
}

circle-to-polygon

Receives a Coordinate, a Radius and a Number of edges and aproximates a circle by creating a polygon that fills its area

ISC
Latest version published 4 years ago

Package Health Score

48 / 100
Full package analysis

Popular circle-to-polygon functions