@dra2020/baseclient 1.0.47 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baseclient.js +80 -46
- package/dist/baseclient.js.map +1 -1
- package/dist/poly/topo.d.ts +1 -0
- package/lib/poly/polylabel.ts +66 -39
- package/lib/poly/topo.ts +12 -9
- package/package.json +1 -1
package/dist/baseclient.js
CHANGED
|
@@ -6874,16 +6874,68 @@ function polyDistance(poly, x, y) {
|
|
|
6874
6874
|
let pp = P.polyNormalize(poly);
|
|
6875
6875
|
if (pp == null)
|
|
6876
6876
|
return 0;
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6877
|
+
// First find if it is contained in one of the outer polygons, or outside all outer polygons
|
|
6878
|
+
let iContaining = -1;
|
|
6879
|
+
let maxOutside = -Infinity;
|
|
6880
|
+
let minInside = Infinity;
|
|
6881
|
+
let noholes = true;
|
|
6882
|
+
PP.polyPackEachRing(pp, (b, iPoly, iRing, iOffset, nPoints) => {
|
|
6883
|
+
// If we have determined we are inside this polygon, keep track of whether it has holes
|
|
6884
|
+
if (iContaining == iPoly && iRing > 0)
|
|
6885
|
+
noholes = false;
|
|
6886
|
+
// Don't process rings
|
|
6887
|
+
if (iRing > 0)
|
|
6888
|
+
return;
|
|
6889
|
+
// OK, get distance
|
|
6890
|
+
let forEachPointPair = (iter) => {
|
|
6891
|
+
PP.polyPackEachRing(pp, (b, iInteriorPoly, iRing, iOffset, nPoints) => {
|
|
6892
|
+
if (iRing || iInteriorPoly != iPoly)
|
|
6893
|
+
return;
|
|
6894
|
+
let iFirst = iOffset;
|
|
6895
|
+
let iLast = iOffset + nPoints * 2;
|
|
6896
|
+
let iSecond = iLast - 2;
|
|
6897
|
+
for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
|
|
6898
|
+
iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
|
|
6899
|
+
});
|
|
6900
|
+
};
|
|
6901
|
+
let dist = pointToPolygonDist(x, y, forEachPointPair);
|
|
6902
|
+
// If inside, is it closest inside (deal with multipolygons that self-contain - think filled donut)
|
|
6903
|
+
if (dist > 0 && dist < minInside) {
|
|
6904
|
+
iContaining = iPoly;
|
|
6905
|
+
minInside = dist;
|
|
6906
|
+
noholes = true;
|
|
6907
|
+
}
|
|
6908
|
+
else if (dist < 0)
|
|
6909
|
+
maxOutside = Math.max(maxOutside, dist);
|
|
6910
|
+
});
|
|
6911
|
+
if (iContaining < 0)
|
|
6912
|
+
return maxOutside;
|
|
6913
|
+
if (noholes)
|
|
6914
|
+
return minInside;
|
|
6915
|
+
// OK, now need to worry about holes in the polygon it is contained in
|
|
6916
|
+
PP.polyPackEachRing(pp, (b, iPoly, iRing, iOffset, nPoints) => {
|
|
6917
|
+
// Only want to look at the holes for the containing polygon
|
|
6918
|
+
if (iPoly != iContaining || iRing == 0)
|
|
6919
|
+
return;
|
|
6920
|
+
// Compute distance to those holes
|
|
6921
|
+
let forEachPointPair = (iter) => {
|
|
6922
|
+
PP.polyPackEachRing(pp, (b, iInteriorPoly, iRing, iOffset, nPoints) => {
|
|
6923
|
+
if (iInteriorPoly != iContaining || iRing == 0)
|
|
6924
|
+
return;
|
|
6925
|
+
let iFirst = iOffset;
|
|
6926
|
+
let iLast = iOffset + nPoints * 2;
|
|
6927
|
+
let iSecond = iLast - 2;
|
|
6928
|
+
for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
|
|
6929
|
+
iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
|
|
6930
|
+
});
|
|
6931
|
+
};
|
|
6932
|
+
// Negate distance since dealing with holes
|
|
6933
|
+
let dist = -pointToPolygonDist(x, y, forEachPointPair);
|
|
6934
|
+
// We take the min to either get a negative value (inside hole) or a smaller positive value
|
|
6935
|
+
// (outside hole but close to hole boundary).
|
|
6936
|
+
minInside = Math.min(minInside, dist);
|
|
6937
|
+
});
|
|
6938
|
+
return minInside;
|
|
6887
6939
|
}
|
|
6888
6940
|
exports.polyDistance = polyDistance;
|
|
6889
6941
|
//
|
|
@@ -6922,7 +6974,7 @@ function polyLabel(poly, precision, debug) {
|
|
|
6922
6974
|
let iLast = iOffset + nPoints * 2;
|
|
6923
6975
|
let iSecond = iLast - 2;
|
|
6924
6976
|
for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
|
|
6925
|
-
iter(
|
|
6977
|
+
iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
|
|
6926
6978
|
});
|
|
6927
6979
|
};
|
|
6928
6980
|
// find the bounding box of the outer ring
|
|
@@ -6996,34 +7048,13 @@ class Cell {
|
|
|
6996
7048
|
}
|
|
6997
7049
|
// signed distance from point to polygon outline (negative if point is outside)
|
|
6998
7050
|
function pointToPolygonDist(x, y, forEachPointPair) {
|
|
6999
|
-
let iPolyLast = -1;
|
|
7000
|
-
let iRingLast = -1;
|
|
7001
7051
|
let inside = false;
|
|
7002
|
-
let thisInside = false;
|
|
7003
|
-
let useInside = false;
|
|
7004
|
-
let isHole = false;
|
|
7005
7052
|
let minDistSq = Infinity;
|
|
7006
|
-
forEachPointPair((
|
|
7007
|
-
if (iPoly != iPolyLast || iRing != iRingLast) {
|
|
7008
|
-
if (useInside)
|
|
7009
|
-
inside = isHole ? !thisInside : thisInside;
|
|
7010
|
-
iPolyLast = iPoly;
|
|
7011
|
-
iRingLast = iRing;
|
|
7012
|
-
thisInside = false;
|
|
7013
|
-
useInside = false;
|
|
7014
|
-
isHole = false;
|
|
7015
|
-
}
|
|
7053
|
+
forEachPointPair((ax, ay, bx, by) => {
|
|
7016
7054
|
if ((ay > y !== by > y) && (x < (bx - ax) * (y - ay) / (by - ay) + ax))
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
if (thisDistSq < minDistSq) {
|
|
7020
|
-
minDistSq = thisDistSq;
|
|
7021
|
-
useInside = true;
|
|
7022
|
-
isHole = iRing != 0;
|
|
7023
|
-
}
|
|
7055
|
+
inside = !inside;
|
|
7056
|
+
minDistSq = Math.min(minDistSq, getSegDistSq(x, y, ax, ay, bx, by));
|
|
7024
7057
|
});
|
|
7025
|
-
if (useInside)
|
|
7026
|
-
inside = isHole ? !thisInside : thisInside;
|
|
7027
7058
|
return (inside ? 1 : -1) * Math.sqrt(minDistSq);
|
|
7028
7059
|
}
|
|
7029
7060
|
// get polygon centroid
|
|
@@ -7033,7 +7064,7 @@ function getCentroidCell(forEachPointPair) {
|
|
|
7033
7064
|
let y = 0;
|
|
7034
7065
|
let fx;
|
|
7035
7066
|
let fy;
|
|
7036
|
-
forEachPointPair((
|
|
7067
|
+
forEachPointPair((ax, ay, bx, by) => {
|
|
7037
7068
|
if (fx === undefined)
|
|
7038
7069
|
fx = ax, fy = ay;
|
|
7039
7070
|
let f = ax * by - bx * ay;
|
|
@@ -8350,7 +8381,6 @@ const P = __importStar(__webpack_require__(/*! ./poly */ "./lib/poly/poly.ts"));
|
|
|
8350
8381
|
const PP = __importStar(__webpack_require__(/*! ./polypack */ "./lib/poly/polypack.ts"));
|
|
8351
8382
|
const PL = __importStar(__webpack_require__(/*! ./polylabel */ "./lib/poly/polylabel.ts"));
|
|
8352
8383
|
const shamos_1 = __webpack_require__(/*! ./shamos */ "./lib/poly/shamos.ts");
|
|
8353
|
-
const pointinpoly_1 = __webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts");
|
|
8354
8384
|
function getGEOID(f) {
|
|
8355
8385
|
if (f.features && f.features.length)
|
|
8356
8386
|
f = f.features[0];
|
|
@@ -8521,8 +8551,9 @@ function intpt(f) {
|
|
|
8521
8551
|
return { x: x, y: y };
|
|
8522
8552
|
}
|
|
8523
8553
|
const DefaultSimplifyOptions = { minArea: 500 };
|
|
8524
|
-
function log(s) {
|
|
8525
|
-
|
|
8554
|
+
function log(emitlog, s) {
|
|
8555
|
+
if (emitlog)
|
|
8556
|
+
console.log(s);
|
|
8526
8557
|
}
|
|
8527
8558
|
//
|
|
8528
8559
|
// topoSimplifyCollection:
|
|
@@ -8546,10 +8577,10 @@ function topoSimplifyCollection(col, options) {
|
|
|
8546
8577
|
let elapsedTotal = new Util.Elapsed();
|
|
8547
8578
|
let elapsed = new Util.Elapsed();
|
|
8548
8579
|
let topo = topoFromCollection(col);
|
|
8549
|
-
log(`topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
|
|
8580
|
+
log(options.log, `topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
|
|
8550
8581
|
elapsed.start();
|
|
8551
8582
|
topo = TopoSimplify.presimplify(topo, TopoSimplify['sphericalTriangleArea']);
|
|
8552
|
-
log(`topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
|
|
8583
|
+
log(options.log, `topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
|
|
8553
8584
|
elapsed.start();
|
|
8554
8585
|
// Keep iterating on removing simplification from degenerate shapes
|
|
8555
8586
|
let nTries = 1;
|
|
@@ -8601,27 +8632,30 @@ function topoSimplifyCollection(col, options) {
|
|
|
8601
8632
|
}
|
|
8602
8633
|
if (!bDecided) {
|
|
8603
8634
|
let pp = PP.polyPackTopoArcs(testtopo, arcs);
|
|
8635
|
+
P.polyRewindRings(pp);
|
|
8604
8636
|
if (shamos_1.selfIntersectFast(pp)) {
|
|
8605
8637
|
keepArcs(topo, oOld.arcs, keepweight);
|
|
8606
8638
|
nBad++;
|
|
8607
8639
|
}
|
|
8608
8640
|
else {
|
|
8609
8641
|
let { x, y } = intpt(f);
|
|
8610
|
-
|
|
8642
|
+
let d = PL.polyDistance(pp, x, y);
|
|
8643
|
+
if (d < 0.00001) // d is negative if outside the polygon, so that qualifies here
|
|
8644
|
+
{
|
|
8611
8645
|
keepTiny.set(f, f);
|
|
8612
8646
|
keepArcs(topo, oOld.arcs, 0); // keeps all points to avoid reprocessing these tiny shapes
|
|
8613
8647
|
nBad++, nTiny++;
|
|
8614
|
-
log(`topoSimplifyCollection: ${f.properties.id}: increasing feature fidelity because
|
|
8648
|
+
log(options.log, `topoSimplifyCollection: ${f.properties.id}: increasing feature fidelity because intpt dist is ${d}`);
|
|
8615
8649
|
}
|
|
8616
8650
|
}
|
|
8617
8651
|
}
|
|
8618
8652
|
}
|
|
8619
8653
|
});
|
|
8620
|
-
log(`topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
|
|
8654
|
+
log(options.log, `topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
|
|
8621
8655
|
// If not making progress, keep more points
|
|
8622
8656
|
if (nBad >= nBadLast) {
|
|
8623
8657
|
keepweight /= 10;
|
|
8624
|
-
log(`topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
|
|
8658
|
+
log(options.log, `topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
|
|
8625
8659
|
}
|
|
8626
8660
|
nBadLast = nBad;
|
|
8627
8661
|
if (nBad && nTries > MAX_TRIES)
|
|
@@ -8633,7 +8667,7 @@ function topoSimplifyCollection(col, options) {
|
|
|
8633
8667
|
}
|
|
8634
8668
|
nTries++;
|
|
8635
8669
|
}
|
|
8636
|
-
log(`topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
|
|
8670
|
+
log(options.log, `topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
|
|
8637
8671
|
return col;
|
|
8638
8672
|
}
|
|
8639
8673
|
exports.topoSimplifyCollection = topoSimplifyCollection;
|