@trackunit/shared-utils 0.0.85 → 0.0.86
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 +0 -517
- package/index.esm.js +1 -490
- package/package.json +2 -4
- package/src/index.d.ts +0 -4
- package/src/GeoJson/GeoJsonSchemas.d.ts +0 -176
- package/src/GeoJson/GeoJsonUtils.d.ts +0 -73
- package/src/GeoJson/TUGeoJsonObjectBridgeUtils.d.ts +0 -33
- package/src/GeoJson/TuGeoJsonSchemas.d.ts +0 -58
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* A Position is an array of coordinates. [x, y]
|
|
4
|
-
* https://tools.ietf.org/html/rfc7946#section-3.1.1
|
|
5
|
-
*/
|
|
6
|
-
export declare const geoJsonPositionSchema: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
7
|
-
export type GeoJsonPosition = z.infer<typeof geoJsonPositionSchema>;
|
|
8
|
-
/**
|
|
9
|
-
* Point geometry object.
|
|
10
|
-
* https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
11
|
-
*/
|
|
12
|
-
export declare const geoJsonPointSchema: z.ZodObject<{
|
|
13
|
-
type: z.ZodLiteral<"Point">;
|
|
14
|
-
coordinates: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
15
|
-
}, "strict", z.ZodTypeAny, {
|
|
16
|
-
type: "Point";
|
|
17
|
-
coordinates: [number, number];
|
|
18
|
-
}, {
|
|
19
|
-
type: "Point";
|
|
20
|
-
coordinates: [number, number];
|
|
21
|
-
}>;
|
|
22
|
-
export type GeoJsonPoint = z.infer<typeof geoJsonPointSchema>;
|
|
23
|
-
/**
|
|
24
|
-
* MultiPoint geometry object.
|
|
25
|
-
* https://tools.ietf.org/html/rfc7946#section-3.1.3
|
|
26
|
-
*/
|
|
27
|
-
export declare const geoJsonMultiPointSchema: z.ZodObject<{
|
|
28
|
-
type: z.ZodLiteral<"MultiPoint">;
|
|
29
|
-
coordinates: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">;
|
|
30
|
-
}, "strict", z.ZodTypeAny, {
|
|
31
|
-
type: "MultiPoint";
|
|
32
|
-
coordinates: [number, number][];
|
|
33
|
-
}, {
|
|
34
|
-
type: "MultiPoint";
|
|
35
|
-
coordinates: [number, number][];
|
|
36
|
-
}>;
|
|
37
|
-
export type GeoJsonMultiPoint = z.infer<typeof geoJsonMultiPointSchema>;
|
|
38
|
-
/**
|
|
39
|
-
* LineString geometry object.
|
|
40
|
-
* Minimum length of 2 positions.
|
|
41
|
-
* https://tools.ietf.org/html/rfc7946#section-3.1.4
|
|
42
|
-
*/
|
|
43
|
-
export declare const geoJsonLineStringSchema: z.ZodObject<{
|
|
44
|
-
type: z.ZodLiteral<"LineString">;
|
|
45
|
-
coordinates: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">;
|
|
46
|
-
}, "strict", z.ZodTypeAny, {
|
|
47
|
-
type: "LineString";
|
|
48
|
-
coordinates: [number, number][];
|
|
49
|
-
}, {
|
|
50
|
-
type: "LineString";
|
|
51
|
-
coordinates: [number, number][];
|
|
52
|
-
}>;
|
|
53
|
-
export type GeoJsonLineString = z.infer<typeof geoJsonLineStringSchema>;
|
|
54
|
-
/**
|
|
55
|
-
* MultiLineString geometry object.
|
|
56
|
-
* https://tools.ietf.org/html/rfc7946#section-3.1.5
|
|
57
|
-
*/
|
|
58
|
-
export declare const geoJsonMultiLineStringSchema: z.ZodObject<{
|
|
59
|
-
type: z.ZodLiteral<"MultiLineString">;
|
|
60
|
-
coordinates: z.ZodArray<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, "many">;
|
|
61
|
-
}, "strict", z.ZodTypeAny, {
|
|
62
|
-
type: "MultiLineString";
|
|
63
|
-
coordinates: [number, number][][];
|
|
64
|
-
}, {
|
|
65
|
-
type: "MultiLineString";
|
|
66
|
-
coordinates: [number, number][][];
|
|
67
|
-
}>;
|
|
68
|
-
export type GeoJsonMultiLineString = z.infer<typeof geoJsonMultiLineStringSchema>;
|
|
69
|
-
/**
|
|
70
|
-
* Helper type for reuse across polygon schemas.
|
|
71
|
-
*
|
|
72
|
-
* - A linear ring is a closed LineString with four or more positions.
|
|
73
|
-
* - The first and last positions are equivalent, and they MUST contain
|
|
74
|
-
identical values; their representation SHOULD also be identical
|
|
75
|
-
* - A linear ring is the boundary of a surface or the boundary of a
|
|
76
|
-
hole in a surface
|
|
77
|
-
* - A linear ring MUST follow the right-hand rule with respect to the
|
|
78
|
-
area it bounds, i.e., exterior rings are counterclockwise, and
|
|
79
|
-
holes are clockwise
|
|
80
|
-
*/
|
|
81
|
-
export declare const geoJsonLinearRingSchema: z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, [number, number][], [number, number][]>;
|
|
82
|
-
export type GeoJsonLinearRing = z.infer<typeof geoJsonLinearRingSchema>;
|
|
83
|
-
/**
|
|
84
|
-
* Polygon geometry object.
|
|
85
|
-
* https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
86
|
-
*/
|
|
87
|
-
export declare const geoJsonPolygonSchema: z.ZodObject<{
|
|
88
|
-
type: z.ZodLiteral<"Polygon">;
|
|
89
|
-
coordinates: z.ZodArray<z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, [number, number][], [number, number][]>, "many">;
|
|
90
|
-
}, "strict", z.ZodTypeAny, {
|
|
91
|
-
type: "Polygon";
|
|
92
|
-
coordinates: [number, number][][];
|
|
93
|
-
}, {
|
|
94
|
-
type: "Polygon";
|
|
95
|
-
coordinates: [number, number][][];
|
|
96
|
-
}>;
|
|
97
|
-
export type GeoJsonPolygon = z.infer<typeof geoJsonPolygonSchema>;
|
|
98
|
-
/**
|
|
99
|
-
* MultiPolygon geometry object.
|
|
100
|
-
* https://tools.ietf.org/html/rfc7946#section-3.1.7
|
|
101
|
-
*/
|
|
102
|
-
export declare const geoJsonMultiPolygonSchema: z.ZodObject<{
|
|
103
|
-
type: z.ZodLiteral<"MultiPolygon">;
|
|
104
|
-
coordinates: z.ZodArray<z.ZodArray<z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, [number, number][], [number, number][]>, "many">, "many">;
|
|
105
|
-
}, "strict", z.ZodTypeAny, {
|
|
106
|
-
type: "MultiPolygon";
|
|
107
|
-
coordinates: [number, number][][][];
|
|
108
|
-
}, {
|
|
109
|
-
type: "MultiPolygon";
|
|
110
|
-
coordinates: [number, number][][][];
|
|
111
|
-
}>;
|
|
112
|
-
export type GeoJsonMultiPolygon = z.infer<typeof geoJsonMultiPolygonSchema>;
|
|
113
|
-
export declare const geoJsonGeometrySchema: z.ZodUnion<[z.ZodObject<{
|
|
114
|
-
type: z.ZodLiteral<"Point">;
|
|
115
|
-
coordinates: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
116
|
-
}, "strict", z.ZodTypeAny, {
|
|
117
|
-
type: "Point";
|
|
118
|
-
coordinates: [number, number];
|
|
119
|
-
}, {
|
|
120
|
-
type: "Point";
|
|
121
|
-
coordinates: [number, number];
|
|
122
|
-
}>, z.ZodObject<{
|
|
123
|
-
type: z.ZodLiteral<"MultiPoint">;
|
|
124
|
-
coordinates: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">;
|
|
125
|
-
}, "strict", z.ZodTypeAny, {
|
|
126
|
-
type: "MultiPoint";
|
|
127
|
-
coordinates: [number, number][];
|
|
128
|
-
}, {
|
|
129
|
-
type: "MultiPoint";
|
|
130
|
-
coordinates: [number, number][];
|
|
131
|
-
}>, z.ZodObject<{
|
|
132
|
-
type: z.ZodLiteral<"LineString">;
|
|
133
|
-
coordinates: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">;
|
|
134
|
-
}, "strict", z.ZodTypeAny, {
|
|
135
|
-
type: "LineString";
|
|
136
|
-
coordinates: [number, number][];
|
|
137
|
-
}, {
|
|
138
|
-
type: "LineString";
|
|
139
|
-
coordinates: [number, number][];
|
|
140
|
-
}>, z.ZodObject<{
|
|
141
|
-
type: z.ZodLiteral<"MultiLineString">;
|
|
142
|
-
coordinates: z.ZodArray<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, "many">;
|
|
143
|
-
}, "strict", z.ZodTypeAny, {
|
|
144
|
-
type: "MultiLineString";
|
|
145
|
-
coordinates: [number, number][][];
|
|
146
|
-
}, {
|
|
147
|
-
type: "MultiLineString";
|
|
148
|
-
coordinates: [number, number][][];
|
|
149
|
-
}>, z.ZodObject<{
|
|
150
|
-
type: z.ZodLiteral<"Polygon">;
|
|
151
|
-
coordinates: z.ZodArray<z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, [number, number][], [number, number][]>, "many">;
|
|
152
|
-
}, "strict", z.ZodTypeAny, {
|
|
153
|
-
type: "Polygon";
|
|
154
|
-
coordinates: [number, number][][];
|
|
155
|
-
}, {
|
|
156
|
-
type: "Polygon";
|
|
157
|
-
coordinates: [number, number][][];
|
|
158
|
-
}>, z.ZodObject<{
|
|
159
|
-
type: z.ZodLiteral<"MultiPolygon">;
|
|
160
|
-
coordinates: z.ZodArray<z.ZodArray<z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, [number, number][], [number, number][]>, "many">, "many">;
|
|
161
|
-
}, "strict", z.ZodTypeAny, {
|
|
162
|
-
type: "MultiPolygon";
|
|
163
|
-
coordinates: [number, number][][][];
|
|
164
|
-
}, {
|
|
165
|
-
type: "MultiPolygon";
|
|
166
|
-
coordinates: [number, number][][][];
|
|
167
|
-
}>]>;
|
|
168
|
-
export type GeoJsonGeometry = z.infer<typeof geoJsonGeometrySchema>;
|
|
169
|
-
/**
|
|
170
|
-
* 2D bounding box of the GeoJSON object.
|
|
171
|
-
* The value of the Bbox member is an array of length 4.
|
|
172
|
-
*
|
|
173
|
-
* [min_lon, min_lat, max_lon, max_lat]
|
|
174
|
-
*/
|
|
175
|
-
export declare const geoJsonBboxSchema: z.ZodEffects<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>, [number, number, number, number], [number, number, number, number]>;
|
|
176
|
-
export type GeoJsonBbox = z.infer<typeof geoJsonBboxSchema>;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { GeoJsonBbox, GeoJsonLinearRing, GeoJsonMultiPolygon, GeoJsonPoint, GeoJsonPolygon, GeoJsonPosition } from "./GeoJsonSchemas";
|
|
2
|
-
import { TuGeoJsonPolygonNoHoles } from "./TuGeoJsonSchemas";
|
|
3
|
-
export declare const EARTH_RADIUS = 6378137;
|
|
4
|
-
interface PointCoordinate {
|
|
5
|
-
longitude: number;
|
|
6
|
-
latitude: number;
|
|
7
|
-
}
|
|
8
|
-
interface BoundingBox {
|
|
9
|
-
nw: PointCoordinate;
|
|
10
|
-
se: PointCoordinate;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @description Creates a polygon (with no holes) from a bounding box.
|
|
14
|
-
*/
|
|
15
|
-
export declare const getPolygonFromBbox: (bbox: GeoJsonBbox) => TuGeoJsonPolygonNoHoles;
|
|
16
|
-
/**
|
|
17
|
-
* @description Creates a bounding box from a GeoJSON Polygon.
|
|
18
|
-
*/
|
|
19
|
-
export declare const getBboxFromGeoJsonPolygon: (polygon: GeoJsonPolygon) => GeoJsonBbox | null;
|
|
20
|
-
/**
|
|
21
|
-
* @description Creates a round polygon from a point and a radius.
|
|
22
|
-
*/
|
|
23
|
-
export declare const getPolygonFromPointAndRadius: (point: GeoJsonPoint, radius: number) => GeoJsonPolygon;
|
|
24
|
-
/**
|
|
25
|
-
* @description Creates a TU bounding box from a GeoJson Polygon.
|
|
26
|
-
*/
|
|
27
|
-
export declare const getBoundingBoxFromGeoJsonPolygon: (polygon: GeoJsonPolygon) => BoundingBox | null;
|
|
28
|
-
/**
|
|
29
|
-
* @description Creates a GeoJSON Polygon from a TU bounding box.
|
|
30
|
-
*/
|
|
31
|
-
export declare const getGeoJsonPolygonFromBoundingBox: (boundingBox: BoundingBox) => GeoJsonPolygon;
|
|
32
|
-
/**
|
|
33
|
-
* @description Creates TU point coordinate from a GeoJSON Point.
|
|
34
|
-
*/
|
|
35
|
-
export declare const getPointCoordinateFromGeoJsonPoint: (point: GeoJsonPoint) => PointCoordinate;
|
|
36
|
-
/**
|
|
37
|
-
* @description Gets the extreme point of a polygon in a given direction.
|
|
38
|
-
* @param {object} params - The parameters object
|
|
39
|
-
* @param {GeoJsonPolygon} params.polygon - The polygon to get the extreme point from
|
|
40
|
-
* @param {("top" | "right" | "bottom" | "left")} params.direction - The direction to get the extreme point in
|
|
41
|
-
* @returns {GeoJsonPoint} The extreme point in the given direction
|
|
42
|
-
*/
|
|
43
|
-
export declare const getExtremeGeoJsonPointFromPolygon: ({ polygon, direction, }: {
|
|
44
|
-
polygon: GeoJsonPolygon;
|
|
45
|
-
direction: "top" | "right" | "bottom" | "left";
|
|
46
|
-
}) => GeoJsonPoint | null;
|
|
47
|
-
/**
|
|
48
|
-
* Checks if a position is inside a linear ring. On edge is considered inside.
|
|
49
|
-
*/
|
|
50
|
-
export declare const isGeoJsonPositionInLinearRing: ({ position, linearRing, }: {
|
|
51
|
-
position: GeoJsonPosition;
|
|
52
|
-
linearRing: GeoJsonLinearRing;
|
|
53
|
-
}) => boolean | null;
|
|
54
|
-
/**
|
|
55
|
-
* @description Checks if a point is inside a polygon.
|
|
56
|
-
*/
|
|
57
|
-
export declare const isGeoJsonPointInPolygon: ({ point, polygon, }: {
|
|
58
|
-
point: GeoJsonPoint;
|
|
59
|
-
polygon: GeoJsonPolygon;
|
|
60
|
-
}) => boolean | null;
|
|
61
|
-
/**
|
|
62
|
-
* Checks if polygon1 is fully contained within polygon2
|
|
63
|
-
*/
|
|
64
|
-
export declare const isFullyContainedInGeoJsonPolygon: (polygon1: GeoJsonPolygon, polygon2: GeoJsonPolygon) => boolean | null;
|
|
65
|
-
/**
|
|
66
|
-
* @description Gets the intersection between two GeoJSON polygons. If one polygon is fully contained within the other,
|
|
67
|
-
* returns the contained polygon. Otherwise returns a MultiPolygon representing the intersection.
|
|
68
|
-
* @param polygon1 The first polygon to check intersection
|
|
69
|
-
* @param polygon2 The second polygon to check intersection
|
|
70
|
-
* @returns {(GeoJsonMultiPolygon | GeoJsonPolygon)} The intersection as either a Polygon (if one contains the other) or MultiPolygon
|
|
71
|
-
*/
|
|
72
|
-
export declare const getGeoJsonPolygonIntersection: (polygon1: GeoJsonPolygon, polygon2: GeoJsonPolygon) => GeoJsonMultiPolygon | GeoJsonPolygon | null;
|
|
73
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { GeoJsonPosition } from "./GeoJsonSchemas";
|
|
2
|
-
interface PointCoordinate {
|
|
3
|
-
longitude: number;
|
|
4
|
-
latitude: number;
|
|
5
|
-
}
|
|
6
|
-
interface GeoJSONGeometry {
|
|
7
|
-
type?: unknown;
|
|
8
|
-
coordinates?: GeoJsonPosition | GeoJsonPosition[] | GeoJsonPosition[][] | null;
|
|
9
|
-
}
|
|
10
|
-
interface GeoJsonFeature {
|
|
11
|
-
type?: unknown;
|
|
12
|
-
geometry?: GeoJSONGeometry | null;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* @description Returns coordinates in consistent format
|
|
16
|
-
* @param inconsistentCoordinates Single point, array of points or nested array of points
|
|
17
|
-
* @returns {GeoJsonPosition[]} Array of standardized coordinates
|
|
18
|
-
*/
|
|
19
|
-
export declare const coordinatesToStandardFormat: (inconsistentCoordinates: GeoJsonPosition | GeoJsonPosition[] | GeoJsonPosition[][] | null | undefined) => [number, number][];
|
|
20
|
-
/**
|
|
21
|
-
* @description Extracts a point coordinate from a GeoJSON object.
|
|
22
|
-
* @param geoObject A GeoJSON object.
|
|
23
|
-
* @returns {PointCoordinate} A point coordinate.
|
|
24
|
-
*/
|
|
25
|
-
export declare const getPointCoordinateFromGeoJsonObject: (geoObject: GeoJsonFeature | GeoJSONGeometry | undefined | null) => PointCoordinate | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* @description Extracts multiple point coordinates from a GeoJSON object.
|
|
28
|
-
* @param geoObject A GeoJSON object.
|
|
29
|
-
* @returns {PointCoordinate[]} An array of point coordinates.
|
|
30
|
-
* @example getMultipleCoordinatesFromGeoJsonObject({ type: "Point", coordinates: [1, 2] }) // [{ longitude: 1, latitude: 2 }]
|
|
31
|
-
*/
|
|
32
|
-
export declare const getMultipleCoordinatesFromGeoJsonObject: (geoObject: GeoJsonFeature | GeoJSONGeometry | undefined | null) => PointCoordinate[] | undefined;
|
|
33
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* Polygon geometry object that explicitly disallows holes.
|
|
4
|
-
*
|
|
5
|
-
* Same as geoJsonPolygonSchema but type disallows holes by
|
|
6
|
-
* using tuple of one single linear ring instead of an array.
|
|
7
|
-
*/
|
|
8
|
-
export declare const tuGeoJsonPolygonNoHolesSchema: z.ZodObject<{
|
|
9
|
-
type: z.ZodLiteral<"Polygon">;
|
|
10
|
-
coordinates: z.ZodTuple<[z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, [number, number][], [number, number][]>], null>;
|
|
11
|
-
}, "strict", z.ZodTypeAny, {
|
|
12
|
-
type: "Polygon";
|
|
13
|
-
coordinates: [[number, number][]];
|
|
14
|
-
}, {
|
|
15
|
-
type: "Polygon";
|
|
16
|
-
coordinates: [[number, number][]];
|
|
17
|
-
}>;
|
|
18
|
-
export type TuGeoJsonPolygonNoHoles = z.infer<typeof tuGeoJsonPolygonNoHolesSchema>;
|
|
19
|
-
/**
|
|
20
|
-
* Point radius object.
|
|
21
|
-
* For when you wish to define an area by a point and a radius.
|
|
22
|
-
*
|
|
23
|
-
* radius is in meters
|
|
24
|
-
*/
|
|
25
|
-
export declare const tuGeoJsonPointRadiusSchema: z.ZodObject<{
|
|
26
|
-
type: z.ZodLiteral<"PointRadius">;
|
|
27
|
-
coordinates: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
28
|
-
radius: z.ZodNumber;
|
|
29
|
-
}, "strict", z.ZodTypeAny, {
|
|
30
|
-
type: "PointRadius";
|
|
31
|
-
coordinates: [number, number];
|
|
32
|
-
radius: number;
|
|
33
|
-
}, {
|
|
34
|
-
type: "PointRadius";
|
|
35
|
-
coordinates: [number, number];
|
|
36
|
-
radius: number;
|
|
37
|
-
}>;
|
|
38
|
-
export type TuGeoJsonPointRadius = z.infer<typeof tuGeoJsonPointRadiusSchema>;
|
|
39
|
-
/**
|
|
40
|
-
* A Polygon with exactly 5 points and 4 horizontal/vertical sides that form a normal rectangular box.
|
|
41
|
-
*/
|
|
42
|
-
export declare const tuGeoJsonRectangularBoxPolygonSchema: z.ZodEffects<z.ZodObject<{
|
|
43
|
-
type: z.ZodLiteral<"Polygon">;
|
|
44
|
-
coordinates: z.ZodArray<z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, "many">, [number, number][], [number, number][]>, "many">;
|
|
45
|
-
}, "strict", z.ZodTypeAny, {
|
|
46
|
-
type: "Polygon";
|
|
47
|
-
coordinates: [number, number][][];
|
|
48
|
-
}, {
|
|
49
|
-
type: "Polygon";
|
|
50
|
-
coordinates: [number, number][][];
|
|
51
|
-
}>, {
|
|
52
|
-
type: "Polygon";
|
|
53
|
-
coordinates: [number, number][][];
|
|
54
|
-
}, {
|
|
55
|
-
type: "Polygon";
|
|
56
|
-
coordinates: [number, number][][];
|
|
57
|
-
}>;
|
|
58
|
-
export type TuGeoJsonRectangularBoxPolygon = z.infer<typeof tuGeoJsonRectangularBoxPolygonSchema>;
|