-
Notifications
You must be signed in to change notification settings - Fork 13
/
geo-interfaces.ts
118 lines (98 loc) · 2.86 KB
/
geo-interfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
export enum ESGeoShapeType {
Point = 'point',
Polygon = 'polygon',
MultiPolygon = 'multipolygon'
}
export type ESGeoShapePoint = {
type: ESGeoShapeType.Point;
coordinates: CoordinateTuple;
}
export type ESGeoShapePolygon = {
type: ESGeoShapeType.Polygon;
coordinates: CoordinateTuple[][];
}
export type ESGeoShapeMultiPolygon = {
type: ESGeoShapeType.MultiPolygon;
coordinates: CoordinateTuple[][][];
}
export type ESGeoShape = ESGeoShapePoint | ESGeoShapePolygon | ESGeoShapeMultiPolygon
export enum GeoShapeType {
Point = 'Point',
Polygon = 'Polygon',
MultiPolygon = 'MultiPolygon',
}
export type GeoShapePoint = {
type: GeoShapeType.Point;
coordinates: CoordinateTuple;
}
export type GeoShapePolygon = {
type: GeoShapeType.Polygon;
coordinates: CoordinateTuple[][];
}
export type GeoShapeMultiPolygon = {
type: GeoShapeType.MultiPolygon;
coordinates: CoordinateTuple[][][];
}
export type GeoShape = GeoShapePoint | GeoShapePolygon | GeoShapeMultiPolygon;
export type JoinGeoShape = GeoShape | ESGeoShape;
export type CoordinateTuple = [lon: number, lat: number];
type GeoPointArr = [lon: number, lat:number];
type GeoPointStr = string;
type GeoObjShort = { lat: string | number; lon: string | number };
type GeoObjLong = { latitude: string | number; longitude: string | number };
export type GeoPointInput =
GeoPointArr|
GeoPointStr|
GeoObjShort|
GeoObjLong|
GeoShapePoint;
export interface GeoPoint {
readonly lat: number;
readonly lon: number;
}
/**
* A geo boundary is a box of geo points requiring at two geo points,
* one point is the top left, the other is the bottom right
*/
export type GeoBoundary = readonly [topLeft: GeoPoint, bottomRight: GeoPoint];
export enum GeoShapeRelation {
Intersects = 'intersects',
Disjoint = 'disjoint',
Within = 'within',
Contains = 'contains'
}
export type GeoInput = GeoPointInput | GeoPointInput[] | GeoShape;
export type GeoDistanceUnit = 'miles'|'yards'|'feet'|'inch'|'kilometers'|'meters'|'centimeters'|'millimeters'|'nauticalmiles';
export const GEO_DISTANCE_UNITS: { readonly [key: string]: GeoDistanceUnit } = {
mi: 'miles',
miles: 'miles',
mile: 'miles',
NM: 'nauticalmiles',
nmi: 'nauticalmiles',
nauticalmile: 'nauticalmiles',
nauticalmiles: 'nauticalmiles',
in: 'inch',
inch: 'inch',
inches: 'inch',
yd: 'yards',
yard: 'yards',
yards: 'yards',
m: 'meters',
meter: 'meters',
meters: 'meters',
km: 'kilometers',
kilometer: 'kilometers',
kilometers: 'kilometers',
mm: 'millimeters',
millimeter: 'millimeters',
millimeters: 'millimeters',
cm: 'centimeters',
centimeter: 'centimeters',
centimeters: 'centimeters',
ft: 'feet',
feet: 'feet',
};
export interface GeoDistanceObj {
distance: number;
unit: GeoDistanceUnit;
}