@trackunit/geo-json-utils 1.15.20-alpha-aedae0c85f6.0 → 1.15.20
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/index.cjs.js +18 -1
- package/index.esm.js +18 -1
- package/package.json +1 -1
- package/src/GeoJsonUtils.d.ts +9 -0
package/index.cjs.js
CHANGED
|
@@ -900,12 +900,20 @@ const getPolygonFromPointAndRadius = (point, radius) => {
|
|
|
900
900
|
const deltaLat = (radius / EARTH_RADIUS) * (180 / Math.PI);
|
|
901
901
|
const deltaLon = deltaLat / Math.cos((lat * Math.PI) / 180);
|
|
902
902
|
const coordinates = [];
|
|
903
|
-
for (let i = 0; i
|
|
903
|
+
for (let i = 0; i < pointsCount; i++) {
|
|
904
904
|
const angle = i * angleStep;
|
|
905
905
|
const newLat = Math.max(-90, Math.min(90, lat + deltaLat * Math.sin(angle)));
|
|
906
906
|
const newLon = lonCenter + deltaLon * Math.cos(angle);
|
|
907
907
|
coordinates.push([newLon, newLat]);
|
|
908
908
|
}
|
|
909
|
+
// Close the ring by copying vertex 0 rather than recomputing it at angle 2π: Math.sin(2π) is
|
|
910
|
+
// -2.449e-16, and near the equator that offset exceeds half an ulp of the latitude, leaving the
|
|
911
|
+
// ring open and failing RFC 7946 validation.
|
|
912
|
+
const firstVertex = coordinates[0];
|
|
913
|
+
if (firstVertex === undefined) {
|
|
914
|
+
return null;
|
|
915
|
+
}
|
|
916
|
+
coordinates.push([...firstVertex]);
|
|
909
917
|
const rawLngs = coordinates.map(c => c[0]);
|
|
910
918
|
const minRawLon = Math.min(...rawLngs);
|
|
911
919
|
const maxRawLon = Math.max(...rawLngs);
|
|
@@ -1277,6 +1285,15 @@ const isFullyContainedInGeoJsonPolygon = (polygon1, polygon2) => {
|
|
|
1277
1285
|
/**
|
|
1278
1286
|
* @description Gets the intersection between two GeoJSON polygons/multi-polygons.
|
|
1279
1287
|
* Returns a MultiPolygon representing the intersection, or null if there is no intersection.
|
|
1288
|
+
*
|
|
1289
|
+
* Delegates to `polygon-clipping`, which can **throw** `"Unable to complete output ring"`
|
|
1290
|
+
* for degenerate or near-self-intersecting geometry that is still schema-valid. Callers must
|
|
1291
|
+
* decide how to handle that: `null` here is reserved for a *provably empty* intersection, so
|
|
1292
|
+
* a thrown failure must not be silently folded into `null` (see SAGA-743). Callers for which
|
|
1293
|
+
* "no overlap" is a safe degradation (e.g. overlap grouping in `@trackunit/react-map`) should
|
|
1294
|
+
* catch and treat the throw as no intersection; callers that turn `null` into "no spatial
|
|
1295
|
+
* filter" (e.g. `mapUtils` viewport/area merges) must instead fall back to a conservative
|
|
1296
|
+
* geometry rather than assume disjointness.
|
|
1280
1297
|
*/
|
|
1281
1298
|
const getGeoJsonPolygonIntersection = (polygon1, polygon2) => {
|
|
1282
1299
|
const geom1 = polygon1.type === "MultiPolygon" ? toClipMultiPolygon(polygon1.coordinates) : [toClipPolygon(polygon1.coordinates)];
|
package/index.esm.js
CHANGED
|
@@ -898,12 +898,20 @@ const getPolygonFromPointAndRadius = (point, radius) => {
|
|
|
898
898
|
const deltaLat = (radius / EARTH_RADIUS) * (180 / Math.PI);
|
|
899
899
|
const deltaLon = deltaLat / Math.cos((lat * Math.PI) / 180);
|
|
900
900
|
const coordinates = [];
|
|
901
|
-
for (let i = 0; i
|
|
901
|
+
for (let i = 0; i < pointsCount; i++) {
|
|
902
902
|
const angle = i * angleStep;
|
|
903
903
|
const newLat = Math.max(-90, Math.min(90, lat + deltaLat * Math.sin(angle)));
|
|
904
904
|
const newLon = lonCenter + deltaLon * Math.cos(angle);
|
|
905
905
|
coordinates.push([newLon, newLat]);
|
|
906
906
|
}
|
|
907
|
+
// Close the ring by copying vertex 0 rather than recomputing it at angle 2π: Math.sin(2π) is
|
|
908
|
+
// -2.449e-16, and near the equator that offset exceeds half an ulp of the latitude, leaving the
|
|
909
|
+
// ring open and failing RFC 7946 validation.
|
|
910
|
+
const firstVertex = coordinates[0];
|
|
911
|
+
if (firstVertex === undefined) {
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
coordinates.push([...firstVertex]);
|
|
907
915
|
const rawLngs = coordinates.map(c => c[0]);
|
|
908
916
|
const minRawLon = Math.min(...rawLngs);
|
|
909
917
|
const maxRawLon = Math.max(...rawLngs);
|
|
@@ -1275,6 +1283,15 @@ const isFullyContainedInGeoJsonPolygon = (polygon1, polygon2) => {
|
|
|
1275
1283
|
/**
|
|
1276
1284
|
* @description Gets the intersection between two GeoJSON polygons/multi-polygons.
|
|
1277
1285
|
* Returns a MultiPolygon representing the intersection, or null if there is no intersection.
|
|
1286
|
+
*
|
|
1287
|
+
* Delegates to `polygon-clipping`, which can **throw** `"Unable to complete output ring"`
|
|
1288
|
+
* for degenerate or near-self-intersecting geometry that is still schema-valid. Callers must
|
|
1289
|
+
* decide how to handle that: `null` here is reserved for a *provably empty* intersection, so
|
|
1290
|
+
* a thrown failure must not be silently folded into `null` (see SAGA-743). Callers for which
|
|
1291
|
+
* "no overlap" is a safe degradation (e.g. overlap grouping in `@trackunit/react-map`) should
|
|
1292
|
+
* catch and treat the throw as no intersection; callers that turn `null` into "no spatial
|
|
1293
|
+
* filter" (e.g. `mapUtils` viewport/area merges) must instead fall back to a conservative
|
|
1294
|
+
* geometry rather than assume disjointness.
|
|
1278
1295
|
*/
|
|
1279
1296
|
const getGeoJsonPolygonIntersection = (polygon1, polygon2) => {
|
|
1280
1297
|
const geom1 = polygon1.type === "MultiPolygon" ? toClipMultiPolygon(polygon1.coordinates) : [toClipPolygon(polygon1.coordinates)];
|
package/package.json
CHANGED
package/src/GeoJsonUtils.d.ts
CHANGED
|
@@ -100,6 +100,15 @@ export declare const isFullyContainedInGeoJsonPolygon: (polygon1: GeoJsonPolygon
|
|
|
100
100
|
/**
|
|
101
101
|
* @description Gets the intersection between two GeoJSON polygons/multi-polygons.
|
|
102
102
|
* Returns a MultiPolygon representing the intersection, or null if there is no intersection.
|
|
103
|
+
*
|
|
104
|
+
* Delegates to `polygon-clipping`, which can **throw** `"Unable to complete output ring"`
|
|
105
|
+
* for degenerate or near-self-intersecting geometry that is still schema-valid. Callers must
|
|
106
|
+
* decide how to handle that: `null` here is reserved for a *provably empty* intersection, so
|
|
107
|
+
* a thrown failure must not be silently folded into `null` (see SAGA-743). Callers for which
|
|
108
|
+
* "no overlap" is a safe degradation (e.g. overlap grouping in `@trackunit/react-map`) should
|
|
109
|
+
* catch and treat the throw as no intersection; callers that turn `null` into "no spatial
|
|
110
|
+
* filter" (e.g. `mapUtils` viewport/area merges) must instead fall back to a conservative
|
|
111
|
+
* geometry rather than assume disjointness.
|
|
103
112
|
*/
|
|
104
113
|
export declare const getGeoJsonPolygonIntersection: (polygon1: GeoJsonPolygon | GeoJsonMultiPolygon, polygon2: GeoJsonPolygon | GeoJsonMultiPolygon) => GeoJsonMultiPolygon | GeoJsonPolygon | null;
|
|
105
114
|
/**
|