@dra2020/baseclient 1.0.63 → 1.0.66

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/lib/geo/geo.ts CHANGED
@@ -56,25 +56,7 @@ export function geoNormalizeFeature(f: any, options?: NormalizeOptions): GeoFeat
56
56
  {
57
57
  options = Util.shallowAssignImmutable({}, options);
58
58
 
59
- if (f && f.geometry && f.geometry.type === 'MultiPolygon' && f.geometry.coordinates)
60
- {
61
- let multiPoly = f.geometry.coordinates;
62
-
63
- // Convert degenerate MultiPolygon to Polygon
64
- if (multiPoly.length == 1)
65
- {
66
- f.geometry.type = 'Polygon';
67
- f.geometry.coordinates = multiPoly[0];
68
- }
69
- }
70
- else if (f && f.geometry && f.geometry.type === 'Point' && f.geometry.coordinates)
71
- {
72
- while (Array.isArray(f.geometry.coordinates[0]))
73
- f.geometry.coordinates = f.geometry.coordinates[0];
74
- }
75
- else if (options.checkRewind)
76
- // Various tools do not guarantee valid GeoJSON winding rules. Verify it since internal processing
77
- // assumes it is correct.
59
+ if (options.checkRewind)
78
60
  Poly.featureRewind(f);
79
61
 
80
62
  return f;
package/lib/poly/poly.ts CHANGED
@@ -762,26 +762,35 @@ export function featureRewind(f: any, options?: RewindOptions): any
762
762
  // Only applies to multi-polygons with no holes
763
763
  let d = Util.depthof(f.geometry.coordinates);
764
764
  let windings = polyRingWindings(f);
765
- if (options.validateHoles && d === 5 && windings.length)
765
+ if (options.validateHoles && d === 5 && windings.length > 1)
766
766
  {
767
- // If there are explicit holes, don't look for implicit ones
768
- let nHoles = 0; windings.forEach(w => { if (w.iRing) nHoles++ });
769
- if (nHoles == 0 && !misWound(windings[0]))
767
+ // First winding needs to be correct so we have a poly to add holes to
768
+ if (!misWound(windings[0]))
770
769
  {
771
- // Looking for pattern: of (G (B*))*
772
- // To convert to ((GH*))*
773
- let iWinding = 0;
770
+ // Flatten everything out and then rebuild hole structure based on windings
771
+ let nHoles = 0; windings.forEach(w => { nHoles += w.iRing ? 1 : 0 });
772
+ if (nHoles)
773
+ {
774
+ let c: any[] = [];
775
+ f.geometry.coordinates.forEach((poly: any) => {
776
+ poly.forEach((ring: any) => {
777
+ c.push([ring]);
778
+ });
779
+ });
780
+ f.geometry.coordinates = c;
781
+ windings = polyRingWindings(f);
782
+ }
783
+
774
784
  let polys = f.geometry.coordinates;
775
- let iPoly: number;
776
- for (; iWinding < windings.length; iWinding++)
785
+ let iPoly = 0;
786
+ for (let iWinding = 0; iWinding < windings.length; iWinding++)
777
787
  {
778
788
  let good = !misWound(windings[iWinding]);
779
- if (!good && iWinding == 0) // First is miswound - no good
780
- break;
781
789
  if (good)
782
790
  iPoly = iWinding;
783
791
  else
784
792
  {
793
+ // If hole, add to previous poly
785
794
  polys[iPoly].push(polys[iWinding][0]);
786
795
  polys[iWinding] = null;
787
796
  }
@@ -794,11 +803,13 @@ export function featureRewind(f: any, options?: RewindOptions): any
794
803
  {
795
804
  f.geometry.type = 'Polygon';
796
805
  f.geometry.coordinates = f.geometry.coordinates[0];
806
+ d = 4;
797
807
  }
798
808
  }
799
809
 
800
810
  // OK, now go through each ring
801
811
  let polys = f.geometry.coordinates;
812
+ if (d == 4) polys = [polys];
802
813
  windings = polyRingWindings(f);
803
814
  windings.forEach((w: Winding) => {
804
815
  let good = !misWound(w);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.63",
3
+ "version": "1.0.66",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",