gis-tools 1.14.1

A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<h1 style="text-align: center;">
  <div align="center">gis-tools</div>
</h1>

<p align="center">
  <a href="https://img.shields.io/github/actions/workflow/status/Open-S2/gis-tools/test.yml?logo=github">
    <img src="https://img.shields.io/github/actions/workflow/status/Open-S2/gis-tools/test.yml?logo=github" alt="GitHub Actions Workflow Status">
  </a>
  <a href="https://npmjs.org/package/gis-tools-ts">
    <img src="https://img.shields.io/npm/v/gis-tools-ts.svg?logo=npm&logoColor=white" alt="npm">
  </a>
  <a href="https://crates.io/crates/gis-tools">
    <img src="https://img.shields.io/crates/v/gis-tools.svg?logo=rust&logoColor=white" alt="crate">
  </a>
  <a href="https://www.npmjs.com/package/gis-tools-ts">
    <img src="https://img.shields.io/npm/dm/gis-tools-ts.svg" alt="downloads">
  </a>
  <a href="https://open-s2.github.io/gis-tools/">
    <img src="https://img.shields.io/badge/docs-typescript-yellow.svg" alt="docs-ts">
  </a>
  <a href="https://docs.rs/gis-tools">
    <img src="https://img.shields.io/badge/docs-rust-yellow.svg" alt="docs-rust">
  </a>
  <a href="https://coveralls.io/github/Open-S2/gis-tools?branch=master">
    <img src="https://coveralls.io/repos/github/Open-S2/gis-tools/badge.svg?branch=master" alt="code-coverage">
  </a>
  <a href="https://discord.opens2.com">
    <img src="https://img.shields.io/discord/953563031701426206?logo=discord&logoColor=white" alt="Discord">
  </a>
</p>

## About

A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.

## Features

Notable features of GIS-Tools are:

