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",
var fs = require('fs')
var helpers = require('@turf/helpers')
var async = require('async')
var geobuf = require('geobuf')
var jsts = require('jsts')
var _ = require('lodash')
var mkdirp = require('mkdirp')
var Pbf = require('pbf')
var featureCollection = helpers.featureCollection
var polygon = helpers.polygon
var geoJsonReader = new jsts.io.GeoJSONReader()
var geoJsonWriter = new jsts.io.GeoJSONWriter()
module.exports = function (tzGeojson, dataDir, targetIndexPercent, callback) {
console.log('indexing')
var data = {
timezones: [],
lookup: {}
}
/**
* iterate through geometry coordinates and change any coordinates along
* longitude 0 to longitude 0.00001
*/
function hackLongitude0Polygon (polygon) {
polygon.forEach(linearRing => {
module.exports = function(poly1, poly2) {
var geom1, geom2;
if(poly1.type === 'Feature') geom1 = poly1.geometry;
else geom1 = poly1;
if(poly2.type === 'Feature') geom2 = poly2.geometry;
else geom2 = poly2;
var reader = new jsts.io.GeoJSONReader();
var a = reader.read(JSON.stringify(geom1));
var b = reader.read(JSON.stringify(geom2));
var intersection = a.intersection(b);
var parser = new jsts.io.GeoJSONParser();
intersection = parser.write(intersection);
if(intersection.type === 'GeometryCollection' && intersection.geometries.length === 0) {
return undefined;
} else {
return {
type: 'Feature',
properties: {},
geometry: intersection
};
}
};
module.exports = function(poly1, poly2, done){
poly1 = correctRings(poly1)
poly2 = correctRings(poly2)
var reader = new jsts.io.GeoJSONReader()
var a = reader.read(JSON.stringify(poly1.geometry))
var b = reader.read(JSON.stringify(poly2.geometry))
var erased = a.difference(b);
var parser = new jsts.io.GeoJSONParser()
erased = parser.write(erased)
var newPoly = _.cloneDeep(poly1);
newPoly.geometry = erased
done(null, newPoly)
}
var bufferOp = function(feature, radius, done){
var reader = new jsts.io.GeoJSONReader()
var geom = reader.read(JSON.stringify(feature.geometry))
var buffered = geom.buffer(radius);
var parser = new jsts.io.GeoJSONParser()
buffered = parser.write(buffered)
if(buffered.type === 'MultiPolygon'){
buffered = {
type: 'Feature',
geometry: buffered,
properties: {}
}
buffered = t.featurecollection([buffered])
done(null, buffered)
}
else{
buffered = t.featurecollection([t.polygon(buffered.coordinates)])
done(null, buffered)
}
}
module.exports = function(poly1, poly2, done){
poly1 = correctRings(poly1)
poly2 = correctRings(poly2)
var reader = new jsts.io.GeoJSONReader()
var a = reader.read(JSON.stringify(poly1.geometry))
var b = reader.read(JSON.stringify(poly2.geometry))
var erased = a.difference(b);
var parser = new jsts.io.GeoJSONParser()
erased = parser.write(erased)
var newPoly = _.cloneDeep(poly1);
newPoly.geometry = erased
done(null, newPoly)
}
export function cleanFeatures(features) {
const writer = new jsts.io.GeoJSONWriter();
return features.map(({ id, geometry, properties }) => {
const geojsonGeometry = (geometry.isSimple() || geometry.isValid())
? writer.write(geometry)
: writer.write(geometry.buffer(0));
return ({
type: 'Feature',
geometry: geojsonGeometry,
...(id ? { id } : {}),
...(properties ? { properties } : {}),
});
});
}
module.exports = function(polys1, polys2, done){
var reader = new jsts.io.GeoJSONReader()
var a = reader.read(JSON.stringify(polys1.features[0].geometry))
var b = reader.read(JSON.stringify(polys2.features[0].geometry))
var intersection = a.intersection(b)
var parser = new jsts.io.GeoJSONParser()
done = done || function () {};
intersection = parser.write(intersection)
intersection = t.featurecollection([intersection])
done(null, intersection)
return intersection;
}