1 | /**
|
2 | * @module h3
|
3 | */
|
4 | declare module "h3-js" {
|
5 | /**
|
6 | * 64-bit hexidecimal string representation of an H3 index
|
7 | * @static
|
8 | * @typedef {string} H3Index
|
9 | */
|
10 | type H3Index = string;
|
11 | /**
|
12 | * Whether a given string represents a valid H3 index
|
13 | * @static
|
14 | * @param {H3Index} h3Index H3 index to check
|
15 | * @return {Boolean} Whether the index is valid
|
16 | */
|
17 | function h3IsValid(h3Index: H3Index): boolean;
|
18 | /**
|
19 | * Whether the given H3 index is a pentagon
|
20 | * @static
|
21 | * @param {H3Index} h3Index H3 index to check
|
22 | * @return {Boolean} isPentagon
|
23 | */
|
24 | function h3IsPentagon(h3Index: H3Index): boolean;
|
25 | /**
|
26 | * Whether the given H3 index is in a Class III resolution (rotated versus
|
27 | * the icosahedron and subject to shape distortion adding extra points on
|
28 | * icosahedron edges, making them not true hexagons).
|
29 | * @static
|
30 | * @param {H3Index} h3Index H3 index to check
|
31 | * @return {Boolean} isResClassIII
|
32 | */
|
33 | function h3IsResClassIII(h3Index: H3Index): boolean;
|
34 | /**
|
35 | * Get the number of the base cell for a given H3 index
|
36 | * @static
|
37 | * @param {H3Index} h3Index H3 index to get the base cell for
|
38 | * @return {Number} Index of the base cell (0-121)
|
39 | */
|
40 | function h3GetBaseCell(h3Index: H3Index): number;
|
41 | /**
|
42 | * Get the indices of all icosahedron faces intersected by a given H3 index
|
43 | * @static
|
44 | * @param {H3Index} h3Index H3 index to get faces for
|
45 | * @return {Number[]} Indices (0-19) of all intersected faces
|
46 | */
|
47 | function h3GetFaces(h3Index: H3Index): Number[];
|
48 | /**
|
49 | * Returns the resolution of an H3 index
|
50 | * @static
|
51 | * @param {H3Index} h3Index H3 index to get resolution
|
52 | * @return {Number} The number (0-15) resolution, or -1 if invalid
|
53 | */
|
54 | function h3GetResolution(h3Index: H3Index): number;
|
55 | /**
|
56 | * Get the hexagon containing a lat,lon point
|
57 | * @static
|
58 | * @param {Number} lat Latitude of point
|
59 | * @param {Number} lng Longtitude of point
|
60 | * @param {Number} res Resolution of hexagons to return
|
61 | * @return {H3Index} H3 index
|
62 | */
|
63 | function geoToH3(lat: number, lng: number, res: number): H3Index;
|
64 | /**
|
65 | * Get the lat,lon center of a given hexagon
|
66 | * @static
|
67 | * @param {H3Index} h3Index H3 index
|
68 | * @return {Number[]} Point as a [lat, lng] pair
|
69 | */
|
70 | function h3ToGeo(h3Index: H3Index): Number[];
|
71 | /**
|
72 | * Get the vertices of a given hexagon (or pentagon), as an array of [lat, lng]
|
73 | * points. For pentagons and hexagons on the edge of an icosahedron face, this
|
74 | * function may return up to 10 vertices.
|
75 | * @static
|
76 | * @param {H3Index} h3Index H3 index
|
77 | * @param {Boolean} formatAsGeoJson Whether to provide GeoJSON output: [lng, lat], closed loops
|
78 | * @return {Number[][]} Array of [lat, lng] pairs
|
79 | */
|
80 | function h3ToGeoBoundary(h3Index: H3Index, formatAsGeoJson: boolean): Number[][];
|
81 | /**
|
82 | * Get the parent of the given hexagon at a particular resolution
|
83 | * @static
|
84 | * @param {H3Index} h3Index H3 index to get parent for
|
85 | * @param {Number} res Resolution of hexagon to return
|
86 | * @return {H3Index} H3 index of parent, or null for invalid input
|
87 | */
|
88 | function h3ToParent(h3Index: H3Index, res: number): H3Index;
|
89 | /**
|
90 | * Get the children/descendents of the given hexagon at a particular resolution
|
91 | * @static
|
92 | * @param {H3Index} h3Index H3 index to get children for
|
93 | * @param {Number} res Resolution of hexagons to return
|
94 | * @return {H3Index[]} H3 indexes of children, or empty array for invalid input
|
95 | */
|
96 | function h3ToChildren(h3Index: H3Index, res: number): H3Index[];
|
97 | /**
|
98 | * Get the center child of the given hexagon at a particular resolution
|
99 | * @static
|
100 | * @param {H3Index} h3Index H3 index to get center child for
|
101 | * @param {Number} res Resolution of hexagon to return
|
102 | * @return {H3Index} H3 index of child, or null for invalid input
|
103 | */
|
104 | function h3ToCenterChild(h3Index: H3Index, res: number): H3Index;
|
105 | /**
|
106 | * Get all hexagons in a k-ring around a given center. The order of the hexagons is undefined.
|
107 | * @static
|
108 | * @param {H3Index} h3Index H3 index of center hexagon
|
109 | * @param {Number} ringSize Radius of k-ring
|
110 | * @return {H3Index[]} H3 indexes for all hexagons in ring
|
111 | */
|
112 | function kRing(h3Index: H3Index, ringSize: number): H3Index[];
|
113 | /**
|
114 | * Get all hexagons in a k-ring around a given center, in an array of arrays
|
115 | * ordered by distance from the origin. The order of the hexagons within each ring is undefined.
|
116 | * @static
|
117 | * @param {H3Index} h3Index H3 index of center hexagon
|
118 | * @param {Number} ringSize Radius of k-ring
|
119 | * @return {H3Index[][]} Array of arrays with H3 indexes for all hexagons each ring
|
120 | */
|
121 | function kRingDistances(h3Index: H3Index, ringSize: number): H3Index[][];
|
122 | /**
|
123 | * Get all hexagons in a hollow hexagonal ring centered at origin with sides of a given length.
|
124 | * Unlike kRing, this function will throw an error if there is a pentagon anywhere in the ring.
|
125 | * @static
|
126 | * @param {H3Index} h3Index H3 index of center hexagon
|
127 | * @param {Number} ringSize Radius of ring
|
128 | * @return {H3Index[]} H3 indexes for all hexagons in ring
|
129 | * @throws {Error} If the algorithm could not calculate the ring
|
130 | */
|
131 | function hexRing(h3Index: H3Index, ringSize: number): H3Index[];
|
132 | /**
|
133 | * Get all hexagons with centers contained in a given polygon. The polygon
|
134 | * is specified with GeoJson semantics as an array of loops. Each loop is
|
135 | * an array of [lat, lng] pairs (or [lng, lat] if isGeoJson is specified).
|
136 | * The first loop is the perimeter of the polygon, and subsequent loops are
|
137 | * expected to be holes.
|
138 | * @static
|
139 | * @param {Number[][] | Number[][][]} coordinates
|
140 | * Array of loops, or a single loop
|
141 | * @param {Number} res Resolution of hexagons to return
|
142 | * @param {Boolean} isGeoJson Whether to expect GeoJson-style [lng, lat]
|
143 | * pairs instead of [lat, lng]
|
144 | * @return {H3Index[]} H3 indexes for all hexagons in polygon
|
145 | */
|
146 | function polyfill(coordinates: Number[][] | Number[][][], res: number, isGeoJson: boolean): H3Index[];
|
147 | /**
|
148 | * Get the outlines of a set of H3 hexagons, returned in GeoJSON MultiPolygon
|
149 | * format (an array of polygons, each with an array of loops, each an array of
|
150 | * coordinates). Coordinates are returned as [lat, lng] pairs unless GeoJSON
|
151 | * is requested.
|
152 | * @static
|
153 | * @param {H3Index[]} h3Indexes H3 indexes to get outlines for
|
154 | * @param {Boolean} formatAsGeoJson Whether to provide GeoJSON output:
|
155 | * [lng, lat], closed loops
|
156 | * @return {Number[][][][]} MultiPolygon-style output.
|
157 | */
|
158 | function h3SetToMultiPolygon(h3Indexes: H3Index[], formatAsGeoJson: boolean): Number[][][][];
|
159 | /**
|
160 | * Compact a set of hexagons of the same resolution into a set of hexagons across
|
161 | * multiple levels that represents the same area.
|
162 | * @static
|
163 | * @param {H3Index[]} h3Set H3 indexes to compact
|
164 | * @return {H3Index[]} Compacted H3 indexes
|
165 | * @throws {Error} If the input is invalid (e.g. duplicate hexagons)
|
166 | */
|
167 | function compact(h3Set: H3Index[]): H3Index[];
|
168 | /**
|
169 | * Uncompact a compacted set of hexagons to hexagons of the same resolution
|
170 | * @static
|
171 | * @param {H3Index[]} compactedSet H3 indexes to uncompact
|
172 | * @param {Number} res The resolution to uncompact to
|
173 | * @return {H3Index[]} The uncompacted H3 indexes
|
174 | * @throws {Error} If the input is invalid (e.g. invalid resolution)
|
175 | */
|
176 | function uncompact(compactedSet: H3Index[], res: number): H3Index[];
|
177 | /**
|
178 | * Whether two H3 indexes are neighbors (share an edge)
|
179 | * @static
|
180 | * @param {H3Index} origin Origin hexagon index
|
181 | * @param {H3Index} destination Destination hexagon index
|
182 | * @return {Boolean} Whether the hexagons share an edge
|
183 | */
|
184 | function h3IndexesAreNeighbors(origin: H3Index, destination: H3Index): boolean;
|
185 | /**
|
186 | * Get an H3 index representing a unidirectional edge for a given origin and destination
|
187 | * @static
|
188 | * @param {H3Index} origin Origin hexagon index
|
189 | * @param {H3Index} destination Destination hexagon index
|
190 | * @return {H3Index} H3 index of the edge, or null if no edge is shared
|
191 | */
|
192 | function getH3UnidirectionalEdge(origin: H3Index, destination: H3Index): H3Index;
|
193 | /**
|
194 | * Get the origin hexagon from an H3 index representing a unidirectional edge
|
195 | * @static
|
196 | * @param {H3Index} edgeIndex H3 index of the edge
|
197 | * @return {H3Index} H3 index of the edge origin
|
198 | */
|
199 | function getOriginH3IndexFromUnidirectionalEdge(edgeIndex: H3Index): H3Index;
|
200 | /**
|
201 | * Get the destination hexagon from an H3 index representing a unidirectional edge
|
202 | * @static
|
203 | * @param {H3Index} edgeIndex H3 index of the edge
|
204 | * @return {H3Index} H3 index of the edge destination
|
205 | */
|
206 | function getDestinationH3IndexFromUnidirectionalEdge(edgeIndex: H3Index): H3Index;
|
207 | /**
|
208 | * Whether the input is a valid unidirectional edge
|
209 | * @static
|
210 | * @param {H3Index} edgeIndex H3 index of the edge
|
211 | * @return {Boolean} Whether the index is valid
|
212 | */
|
213 | function h3UnidirectionalEdgeIsValid(edgeIndex: H3Index): boolean;
|
214 | /**
|
215 | * Get the [origin, destination] pair represented by a unidirectional edge
|
216 | * @static
|
217 | * @param {H3Index} edgeIndex H3 index of the edge
|
218 | * @return {H3Index[]} [origin, destination] pair as H3 indexes
|
219 | */
|
220 | function getH3IndexesFromUnidirectionalEdge(edgeIndex: H3Index): H3Index[];
|
221 | /**
|
222 | * Get all of the unidirectional edges with the given H3 index as the origin (i.e. an edge to
|
223 | * every neighbor)
|
224 | * @static
|
225 | * @param {H3Index} h3Index H3 index of the origin hexagon
|
226 | * @return {H3Index[]} List of unidirectional edges
|
227 | */
|
228 | function getH3UnidirectionalEdgesFromHexagon(h3Index: H3Index): H3Index[];
|
229 | /**
|
230 | * Get the vertices of a given edge as an array of [lat, lng] points. Note that for edges that
|
231 | * cross the edge of an icosahedron face, this may return 3 coordinates.
|
232 | * @static
|
233 | * @param {H3Index} edgeIndex H3 index of the edge
|
234 | * @param {Boolean} formatAsGeoJson Whether to provide GeoJSON output: [lng, lat]
|
235 | * @return {Number[][]} Array of geo coordinate pairs
|
236 | */
|
237 | function getH3UnidirectionalEdgeBoundary(edgeIndex: H3Index, formatAsGeoJson: boolean): Number[][];
|
238 | /**
|
239 | * Get the grid distance between two hex indexes. This function may fail
|
240 | * to find the distance between two indexes if they are very far apart or
|
241 | * on opposite sides of a pentagon.
|
242 | * @static
|
243 | * @param {H3Index} origin Origin hexagon index
|
244 | * @param {H3Index} destination Destination hexagon index
|
245 | * @return {Number} Distance between hexagons, or a negative
|
246 | * number if the distance could not be computed
|
247 | */
|
248 | function h3Distance(origin: H3Index, destination: H3Index): number;
|
249 | /**
|
250 | * Given two H3 indexes, return the line of indexes between them (inclusive).
|
251 | *
|
252 | * This function may fail to find the line between two indexes, for
|
253 | * example if they are very far apart. It may also fail when finding
|
254 | * distances for indexes on opposite sides of a pentagon.
|
255 | *
|
256 | * Notes:
|
257 | *
|
258 | * - The specific output of this function should not be considered stable
|
259 | * across library versions. The only guarantees the library provides are
|
260 | * that the line length will be `h3Distance(start, end) + 1` and that
|
261 | * every index in the line will be a neighbor of the preceding index.
|
262 | * - Lines are drawn in grid space, and may not correspond exactly to either
|
263 | * Cartesian lines or great arcs.
|
264 | *
|
265 | * @static
|
266 | * @param {H3Index} origin Origin hexagon index
|
267 | * @param {H3Index} destination Destination hexagon index
|
268 | * @return {H3Index[]} H3 indexes connecting origin and destination
|
269 | * @throws {Error} If the line cannot be calculated
|
270 | */
|
271 | function h3Line(origin: H3Index, destination: H3Index): H3Index[];
|
272 | /**
|
273 | * Produces IJ coordinates for an H3 index anchored by an origin.
|
274 | *
|
275 | * - The coordinate space used by this function may have deleted
|
276 | * regions or warping due to pentagonal distortion.
|
277 | * - Coordinates are only comparable if they come from the same
|
278 | * origin index.
|
279 | * - Failure may occur if the index is too far away from the origin
|
280 | * or if the index is on the other side of a pentagon.
|
281 | * - This function is experimental, and its output is not guaranteed
|
282 | * to be compatible across different versions of H3.
|
283 | * @static
|
284 | * @param {H3Index} origin Origin H3 index
|
285 | * @param {H3Index} destination H3 index for which to find relative coordinates
|
286 | * @return {Object} Coordinates as an `{i, j}` pair
|
287 | * @throws {Error} If the IJ coordinates cannot be calculated
|
288 | */
|
289 | function experimentalH3ToLocalIj(origin: H3Index, destination: H3Index): any;
|
290 | /**
|
291 | * Produces an H3 index for IJ coordinates anchored by an origin.
|
292 | *
|
293 | * - The coordinate space used by this function may have deleted
|
294 | * regions or warping due to pentagonal distortion.
|
295 | * - Coordinates are only comparable if they come from the same
|
296 | * origin index.
|
297 | * - Failure may occur if the index is too far away from the origin
|
298 | * or if the index is on the other side of a pentagon.
|
299 | * - This function is experimental, and its output is not guaranteed
|
300 | * to be compatible across different versions of H3.
|
301 | * @static
|
302 | * @param {H3Index} origin Origin H3 index
|
303 | * @param {Object} coords Coordinates as an `{i, j}` pair
|
304 | * @return {H3Index} H3 index at the relative coordinates
|
305 | * @throws {Error} If the H3 index cannot be calculated
|
306 | */
|
307 | function experimentalLocalIjToH3(origin: H3Index, coords: any): H3Index;
|
308 | /**
|
309 | * Average hexagon area at a given resolution
|
310 | * @static
|
311 | * @param {Number} res Hexagon resolution
|
312 | * @param {String} unit Area unit (either UNITS.m2 or UNITS.km2)
|
313 | * @return {Number} Average area
|
314 | * @throws {Error} If the unit is invalid
|
315 | */
|
316 | function hexArea(res: number, unit: string): number;
|
317 | /**
|
318 | * Average hexagon edge length at a given resolution
|
319 | * @static
|
320 | * @param {Number} res Hexagon resolution
|
321 | * @param {String} unit Area unit (either UNITS.m or UNITS.km)
|
322 | * @return {Number} Average edge length
|
323 | * @throws {Error} If the unit is invalid
|
324 | */
|
325 | function edgeLength(res: number, unit: string): number;
|
326 | /**
|
327 | * The total count of hexagons in the world at a given resolution. Note that above
|
328 | * resolution 8 the exact count cannot be represented in a JavaScript 32-bit number,
|
329 | * so consumers should use caution when applying further operations to the output.
|
330 | * @static
|
331 | * @param {Number} res Hexagon resolution
|
332 | * @return {Number} Count
|
333 | */
|
334 | function numHexagons(res: number): number;
|
335 | /**
|
336 | * Get all H3 indexes at resolution 0. As every index at every resolution > 0 is
|
337 | * the descendant of a res 0 index, this can be used with h3ToChildren to iterate
|
338 | * over H3 indexes at any resolution.
|
339 | * @static
|
340 | * @return {H3Index[]} All H3 indexes at res 0
|
341 | */
|
342 | function getRes0Indexes(): H3Index[];
|
343 | /**
|
344 | * Get the twelve pentagon indexes at a given resolution.
|
345 | * @static
|
346 | * @param {Number} res Hexagon resolution
|
347 | * @return {H3Index[]} All H3 pentagon indexes at res
|
348 | */
|
349 | function getPentagonIndexes(res: number): H3Index[];
|
350 | /**
|
351 | * Convert degrees to radians
|
352 | * @static
|
353 | * @param {Number} deg Value in degrees
|
354 | * @return {Number} Value in radians
|
355 | */
|
356 | function degsToRads(deg: number): number;
|
357 | /**
|
358 | * Convert radians to degrees
|
359 | * @static
|
360 | * @param {Number} rad Value in radians
|
361 | * @return {Number} Value in degrees
|
362 | */
|
363 | function radsToDegs(rad: number): number;
|
364 | }
|
365 |
|
366 |
|