Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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)
}
})
}
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",
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));
}
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();
},
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));
}
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;
}
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();
},
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)
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",