# sharedstreets-conflator

> SharedStreets Conflator

Latest version **0.2.1** (published 2018-02-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install sharedstreets-conflator
pnpm add sharedstreets-conflator
yarn add sharedstreets-conflator
bun add sharedstreets-conflator
```

Provides the command `sharedstreets-conflator`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2018-02-20 |
| First published | 2018-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 29 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | SharedStreets |
| Maintainers | deniscarriere |

## Links

- npm: https://www.npmjs.com/package/sharedstreets-conflator
- Repository: https://github.com/sharedstreets/sharedstreets-conflator
- Homepage: https://github.com/sharedstreets/sharedstreets-conflator#readme
- Issues: https://github.com/sharedstreets/sharedstreets-conflator/issues
- npm.io page: https://npm.io/package/sharedstreets-conflator

## Dependencies (8)

- [meow](https://npm.io/package/meow.md) *
- [shapefile](https://npm.io/package/shapefile.md) *
- [@turf/helpers](https://npm.io/package/@turf/helpers.md) 6.x
- [sharedstreets](https://npm.io/package/sharedstreets.md) *
- [load-json-file](https://npm.io/package/load-json-file.md) *
- [global-mercator](https://npm.io/package/global-mercator.md) 3.x
- [write-json-file](https://npm.io/package/write-json-file.md) *
- [sharedstreets-types](https://npm.io/package/sharedstreets-types.md) *

## Recent versions

- 0.2.1 (latest) — 2018-02-20
- 0.2.0 — 2018-02-19
- 0.1.2 — 2018-02-17
- 0.1.1 — 2018-02-17

## README

# SharedStreets Conflator

## Install

```bash
$ yarn add sharedstreets-conflator
```

## Process

1.  Load LineString GeoJSON data into conflator
2.  Iterate over SharedStreets Objects (only Geometry & Intersection at the moment)
3.  Manipulate Conflator Objects by using `data`, `type`, `tile` components.

> SharedStreets Objects are streamed as each individual LineString is being processed.

## Example - CLI

**Install CLI globally**

```bash
$ yarn global add sharedstreets-conflator
```

**terminal**

```
Usage:
  $ sharedstreets-conflator <filepath>

Options:
  -o, --out <folder>      output folder name (default: "./")
  --zoom                  zoom level given to calculate the ZXY tiles (default: 12)

Examples:
  $ sharedstreets-conflator "example.shp" --out "./data"
```

The example Shapefile will not produce tiles in JSON format in the desired `./data` folder.

- `./data/example.12-1144-1494.geometry.json`
- `./data/example.12-1144-1494.intersection.json`
- `./data/example.12-1144-1494.reference.json`

## Example - Javascript/Node

```js
import conflator from 'sharedstreets-conflator';
import {lineString} from '@turf/helpers';

// Load custom GeoJSON data (Feature<LineString> or FeatureCollection<LineString>)
const geojson = lineString([[-76, 40], [-75, 38]]);

for (const value of conflator(geojson)) {
  console.log(value);
  value.data // => SharedStreets Object (Geometry | Intersection | Reference)
  value.type // => SharedStreets Type as String ("geometry", "intersection", "reference")
  value.tile // => XYZ Tile (ex: [180, 220, 12])
}
```

Another syntax approach when handling ES6 Iterators:

```js
const iterator = conflator(geojson);
while (true) {
  const {value, done} = iterator.next();
  if (done) { break; }
  value.data // => SharedStreets Object (Geometry | Intersection | Reference)
  value.type // => SharedStreets Type as String ("geometry", "intersection", "reference")
  value.tile // => XYZ Tile (ex: [180, 220, 12])
}
```

## Output

![image](https://user-images.githubusercontent.com/550895/36337312-620560d4-1361-11e8-92ec-93b1eb8fee1f.png)

## Convert Shapefile to GeoJSON

With NodeJS we can convert an ESRI Shapefile with [`mbostock/shapefile`](https://github.com/mbostock/shapefile) to GeoJSON.

**Install `shapefile`**

```bash
$ yarn global add shapefile
```

**Using NodeJS/Javascript**

```js
import * as shapefile from "shapefile";

shapefile.read("example.shp").then(geojson => {
  // SharedStreets Conflator inputs GeoJSON LineString FeatureCollection
});
```

**Or via terminal (CLI)**

```bash
$ shp2json --help

  Usage: shp2json [options] [file]

  Convert a Shapefile to GeoJSON.


  Options:

    -V, --version            output the version number
    -o, --out <file>         output file name; defaults to “-” for stdout (default: -)
    -n, --newline-delimited  output newline-delimited JSON
    -g, --geometry           output geometries (implies --ignore-properties)
    --ignore-properties      don’t read shapefile properties (.dbf)
    --encoding <encoding>    character encoding for shapefile properties (.dbf)
    --crs-name <name>        specify a named CRS for the output feature collection
    -h, --help               output usage information

$ shp2json example.shp --out example.geojson
```

## Typescript Config

**tsconfig.json** (target must equal ES6)

```js
{
  "compilerOptions": {
    /* Basic Options */
    "target": "es6",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */

    /* Strict Type-Checking Options */
    "strict": true,                           /* Enable all strict type-checking options. */

    /* Module Resolution Options */
    "esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
  }
}
```

## Considerations

-   Streaming Data using Iterators.
-   Saving Tilesets using `xyz` tile pattern.
-   FeatureCollection sets up a processing queue.
-   Atomic actions piped into a message queue.
-   stream queues need to spill to disk at various points in the process
-   Memory requirements to cache intermediate products
-   AWS message queues that buffer between lambdas processing the data
-   self-contained operation

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

-   [conflator](#conflator)
-   [geometry](#geometry)
-   [intersection](#intersection)
-   [reference](#reference)

### conflator

SharedStreets Conflator

**Parameters**

-   `geojson` **(Feature&lt;LineString> | FeatureCollection&lt;LineString>)** GeoJSON LineString Feature/FeatureCollection
-   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
    -   `options.zoom` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Zoom level given to calculate the ZXY tiles (optional, default `12`)

**Examples**

```javascript
import { lineString } from "@turf/helpers";
import * as sharedstreetsConflator from "sharedstreets-conflator";

// GeoJSON Data
const geojson = lineString([[110, 45], [115, 50], [120, 55]]);

// Iterate over SharedStreets Objects
for (const value of sharedstreetsConflator.conflator(geojson, {zoom: 12})) {
  value.data // => SharedStreets Object (Geometry | Intersection | Reference)
  value.type // => SharedStreets Type as String ("geometry", "intersection", "reference")
  value.tile // => XYZ Tile (ex: [180, 220, 12])
}
```

Returns **IterableIterator&lt;(ConflatorGeometry | ConflatorIntersection)>** Iterator of SharedStreets Objects

### geometry

Process Geometry

**Parameters**

-   `feature` **Feature&lt;LineString>** GeoJSON LineString Feature
-   `options`   (optional, default `{zoom:12}`)

**Examples**

```javascript
import { lineString } from "@turf/helpers";
import * as sharedstreetsConflator from "sharedstreets-conflator";

const feature = lineString([[110, 45], [115, 50], [120, 55]]);

for (const geom of sharedstreetsConflator.geometry(feature, {zoom: 12})) {
  geom; // => SharedStreetsGeometry
}
```

Returns **IterableIterator&lt;SharedStreetsGeometry>** SharedStreetsGeometry Iterator

### intersection

Process Intersection

**Parameters**

-   `feature` **Feature&lt;LineString>** GeoJSON LineString Feature
-   `options`   (optional, default `{zoom:12}`)

**Examples**

```javascript
import { lineString } from "@turf/helpers";
import * as sharedstreetsConflator from "sharedstreets-conflator";

const feature = lineString([[110, 45], [115, 50], [120, 55]]);

for (const intersect of sharedstreetsConflator.intersection(feature, {zoom: 12})) {
  intersect; // => SharedStreetsIntersection
}
```

Returns **IterableIterator&lt;SharedStreetsIntersection>** SharedStreetsIntersection Iterator

### reference

Process Reference

**Parameters**

-   `feature` **Feature&lt;LineString>** GeoJSON LineString Feature
-   `options`   (optional, default `{zoom:12}`)

**Examples**

```javascript
import { lineString } from "@turf/helpers";
import * as sharedstreetsConflator from "sharedstreets-conflator";

const feature = lineString([[110, 45], [115, 50], [120, 55]]);

for (const ref of sharedstreetsConflator.reference(feature, {zoom: 12})) {
  ref; // => SharedStreetsReference
}
```

Returns **IterableIterator&lt;SharedStreetsRefrence>** SharedStreetsReference Iterator

---
_Source: https://npm.io/package/sharedstreets-conflator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
