Beispiel #1
0
 const segments = coordinates.map(set => {
   const polySegment = Turf.multiLineString([
     translateFromOpenlayersCoordinates(set),
   ])
   return Turf.buffer(polySegment, bufferWidth, 'meters').geometry
     .coordinates
 })
Beispiel #2
0
  drawBorderedPolygon: function(rectangle) {
    if (!rectangle) {
      // handles case where model changes to empty vars and we don't want to draw anymore
      return
    }
    var lineWidth =
      DistanceUtils.getDistanceInMeters(
        this.model.get('lineWidth'),
        this.model.get('lineUnits')
      ) || 1

    var turfLine = Turf.lineString(
      translateFromOpenlayersCoordinates(rectangle.getCoordinates())
    )
    var bufferedLine = Turf.buffer(turfLine, lineWidth, 'meters')
    var geometryRepresentation = new ol.geom.MultiLineString(
      translateToOpenlayersCoordinates(bufferedLine.geometry.coordinates)
    )

    if (this.vectorLayer) {
      this.map.removeLayer(this.vectorLayer)
    }

    this.billboard = new ol.Feature({
      geometry: geometryRepresentation,
    })

    this.billboard.setId(this.model.cid)

    var color = this.model.get('color')

    var iconStyle = new ol.style.Style({
      stroke: new ol.style.Stroke({
        color: color ? color : '#914500',
        width: 3,
      }),
    })
    this.billboard.setStyle(iconStyle)

    var vectorSource = new ol.source.Vector({
      features: [this.billboard],
    })

    var vectorLayer = new ol.layer.Vector({
      source: vectorSource,
    })

    this.vectorLayer = vectorLayer
    this.map.addLayer(vectorLayer)
  },
Beispiel #3
0
  drawGeometry = model => {
    const json = model.toJSON()
    let linePoints = json.line
    const lineWidth =
      DistanceUtils.getDistanceInMeters(
        json.lineWidth,
        model.get('lineUnits')
      ) || 1
    if (!linePoints) {
      return
    }

    linePoints.forEach(point => {
      point[0] = DistanceUtils.coordinateRound(point[0])
      point[1] = DistanceUtils.coordinateRound(point[1])
    })

    const setArr = _.uniq(linePoints)
    if (setArr.length < 2) {
      return
    }

    const turfLine = Turf.lineString(setArr)
    let bufferedLine = turfLine
    this.cameraMagnitude = this.map.camera.getMagnitude()
    if (lineWidth > 100 || this.cameraMagnitude < CAMERA_MAGNITUDE_THRESHOLD) {
      bufferedLine = Turf.buffer(turfLine, Math.max(lineWidth, 1), 'meters')
    }

    // first destroy old one
    if (this.primitive && !this.primitive.isDestroyed()) {
      this.map.scene.primitives.remove(this.primitive)
    }

    this.primitive = new Cesium.PolylineCollection()
    this.primitive.add(
      this.constructLinePrimitive(bufferedLine.geometry.coordinates)
    )

    this.map.scene.primitives.add(this.primitive)
  }
function matchesLINESTRING(value, filter) {
    var pointText = filter.value.value.substring(11);
    pointText = pointText.substring(0, pointText.length - 1);
    var lineWidth = filter.distance || 0;
    if (lineWidth <= 0) {
        return false;
    }
    var line = pointText.split(',').map(function (coordinate) {
        return coordinate.split(' ').map(function (value) {
            return Number(value);
        });
    });
    var turfLine = Turf.lineString(line);
    var bufferedLine = Turf.buffer(turfLine, lineWidth, 'meters');
    var polygonToCheck = new Terraformer.Polygon({
        type: 'Polygon',
        coordinates: bufferedLine.geometry.coordinates
    });
    if (intersects(polygonToCheck, value)) {
        return true;
    }
    return false;
}
Beispiel #5
0
"use strict";
const concaveman = require("concaveman");
const helpers = require("geojson-helpers");
const turf = require("@turf/turf");
const data = './halifax-buildings.json';
const geojson = require(data);
const points = [];
geojson.features.map(feature => {
    turf.explode(feature).features.map(point => {
        points.push(point.geometry.coordinates);
    });
});
const extent = turf.polygon([concaveman(points)]);
const buffer = turf.buffer(extent, 500, 'meters');
const simple = turf.simplify(buffer, 0.001, false);
helpers.writeFileSync('./extent.geojson', turf.featureCollection([extent]));
helpers.writeFileSync('./buffer.geojson', turf.featureCollection([buffer]));
helpers.writeFileSync('./simple.geojson', turf.featureCollection([simple]));
Beispiel #6
0
"use strict";
const turf = require("@turf/turf");
const path = require("path");
const fs = require("fs");
const features = require(path.join(__dirname, 'CSD-schools.json'));
const buffer = turf.buffer(features, 500, 'meters');
fs.writeFileSync(path.join(__dirname, 'buffer.json'), JSON.stringify(buffer, null, 4));
Beispiel #7
0
  .option('-o, --output <path>', 'Path to output files to')
  .option('-d, --distance <value>', 'Distance between grid points', parseFloat)
  .option('-b, --buffer <value>', 'Buffer to add around bounding box', parseFloat)
  .option('-u, --unit <meters|kilometers|miles>', 'Unit of measure for distance and buffer')
  .parse(process.argv)

const INPUT = program.input || './data/singapore.geo.json'
const OUTPUT = program.output || './output'
const DISTANCE = +program.distance || 0.2
const BUFFER = +program.buffer || 1
const UNIT = program.unit || 'kilometers'

// create bounding box
const geojson = require(path.resolve(__dirname, INPUT))
const bbox = turf.bbox(
  turf.buffer(geojson, BUFFER, UNIT)
)

// how to get width and height? lol
const width = Math.ceil(turf.distance(
  [bbox[0], bbox[1]],
  [bbox[2], bbox[1]],
  UNIT
) / DISTANCE)
const height = Math.ceil(turf.distance(
  [bbox[0], bbox[1]],
  [bbox[0], bbox[3]],
  UNIT
) / DISTANCE)

// generate point pointGrid & point set