Skip to content

starry97/sharedstreets-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SharedStreets (Node.js & Javascript)

npm version Build Status

Node.js & Javascript implementation of SharedStreets Reference System.

Install

In Node.js

$ yarn add sharedstreets

CommonJS

const sharedstreets = require('sharedstreets');

Typescript

import * as sharedstreets from 'sharedstreets';

In Browser

For a full list of web examples, check out SharedStreets examples.

How to build

$ git clone [email protected]:sharedstreets/sharedstreets-js.git
$ cd sharedstreets-js
$ yarn
$ yarn test

API

Table of Contents

geometryId

Geometry Id

Parameters

  • line (Feature<LineString> | Array<Array<number>>) Line Geometry as a GeoJSON LineString or an Array of Positions Array<<longitude, latitude>>.

Examples

const id = sharedstreets.geometryId([[110, 45], [115, 50], [120, 55]]);
id // => "ce9c0ec1472c0a8bab3190ab075e9b21"

Returns string SharedStreets Geometry Id

geometry

geometry

Parameters

  • line (Feature<LineString> | Array<Array<number>>) GeoJSON LineString Feature
  • options Object Optional parameters (optional, default {})
    • options.formOfWay string? Property field that contains FormOfWay value (number/string).
    • options.roadClass string? Property field that contains RoadClass value (number/string).

Examples

const line = [[110, 45], [115, 50], [120, 55]];
const geom = sharedstreets.geometry(line);
geom.id; // => "ce9c0ec1472c0a8bab3190ab075e9b21"
geom.lonlats; // => [ 110, 45, 115, 50, 120, 55 ]

Returns SharedStreetsGeometry SharedStreets Geometry

intersectionId

Intersection Id

Parameters

  • pt (Feature<Point> | Array<number>) Point location reference as a GeoJSON Point or an Array of numbers <longitude, latitude>.

Examples

const id = sharedstreets.intersectionId([110, 45]);
id // => "71f34691f182a467137b3d37265cb3b6"

Returns string SharedStreets Intersection Id

intersection

Intersection

Parameters

  • pt (Feature<Point> | Array<number>) Point location reference as a GeoJSON Point or an Array of numbers <longitude, latitude>.
  • options Object Optional parameters (optional, default {})
    • options.nodeId string? Define NodeId for Intersection

Examples

const intersection = sharedstreets.intersection([110, 45]);
intersection.id // => "71f34691f182a467137b3d37265cb3b6"

Returns SharedStreetsIntersection SharedStreets Intersection

referenceId

Reference Id

Parameters

  • locationReferences Array<LocationReference> An Array of Location References.
  • formOfWay FormOfWay Form Of Way (optional, default 0)

Examples

const locationReferences = [
  sharedstreets.locationReference([-74.0048213, 40.7416415], {outboundBearing: 208, distanceToNextRef: 9279}),
  sharedstreets.locationReference([-74.0051265, 40.7408505], {inboundBearing: 188})
];
const formOfWay = 2; // => "MultipleCarriageway"

const id = sharedstreets.referenceId(locationReferences, formOfWay);
id // => "ef209661aeebadfb4e0a2cb93153493f"

Returns string SharedStreets Reference Id

reference

Reference

Parameters

  • geom SharedStreetsGeometry SharedStreets Geometry
  • locationReferences Array<LocationReference> An Array of Location References.
  • formOfWay number Form Of Way (default Undefined) (optional, default 0)

Examples

const line = [[110, 45], [115, 50], [120, 55]];
const geom = sharedstreets.geometry(line);
const locationReferences = [
  sharedstreets.locationReference([-74.0048213, 40.7416415], {outboundBearing: 208, distanceToNextRef: 9279}),
  sharedstreets.locationReference([-74.0051265, 40.7408505], {inboundBearing: 188}),
];
const formOfWay = 2; // => "MultipleCarriageway"
const ref = sharedstreets.reference(geom, locationReferences, formOfWay);
ref.id // => "ef209661aeebadfb4e0a2cb93153493f"

Returns SharedStreetsReference SharedStreets Reference

forwardReference

Forward Reference

Parameters

  • line (Feature<LineString> | Array<Array<number>>) GeoJSON LineString Feature or an Array of Positions
  • options Object Optional parameters (optional, default {})
    • options.formOfWay (number | string) Form of Way (default "Undefined") (optional, default 0)

Examples

const line = [[110, 45], [115, 50], [120, 55]];
const ref = sharedstreets.forwardReference(line);
ref.id // => "3f652e4585aa7d7df3c1fbe4f55cea0a"

Returns SharedStreetsReference Forward SharedStreets Reference

backReference

Back Reference

Parameters

  • line (Feature<LineString> | Array<Array<number>>) GeoJSON LineString Feature or an Array of Positions
  • options Object Optional parameters (optional, default {})
    • options.formOfWay (number | string) Form of Way (default "Undefined") (optional, default 0)

Examples

const line = [[110, 45], [115, 50], [120, 55]];
const ref = sharedstreets.backReference(line);
ref.id // => "a18b2674e41cad630f5693154837baf4"

Returns SharedStreetsReference Back SharedStreets Reference

metadata

Metadata

Parameters

  • geom SharedStreetsGeometry SharedStreets Geometry
  • osmMetadata OSMMetadata OSM Metadata (optional, default {})
  • gisMetadata Array<GISMetadata> GIS Metadata (optional, default [])

Examples

const line = [[110, 45], [115, 50], [120, 55]];
const geom = sharedstreets.geometry(line);
const metadata = sharedstreets.metadata(geom)

Returns SharedStreetsMetadata SharedStreets Metadata