- πŸ”— Lightweight, fast, and memory efficient. `no_std` builds for Rust. Tree-shaking for Typescript.
- πŸ—ΊοΈ Full toolkit support for WGS84, Web Mercator, and S2 projections.
- 🌱 A large list of projections can be converted to/from one of the above 3 via Transformers.
- πŸ“¦ Build Vector Tiles, Raster Tiles, and Gridded Data Tiles. Vector supports 3 output formats (Mapbox Vector Tile, Open S2 Tiles, and Flat Open S2 Tiles).
- βœ… Most data structures support all projections, but primarily focus the big 3 states above. Also handle large data sets through working with the filesystem and mmap buffers.
- πŸ“– Contains **25** native GIS readers. The list of readers are: CSV, SVG, GBFS, GeoTIFF, GPX, GRIB2, GTFS, JPEG and JPEG2000, (Geo|S2)JSON, LineDelimted GeoJSON, GeoJSON Text Sequences, LAS, LAZ, NadGrids, NetCDF, OSM, (S2)PMTiles, S2Tiles, Shapefiles, raster and vector tiles, WKT, and XML.
- 🦺 Secure code where the only external dependency is [sharp](https://github.com/lovell/sharp) for local image processing, otherwise all code is written internally by Open S2 in Typescript. Rust requires a little more: [libm](https://github.com/rust-lang/libm), [half](https://docs.rs/half/latest/half/), [regex](https://github.com/rust-lang/regex), [serde](https://github.com/serde-rs/serde), [serde_json](https://github.com/serde-rs/json), and some optional std/wasm [memmap2](https://github.com/RazrFalcon/memmap2-rs), [image](https://github.com/image-rs/image), [flate2](https://github.com/rust-lang/flate2-rs) and [surf](https://github.com/http-rs/surf).
- 🧲 Full suite of tools for points, lines, polygons, greater-circle-arcs, predicates, and more.
- 🌌 Space specific tools for planets and satellite orbits.

## Goals

Making GIS data easy to parse and work with. One of the biggest issues in GIS right now is how segmented various niche tools are. The other issue is how most solutions to read GIS data are half baked, deprecated, or partially parse results that need to be transformed one more time to use them.

So this tool exists to make GIS tools simple to use, various data fast to parse, and transformed to usable projections without having to worry about the details.

Lastly the goal is for all code to be accessible to both the browser and locally. An example was the shapefile reader where it can pull from online data or handle extremely large data as well.

## Install

```bash
# NPM
npm install gis-tools-ts
# PNPM
pnpm add gis-tools-ts
# Yarn
yarn add gis-tools-ts
# Bun
bun add gis-tools-ts
# Deno
deno install gis-tools-ts

# Cargo
cargo add gis-tools
```

### CLI Install

You can read the docs on the [CLI here](/docs-ts/cli.md).

```bash
# NPM
npm install -g gis-tools-ts
# PNPM
pnpm add -g gis-tools-ts
# Yarn
yarn global add gis-tools-ts
# Bun
bun add -g gis-tools-ts
# Deno
deno install -g gis-tools-ts
```

## Components

> πŸ’‘ **NOTE:** The sizes are estimates and can change based on how you use them. Click the module link for documentation and more precise guides on file cost.

### Readers

Most readers are parsers that take `ReaderInputs` as an input. This is to ensure both browser and file inputs are supported. You can learn more about [readers here](/docs-ts/readers/reader.md).

| Module       |             Size             |                      <img width="550" height="0"> Description |
| :----------- | :--------------------------: | ------------------------------------------------------------: |
| [jpeg]       |   ![JPEG Badge][jpegBadge]   |                                         Read/parse JPEG data. |
| [jpeg2000]   |  ![JPEG2 Badge][jpeg2Badge]  |                                    Read/parse JPEG 2000 data. |
| [lanczos]    |   ![Lanc Badge][lancBadge]   |             Apply a Lanczos filter that downsamples an image. |
| [csv]        |    ![CSV Badge][csvBadge]    |                      CSV data reader with options on parsing. |
| [gbfs]       |   ![GBFS Badge][gbfsBadge]   |                  General Bikeshare Feed Specification reader. |
| [geotiff]    |  ![GTiff Badge][gtiffBadge]  |                 Geotiff image reader with projection support. |
| [gpx]        |    ![GPX Badge][gpxBadge]    |                                  GPX (xml based) data reader. |
| [grib2]      |  ![grib2 Badge][grib2Badge]  |                                           GRIB 2 data reader. |
| [gtfs]       |   ![gtfs Badge][gtfsBadge]   | General Transit Feed Specification. Both Static and Realtime. |
| [json]       |   ![JSON Badge][jsonBadge]   |                 JSON data reader with line delimiter support. |
| [las]        |    ![LAS Badge][lasBadge]    |                                              LAS data reader. |
| [laz]        |    ![LAZ Badge][lazBadge]    |                                        LASzipped data reader. |
| [nadgrid]    |  ![NGrid Badge][ngridBadge]  |                                         NAD Grid data reader. |
| [netcdf]     | ![NetCDF Badge][netcdfBadge] |                                           NetCDF data reader. |
| [osm]        |    ![OSM Badge][osmBadge]    |                                 OpenStreetMap PBF data reader |
| [pmtiles]    |    ![PMT Badge][pmtBadge]    |                                      (S2)PMTiles data reader. |
| [protobuf]   |  ![Proto Badge][protoBadge]  |                                  Protobuf data reader/writer. |
| [s2tiles]    |    ![S2T Badge][s2tBadge]    |                                          S2Tiles data reader. |
| [shapefile]  |  ![Shape Badge][shapeBadge]  |   Shapefile data reader supporting DBF and projections (PRJ). |
| [tileReader] |     ![TR Badge][trBadge]     |          Tile data reader, usually from a local input folder. |
| [wkt]        |    ![wkt Badge][wktBadge]    |                                  Well Known Text data reader. |
| [xml]        |    ![XML Badge][xmlBadge]    |                                              XML data reader. |

[jpeg]: /docs-ts/readers/image/jpeg.md
[jpegBadge]: /assets/badges/jpeg-gzip-cover.svg
[jpeg2000]: /docs-ts/readers/image/jpeg2000.md
[jpeg2Badge]: /assets/badges/jpeg2000-gzip-cover.svg
[lanczos]: /docs-ts/readers/image/lanczos.md
[lancBadge]: /assets/badges/lanczos-gzip-cover.svg
[csv]: /docs-ts/readers/csv.md
[csvBadge]: /assets/badges/csv-gzip-cover.svg
[gbfs]: /docs-ts/readers/gbfs.md
[gbfsBadge]: /assets/badges/gbfs-gzip-cover.svg
[geotiff]: /docs-ts/readers/geotiff.md
[gtiffBadge]: /assets/badges/geotiff-gzip-cover.svg
[gpx]: /docs-ts/readers/gpx.md
[gpxBadge]: /assets/badges/gpx-gzip-cover.svg
[grib2]: /docs-ts/readers/grib2.md
[grib2Badge]: /assets/badges/grib2-gzip-cover.svg
[gtfs]: /docs-ts/readers/gtfs.md
[gtfsBadge]: /assets/badges/gtfs-gzip-cover.svg
[json]: /docs-ts/readers/json.md
[jsonBadge]: /assets/badges/json-gzip-cover.svg
[las]: /docs-ts/readers/las.md
[lasBadge]: /assets/badges/las-gzip-cover.svg
[laz]: /docs-ts/readers/laz.md
[lazBadge]: /assets/badges/laz-gzip-cover.svg
[nadgrid]: /docs-ts/readers/nadgrid.md
[ngridBadge]: /assets/badges/nadgrid-gzip-cover.svg
[netcdf]: /docs-ts/readers/netcdf.md
[netcdfBadge]: /assets/badges/netcdf-gzip-cover.svg
[osm]: /docs-ts/readers/osm.md
[osmBadge]: /assets/badges/osm-gzip-cover.svg
[pmtiles]: /docs-ts/readers/pmtiles.md
[pmtBadge]: /assets/badges/pmtilesReader-gzip-cover.svg
[protobuf]: /docs-ts/readers/protobuf.md
[protoBadge]: /assets/badges/protobuf-gzip-cover.svg
[s2tiles]: /docs-ts/readers/s2tiles.md
[s2tBadge]: /assets/badges/s2tiles-gzip-cover.svg
[shapefile]: /docs-ts/readers/shapefile.md
[shapeBadge]: /assets/badges/shapefile-gzip-cover.svg
[tileReader]: /docs-ts/readers/tile.md
[trBadge]: /assets/badges/tileReader-gzip-cover.svg
[wkt]: /docs-ts/readers/wkt.md
[wktBadge]: /assets/badges/wkt-gzip-cover.svg
[xml]: /docs-ts/readers/xml.md
[xmlBadge]: /assets/badges/xml-gzip-cover.svg

### Writers

| Module          |             Size              |                    <img width="550" height="0"> Description |
| :-------------- | :---------------------------: | ----------------------------------------------------------: |
| [csvWriter]     |   ![CSVW Badge][csvwBadge]    |                             Convert any Reader to CSV data. |
| [gpxWriter]     |   ![GPXW Badge][gpxwBadge]    |                             Convert any Reader to GPX data. |
| [pmtilesWriter] |   ![PMTW Badge][pmtwBadge]    |                                     Write (S2)PMTiles data. |
| [s2tilesWriter] |   ![S2TW Badge][s2twBadge]    |                                         Write S2Tiles data. |
| [shapefile]     |  ![Shape Badge][shapeBadge]   | Shapefile data reader supporting DBF and projections (PRJ). |
| [tileWriter]    |     ![TW Badge][twBadge]      |         Write (S2)Tiles data. Supports time series as well. |
| [toJSON]        | ![To JSON Badge][toJSONBadge] |                            Convert any Reader to JSON data. |
| [toTiles]       |   ![FT Badge][toTilesBadge]   |           Convert any Reader to vector and/or raster tiles. |

[csvWriter]: /docs-ts/writers/csv.md
[csvwBadge]: /assets/badges/csvWriter-gzip-cover.svg
[gpxWriter]: /docs-ts/writers/gpx.md
[gpxwBadge]: /assets/badges/gpxWriter-gzip-cover.svg
[pmtilesWriter]: /docs-ts/writers/pmtiles.md
[pmtwBadge]: /assets/badges/pmtilesWriter-gzip-cover.svg
[s2tilesWriter]: /docs-ts/writers/s2tiles.md
[s2twBadge]: /assets/badges/s2tilesWriter-gzip-cover.svg
[shapefile]: /docs-ts/writers/shapefile.md
[shapeBadge]: /assets/badges/shapefileWriter-gzip-cover.svg
[tileWriter]: /docs-ts/writers/tile.md
[twBadge]: /assets/badges/tileWriter-gzip-cover.svg
[toJSON]: /docs-ts/writers/toJSON.md
[toJSONBadge]: /assets/badges/toJSON-gzip-cover.svg
[toTiles]: /docs-ts/writers/toTiles.md
[toTilesBadge]: /assets/badges/toTiles-gzip-cover.svg

### Geometry

| Module       |             Size             |                   <img width="550" height="0"> Description |
| :----------- | :--------------------------: | ---------------------------------------------------------: |
| [angles]     | ![Angle Badge][anglesBadge]  |                          Spherical geodetic angle methods. |
| [bbox]       |   ![BBOX Badge][bboxBadge]   |                        Bounding box creation/manipulation. |
| [id]         |     ![ID Badge][idBadge]     |                                    ID tools for S2 and WM. |
| [lonlat]     | ![LonLat Badge][lonlanBadge] |                   Longitude/Latitude convienience methods. |
| [predicates] |   ![Pred Badge][predBadge]   | Reliability predicates for 2D and 3D orientation geometry. |
| [s2]         |     ![S2 Badge][s2Badge]     |                          S2 geometry convienience methods. |
| [tools]      |  ![Tools Badge][toolsBadge]  |                               Geometry manipulation tools. |
| [wm]         |     ![WM Badge][wmBadge]     |           Web Mercator (WM) geometry convienience methods. |

[angles]: /docs-ts/geometry/angles.md
[anglesBadge]: /assets/badges/angles-gzip-cover.svg
[bbox]: /docs-ts/geometry/bbox.md
[bboxBadge]: /assets/badges/bbox-gzip-cover.svg
[id]: /docs-ts/geometry/id.md
[idBadge]: /assets/badges/id-gzip-cover.svg
[lonlat]: /docs-ts/geometry/lonlat.md
[lonlanBadge]: /assets/badges/lonlat-gzip-cover.svg
[predicates]: /docs-ts/geometry/predicates.md
[predBadge]: /assets/badges/predicates-gzip-cover.svg
[s2]: /docs-ts/geometry/s2.md
[s2Badge]: /assets/badges/s2-gzip-cover.svg
[tools]: /docs-ts/geometry/tools.md
[toolsBadge]: /assets/badges/tools-gzip-cover.svg
[wm]: /docs-ts/geometry/wm.md
[wmBadge]: /assets/badges/wm-gzip-cover.svg

### PROJ4

| Module        |            Size            |                          <img width="550" height="0"> Description |
| :------------ | :------------------------: | ----------------------------------------------------------------: |
| [mgrs]        |  ![MGRS Badge][mgrsBadge]  |                  Military Grid Reference System (MGRS) converter. |
| [projections] |  ![Proj Badge][projBadge]  |  Supports a large list of projections to be used by transformers. |
| [transformer] | ![Trans Badge][transBadge] | Tool for transforming coordinates from one projection to another. |

[mgrs]: /docs-ts/proj4/mgrs.md
[mgrsBadge]: /assets/badges/mgrs-gzip-cover.svg
[projections]: /docs-ts/proj4/projections.md
[projBadge]: /assets/badges/projections-gzip-cover.svg
[transformer]: /docs-ts/proj4/transformer.md
[transBadge]: /assets/badges/transformer-gzip-cover.svg

### Data Stores

| Module         |          Size          |                      <img width="550" height="0"> Description |
| :------------- | :--------------------: | ------------------------------------------------------------: |
| [externalSort] |  ![ES Badge][esBadge]  |                             Sort large files with uint64 keys |
| [kv]           |  ![KV Badge][kvBadge]  | Key-Value store that works in the browser and the filesystem. |
| [multiMap]     |  ![MM Badge][mmBadge]  |       Multi-map that works in the browser and the filesystem. |
| [vector]       | ![Vec Badge][vecBadge] |    Vector store that works in the browser and the filesystem. |

[externalSort]: /docs-ts/dataStore/externalSort.md
[esBadge]: /assets/badges/externalSort-gzip-cover.svg
[kv]: /docs-ts/dataStore/kv.md
[kvBadge]: /assets/badges/kv-gzip-cover.svg
[multiMap]: /docs-ts/dataStore/multiMap.md
[mmBadge]: /assets/badges/multimap-gzip-cover.svg
[vector]: /docs-ts/dataStore/vector.md
[vecBadge]: /assets/badges/vector-gzip-cover.svg

### Data Structures

| Module           |            Size            |                         <img width="550" height="0"> Description |
| :--------------- | :------------------------: | ---------------------------------------------------------------: |
| [cache]          | ![Cache Badge][cacheBadge] | A KV cache for values with a max size. Least used dropped first. |
| [pointGrid]      |    ![PG Badge][pgBadge]    |                     Point grid tiling for number or raster data. |
| [pointCluster]   |    ![PC Badge][pcBadge]    |                                Point cluster tool with indexing. |
| [pointIndex]     |    ![PI Badge][piBadge]    |                        Point indexing with range/radius queries. |
| [pointIndexFast] |   ![PIF Badge][pifBadge]   |                 Faster point indexing with range/radius queries. |
| [priorityQueue]  |    ![PQ Badge][pqBadge]    |                                                A priority queue. |
| [splayTree]      |    ![ST Badge][stBadge]    |                  Self balancing binary tree with O(log n) access |
| [tile]           |  ![Tile Badge][tileBadge]  |                       A tile/layer management tool for features. |

[cache]: /docs-ts/dataStructures/cache.md
[cacheBadge]: /assets/badges/cache-gzip-cover.svg
[pointGrid]: /docs-ts/dataStructures/pointGrid.md
[pgBadge]: /assets/badges/pointGrid-gzip-cover.svg
[pointCluster]: /docs-ts/dataStructures/pointCluster.md
[pcBadge]: /assets/badges/pointCluster-gzip-cover.svg
[pointIndex]: /docs-ts/dataStructures/pointIndex.md
[piBadge]: /assets/badges/pointIndex-gzip-cover.svg
[pointIndexFast]: /docs-ts/dataStructures/pointIndexFast.md
[pifBadge]: /assets/badges/pointIndexFast-gzip-cover.svg
[priorityQueue]: /docs-ts/dataStructures/priorityQueue.md
[pqBadge]: /assets/badges/priorityQueue-gzip-cover.svg
[splayTree]: /docs-ts/dataStructures/splayTree.md
[stBadge]: /assets/badges/splayTree-gzip-cover.svg
[tile]: /docs-ts/dataStructures/tile.md
[tileBadge]: /assets/badges/dataTile-gzip-cover.svg

### Space

| Module      |             Size             |               <img width="550" height="0"> Description |
| :---------- | :--------------------------: | -----------------------------------------------------: |
| [planets]   | ![Planet Badge][planetBadge] | Collection of planet constants with observation tools. |
| [satellite] |    ![SAT Badge][satBadge]    |                    Satellite Orbit Class from TLE data |

[planets]: /docs-ts/space/planets.md
[planetBadge]: /assets/badges/planets-gzip-cover.svg
[satellite]: /docs-ts/space/satellite.md
[satBadge]: /assets/badges/sat-gzip-cover.svg

### Tools

| Module          |          Size           |                <img width="550" height="0"> Description |
| :-------------- | :---------------------: | ------------------------------------------------------: |
| [delaunator]    | ![DEL Badge][delBadge]  |                    Delaunay triangulation of 2D points. |
| [interpolators] | ![INT Badge][intBadge]  |             Interpolate values from points and weights. |
| [orthodrome]    | ![ORT Badge][orthBadge] | Find shortest path between two points or point on path. |
| [polylabel]     | ![POL Badge][polBadge]  |                     Find the labels for vector polygons |

[delaunator]: /docs-ts/tools/delaunator.md
[delBadge]: /assets/badges/delaunator-gzip-cover.svg
[interpolators]: /docs-ts/tools/interpolators.md
[intBadge]: /assets/badges/interpolators-gzip-cover.svg
[orthodrome]: /docs-ts/tools/orthodrome.md
[orthBadge]: /assets/badges/orthodrome-gzip-cover.svg
[polylabel]: /docs-ts/tools/polylabel.md
[polBadge]: /assets/badges/polylabel-gzip-cover.svg

### Utils

| Module        |          Size          |                      <img width="550" height="0"> Description |
| :------------ | :--------------------: | ------------------------------------------------------------: |
| [polyfills]   |  ![PF Badge][pfBadge]  | Collection of polyfills that might add value for the browser. |
| [compression] | ![CMP Badge][cmpBadge] |                compression/decompression convenience methods. |

[polyfills]: /docs-ts/util/polyfills.md
[pfBadge]: /assets/badges/polyfills-gzip-cover.svg
[compression]: /docs-ts/util/compression.md
[cmpBadge]: /assets/badges/compression-gzip-cover.svg

---

## Development

### Requirements

You need the tool `tarpaulin` to generate the coverage report. Install it using the following command:

```bash
cargo install cargo-tarpaulin
```

The `bacon coverage` tool is used to generate the coverage report. To utilize the [pycobertura](https://pypi.org/project/pycobertura/) package for a prettier coverage report, install it using the following command:

```bash
pip install pycobertura
```

### Running Tests

To run the tests, use the following command:

```bash
# TYPESCRIPT
## basic test
bun run test
## live testing
bun run test:dev

# RUST
## basic test
cargo test
# live testing
bacon test
```

### Running Linters and Coverage

```bash
# TYPESCRIPT LINT
bun run lint
#TYPESCRIPT COVERAGE
bun run test:coverage

# RUST LINT
# bun run rust:test:coverage
RUSTC_BOOTSTRAP=1 cargo +nightly clippy -- -D warnings
# RUST COVERAGE
# bun run rust:test:coverage
RUSTC_BOOTSTRAP=1 cargo +nightly llvm-cov --lcov --output-path coverage/lcov.info --workspace --features nightly
```

### Generating Coverage Report

To generate the coverage report, use the following command:

```bash
# install
cargo +stable install cargo-llvm-cov --locked
# run test
cargo llvm-cov
# bacon
bacon coverage # or type `l` inside the tool

# output lcov
cargo llvm-cov --lcov --output-path coverage/lcov.info
```

### Using Tokei

```bash
cargo install tokei
```