npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sharedstreets-conflator

v0.2.1

Published

SharedStreets Conflator

Downloads

2

Readme

SharedStreets Conflator

Install

$ 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

$ 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

image

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/FeatureCollection
  • options Object Optional Parameters (optional, default {})
    • options.zoom number Zoom level given to calculate the ZXY tiles (optional, default 12)

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 Feature
  • options (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 Feature
  • options (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 Feature
  • options (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