sharedstreets-conflator
v0.2.1
Published
SharedStreets Conflator
Downloads
2
Readme
SharedStreets Conflator
Install
$ yarn add sharedstreets-conflator
Process
- Load LineString GeoJSON data into conflator
- Iterate over SharedStreets Objects (only Geometry & Intersection at the moment)
- 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
$ 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
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:
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
Convert Shapefile to GeoJSON
With NodeJS we can convert an ESRI Shapefile with mbostock/shapefile
to GeoJSON.
Install shapefile
$ yarn global add shapefile
Using NodeJS/Javascript
import * as shapefile from "shapefile";
shapefile.read("example.shp").then(geojson => {
// SharedStreets Conflator inputs GeoJSON LineString FeatureCollection
});
Or via terminal (CLI)
$ 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)
{
"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
Table of Contents
conflator
SharedStreets Conflator
Parameters
geojson
(Feature<LineString> | FeatureCollection<LineString>) GeoJSON LineString Feature/FeatureCollectionoptions
Object Optional Parameters (optional, default{}
)options.zoom
number Zoom level given to calculate the ZXY tiles (optional, default12
)
Examples
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<(ConflatorGeometry | ConflatorIntersection)> Iterator of SharedStreets Objects
geometry
Process Geometry
Parameters
feature
Feature<LineString> GeoJSON LineString Featureoptions
(optional, default{zoom:12}
)
Examples
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<SharedStreetsGeometry> SharedStreetsGeometry Iterator
intersection
Process Intersection
Parameters
feature
Feature<LineString> GeoJSON LineString Featureoptions
(optional, default{zoom:12}
)
Examples
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<SharedStreetsIntersection> SharedStreetsIntersection Iterator
reference
Process Reference
Parameters
feature
Feature<LineString> GeoJSON LineString Featureoptions
(optional, default{zoom:12}
)
Examples
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<SharedStreetsRefrence> SharedStreetsReference Iterator