How to use jsts - 10 common examples

To help you get started, we’ve selected a few jsts 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 stamen / open-redistricting / js / components / DiffMap.jsx View on Github external
responses => {
				
				let reader = new jsts.io.GeoJSONReader(),
					p1 = reader.read(responses[0]),
					p2 = reader.read(responses[1]),
					unionP1,
					unionP2,
					diff,
					intersection,
					startTime = performance.now();

				console.info(`comparing ${ p1.features.length } previous districts against ${ p2.features.length } proposed districts...`);

				try {

					// TODO: this unioning seems necessary to perform JSTS operations between the two GeoJSON objects,
					// but causes boundaries between features to be erased. Find a better solution.
					unionP1 = p1.features.reduce((acc, f, i) => {
						if (i === 0) return f.geometry;
github evansiroky / timezone-boundary-builder / index.js View on Github external
zoneCfg = newZoneCfg

  // filter out unneccessary downloads
  var newOsmBoundarySources = {}
  Object.keys(zoneCfg).forEach((zoneName) => {
    zoneCfg[zoneName].forEach((op) => {
      if (op.source === 'overpass') {
        newOsmBoundarySources[op.id] = osmBoundarySources[op.id]
      }
    })
  })

  osmBoundarySources = newOsmBoundarySources
}

var geoJsonReader = new jsts.io.GeoJSONReader()
var geoJsonWriter = new jsts.io.GeoJSONWriter()
var precisionModel = new jsts.geom.PrecisionModel(1000000)
var precisionReducer = new jsts.precision.GeometryPrecisionReducer(precisionModel)
var distZones = {}
var minRequestGap = 4
var curRequestGap = 4

var safeMkdir = function (dirname, callback) {
  fs.mkdir(dirname, function (err) {
    if (err && err.code === 'EEXIST') {
      callback()
    } else {
      callback(err)
    }
  })
}
github GreenInfo-Network / caliparks.org / play / gather / gatherer_4sq_venues.js View on Github external
var fs = require("fs"),
    util = require("util");
var async = require("async"),
    connect = require("connect"),
    pg = require("pg"),
    request = require("request"),
    jsts = require("jsts");

var factory = new jsts.geom.GeometryFactory();
var reader = new jsts.io.WKTReader(factory);

var zerocount = 0,
    nonzerocount = 0,
    undefcount = 0,
    existscount = 0;

var startPostgresClient = function(callback) {
  // postgres
  var client = new pg.Client({
    user: "",
    user: "openspaces",
    //user: "ggnpc",
    password: "",
    database: "openspaces",
    //database: "ggnpc",
    //host: "localhost",
github EventKit / eventkit-cloud / eventkit_cloud / ui / static / ui / app / utils / mapUtils.js View on Github external
export function transformJSTSGeometry(jstsGeometry, fromSrs, toSrs) {
    // This all seems excessive, however jsts ol3Parser wasn't working with versions
    // "jsts": "~1.4.0" and "openlayers": "~3.19.1", worth revisting in the future.
    const writer = new GeoJSONWriter();
    const geojsonReader = new Reader();
    const ol3GeoJSON = new GeoJSON();
    const geom = (new GeoJSON())
        .readGeometry(writer.write(jstsGeometry)).transform(fromSrs, toSrs);
    return geojsonReader.read(ol3GeoJSON.writeGeometry(geom));
}
github skeate / Leaflet.buffer / src / leaflet.buffer.js View on Github external
this._replacePolyline = options.replacePolylines;
    this._separateBuffer = options.separateBuffer;
    this._bufferStyle = options.bufferStyle;

    if (!(this._featureGroup instanceof L.FeatureGroup)) {
      throw new Error('options.featureGroup must be a L.FeatureGroup');
    }

    this._unbufferedLayerProps = {};

    // Save the type so super can fire,
    // need to do this as cannot do this.TYPE :(
    this.type = L.EditToolbar.Buffer.TYPE;

    this.geoReader = new GeoJSONReader();
    this.geoWriter = new GeoJSONWriter();
  },
github EventKit / eventkit-cloud / eventkit_cloud / ui / static / ui / app / utils / mapUtils.js View on Github external
export function transformJSTSGeometry(jstsGeometry, fromSrs, toSrs) {
    // This all seems excessive, however jsts ol3Parser wasn't working with versions
    // "jsts": "~1.4.0" and "openlayers": "~3.19.1", worth revisting in the future.
    const writer = new GeoJSONWriter();
    const geojsonReader = new Reader();
    const ol3GeoJSON = new GeoJSON();
    const geom = (new GeoJSON())
        .readGeometry(writer.write(jstsGeometry)).transform(fromSrs, toSrs);
    return geojsonReader.read(ol3GeoJSON.writeGeometry(geom));
}
github EventKit / eventkit-cloud / eventkit_cloud / ui / static / ui / app / utils / mapUtils.js View on Github external
export function isGeoJSONValid(featureCollection) {
    // creates a jsts GeoJSONReader
    const parser = new Reader();
    for (let i = 0; i < featureCollection.features.length; i += 1) {
        // reads in geojson geometry and returns a jsts geometry
        const geom = parser.read(featureCollection.features[i].geometry);
        if (!isValidOp.isValid(geom)) {
            return false;
        }
    }
    return true;
}
github skeate / Leaflet.buffer / src / leaflet.buffer.js View on Github external
this._featureGroup = options.featureGroup;
    this._replacePolyline = options.replacePolylines;
    this._separateBuffer = options.separateBuffer;
    this._bufferStyle = options.bufferStyle;

    if (!(this._featureGroup instanceof L.FeatureGroup)) {
      throw new Error('options.featureGroup must be a L.FeatureGroup');
    }

    this._unbufferedLayerProps = {};

    // Save the type so super can fire,
    // need to do this as cannot do this.TYPE :(
    this.type = L.EditToolbar.Buffer.TYPE;

    this.geoReader = new GeoJSONReader();
    this.geoWriter = new GeoJSONWriter();
  },
github cswbrian / district-councils-dashboard / web / src / data / overlap.js View on Github external
const jsts_validate = function(geom) {
  if (geom instanceof jsts.geom.Polygon) {
    if (geom.isValid()) {
      geom.normalize() // validate does not pick up rings in the wrong order - this will fix that
      return geom // If the polygon is valid just return it
    }
    var polygonizer = new jsts.operation.polygonize.Polygonizer()
    jsts_addPolygon(geom, polygonizer)
    return jsts_toPolygonGeometry(polygonizer.getPolygons(), geom.getFactory())
  } else if (geom instanceof jsts.geom.MultiPolygon) {
    if (geom.isValid()) {
      geom.normalize() // validate does not pick up rings in the wrong order - this will fix that
      return geom // If the multipolygon is valid just return it
    }
    var polygonizer = new jsts.operation.polygonize.Polygonizer()

    for (var n = geom.getNumGeometries(); n > 0; n--) {
      jsts_addPolygon(geom.getGeometryN(n - 1), polygonizer)
github GreenInfo-Network / caliparks.org / play / gather / gatherer_4sq_venues.js View on Github external
var fs = require("fs"),
    util = require("util");
var async = require("async"),
    connect = require("connect"),
    pg = require("pg"),
    request = require("request"),
    jsts = require("jsts");

var factory = new jsts.geom.GeometryFactory();
var reader = new jsts.io.WKTReader(factory);

var zerocount = 0,
    nonzerocount = 0,
    undefcount = 0,
    existscount = 0;

var startPostgresClient = function(callback) {
  // postgres
  var client = new pg.Client({
    user: "",
    user: "openspaces",
    //user: "ggnpc",
    password: "",
    database: "openspaces",
    //database: "ggnpc",