outboundBearing

Calculates outbound bearing from a LineString

Parameters

  • line (Feature<LineString> | Array<Array<number>>) GeoJSON LineString or an Array of Positions

Examples

const line = [[110, 45], [115, 50], [120, 55]];
const outboundBearing = sharedstreets.outboundBearing(line);
outboundBearing; // => 208

Returns number Outbound Bearing

inboundBearing

Calculates inbound bearing from a LineString

Parameters

  • line (Feature<LineString> | Array<Array<number>>) GeoJSON LineString or an Array of Positions

Examples

const line = [[110, 45], [115, 50], [120, 55]];
const inboundBearing = sharedstreets.inboundBearing(line);
inboundBearing; // => 188

Returns number Inbound Bearing

distanceToNextRef

Calculates inbound bearing from a LineString

Parameters

  • start Coord GeoJSON Point or an Array of numbers [Longitude/Latitude]
  • end Coord GeoJSON Point or an Array of numbers [Longitude/Latitude]

Examples

const start = [110, 45];
const end = [120, 55];
const distanceToNextRef = sharedstreets.distanceToNextRef(start, end);
distanceToNextRef; // => 9279

Returns number Distance to next Ref in centimeters

lonlatsToCoords

Converts lonlats to GeoJSON LineString Coords

Parameters

  • lonlats Array<number> Single Array of paired longitudes & latitude

Examples

const coords = lonlatsToCoords([110, 45, 120, 55]);
coords // => [[110, 45], [120, 55]]

Returns Array<Array<number>> GeoJSON LineString coordinates

coordsToLonlats

Converts GeoJSON LineString Coords to lonlats

Parameters

Examples

const lonlats = coordsToLonlats([[110, 45], [120, 55]]);
lonlats // => [110, 45, 120, 55]

Returns Array<number> lonlats Single Array of paired longitudes & latitude

generateHash

Generates Base16 Hash

Parameters

  • message string Message to hash

Examples

const message = "Intersection -74.00482177734375 40.741641998291016";
const hash = sharedstreets.generateHash(message);
hash // => "69f13f881649cb21ee3b359730790bb9"

Returns string SharedStreets Reference ID

getRoadClassString

Get RoadClass from a Number to a String

Parameters

  • value number Number value [between 0-8]

Examples

sharedstreets.getRoadClassString(0); // => "Motorway"
sharedstreets.getRoadClassString(5); // => "Residential"

Returns string Road Class

getRoadClassNumber

Get RoadClass from a String to a Number

Parameters

  • value number String value ["Motorway", "Trunk", "Primary", etc...]

Examples

sharedstreets.getRoadClassNumber("Motorway"); // => 0
sharedstreets.getRoadClassNumber("Residential"); // => 5

Returns string Road Class

getFormOfWayString

Get FormOfWay from a GeoJSON LineString and/or Optional parameters

Parameters

  • value number Number value [between 0-7]

Examples

sharedstreets.getFormOfWayString(0); // => "Undefined"
sharedstreets.getFormOfWayString(5); // => "TrafficSquare"

Returns string Form of Way

getFormOfWay

Get FormOfWay from a GeoJSON LineString

Parameters

  • line (Feature<LineString> | Array<Array<number>>) GeoJSON LineString Feature or an Array of Positions
  • options Object Optional parameters (optional, default {})
    • options.formOfWay number Form of Way (optional, default 0)

Examples

const lineA = turf.lineString([[110, 45], [115, 50], [120, 55]], {formOfWay: 3});
const lineB = turf.lineString([[110, 45], [115, 50], [120, 55]]);
const lineC = turf.lineString([[110, 45], [115, 50], [120, 55]], {formOfWay: "Motorway"});

sharedstreets.getFormOfWay(lineA); // => 3
sharedstreets.getFormOfWay(lineB); // => 0
sharedstreets.getFormOfWay(lineC); // => 1

getStartCoord

Get Start Coordinate from a GeoJSON LineString

Parameters

  • line (Feature<LineString> | Array<Position>) GeoJSON LineString or an Array of Positiosn

Examples

const line = turf.lineString([[110, 45], [115, 50], [120, 55]]);
const start = sharedstreets.getStartCoord(line);
start // => [110, 45]

Returns Position Start Coordinate

getEndCoord

Get Start Coordinate from a GeoJSON LineString

Parameters

  • line (Feature<LineString> | Array<Position>) GeoJSON LineString or an Array of Positiosn

Examples

const line = turf.lineString([[110, 45], [115, 50], [120, 55]]);
const end = sharedstreets.getEndCoord(line);
end // => [120, 55]

Returns Position Start Coordinate

getFormOfWayNumber

Get FormOfWay from a String to a Number

Parameters

  • value number String value [ex: "Undefined", "Motorway", etc...]

Examples

sharedstreets.getFormOfWayNumber("Undefined"); // => 0
sharedstreets.getFormOfWayNumber("TrafficSquare"); // => 5

Returns number Form of Way

getCoords

getCoords

Parameters

  • line (Feature<LineString> | Array<Array<number>>) GeoJSON LineString or an Array of positions

Examples

const line = turf.lineString([[110, 45], [115, 50], [120, 55]]);
const coords = sharedstreets.getCoords(line);
coords; // => [[110, 45], [115, 50], [120, 55]]

Returns Array<Array<number>> Array of positions

round

Round Number to 6 decimals

Parameters

  • num number Number to round
  • decimalPlaces number Decimal Places (optional, default 6)

Examples

sharedstreets.round(10.123456789) // => 10.123457

Returns string Big Number fixed string

About

SharedStreets (Node.js & Javascript)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%