@trackunit/geo-json-utils 0.0.1

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.
@@ -0,0 +1,73 @@
1
+ import { GeoJsonBbox, GeoJsonLinearRing, GeoJsonMultiPolygon, GeoJsonPoint, GeoJsonPolygon, GeoJsonPosition } from "./GeoJsonSchemas";
2
+ import { TuGeoJsonPolygonNoHoles } from "./TuGeoJsonSchemas";
3
+ export declare const EARTH_RADIUS = 6378137;
4
+ interface TuCoordinate {
5
+ longitude: number;
6
+ latitude: number;
7
+ }
8
+ interface TuBoundingBox {
9
+ nw: TuCoordinate;
10
+ se: TuCoordinate;
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) => TuBoundingBox | null;
28
+ /**
29
+ * @description Creates a GeoJSON Polygon from a TU bounding box.
30
+ */
31
+ export declare const getGeoJsonPolygonFromBoundingBox: (boundingBox: TuBoundingBox) => GeoJsonPolygon;
32
+ /**
33
+ * @description Creates TU point coordinate from a GeoJSON Point.
34
+ */
35
+ export declare const getPointCoordinateFromGeoJsonPoint: (point: GeoJsonPoint) => TuCoordinate;
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 {};
@@ -0,0 +1,33 @@
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 {};
@@ -0,0 +1,58 @@
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>;
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./GeoJsonSchemas";
2
+ export * from "./GeoJsonUtils";
3
+ export * from "./TUGeoJsonObjectBridgeUtils";
4
+ export * from "./TuGeoJsonSchemas";