Node.js & Javascript implementation of SharedStreets Reference System.
In Node.js
$ yarn add sharedstreets
CommonJS
const sharedstreets = require('sharedstreets');
Typescript
import * as sharedstreets from 'sharedstreets';
For a full list of web examples, check out SharedStreets examples.
$ git clone [email protected]:sharedstreets/sharedstreets-js.git
$ cd sharedstreets-js
$ yarn
$ yarn test
- geometryId
- geometry
- intersectionId
- intersection
- referenceId
- reference
- forwardReference
- backReference
- metadata
- outboundBearing
- inboundBearing
- distanceToNextRef
- lonlatsToCoords
- coordsToLonlats
- generateHash
- getRoadClassString
- getRoadClassNumber
- getFormOfWayString
- getFormOfWay
- getStartCoord
- getEndCoord
- getFormOfWayNumber
- getCoords
- round
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
Parameters
line
(Feature<LineString> | Array<Array<number>>) GeoJSON LineString Featureoptions
Object Optional parameters (optional, default{}
)
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
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
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
Reference Id
Parameters
locationReferences
Array<LocationReference> An Array of Location References.formOfWay
FormOfWay Form Of Way (optional, default0
)
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
Parameters
geom
SharedStreetsGeometry SharedStreets GeometrylocationReferences
Array<LocationReference> An Array of Location References.formOfWay
number Form Of Way (default Undefined) (optional, default0
)
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
Forward Reference
Parameters
line
(Feature<LineString> | Array<Array<number>>) GeoJSON LineString Feature or an Array of Positionsoptions
Object Optional parameters (optional, default{}
)
Examples
const line = [[110, 45], [115, 50], [120, 55]];
const ref = sharedstreets.forwardReference(line);
ref.id // => "3f652e4585aa7d7df3c1fbe4f55cea0a"
Returns SharedStreetsReference Forward SharedStreets Reference
Back Reference
Parameters
line
(Feature<LineString> | Array<Array<number>>) GeoJSON LineString Feature or an Array of Positionsoptions
Object Optional parameters (optional, default{}
)
Examples
const line = [[110, 45], [115, 50], [120, 55]];
const ref = sharedstreets.backReference(line);
ref.id // => "a18b2674e41cad630f5693154837baf4"
Returns SharedStreetsReference Back SharedStreets Reference
Metadata
Parameters
geom
SharedStreetsGeometry SharedStreets GeometryosmMetadata
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
Calculates outbound bearing from a LineString
Parameters
Examples
const line = [[110, 45], [115, 50], [120, 55]];
const outboundBearing = sharedstreets.outboundBearing(line);
outboundBearing; // => 208
Returns number Outbound Bearing
Calculates inbound bearing from a LineString
Parameters
Examples
const line = [[110, 45], [115, 50], [120, 55]];
const inboundBearing = sharedstreets.inboundBearing(line);
inboundBearing; // => 188
Returns number Inbound Bearing
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
Converts lonlats to GeoJSON LineString Coords
Parameters
Examples
const coords = lonlatsToCoords([110, 45, 120, 55]);
coords // => [[110, 45], [120, 55]]
Returns Array<Array<number>> GeoJSON LineString coordinates
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
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
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
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
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
Get FormOfWay from a GeoJSON LineString
Parameters
line
(Feature<LineString> | Array<Array<number>>) GeoJSON LineString Feature or an Array of Positionsoptions
Object Optional parameters (optional, default{}
)options.formOfWay
number Form of Way (optional, default0
)
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
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
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
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
Parameters
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 Number to 6 decimals
Parameters
Examples
sharedstreets.round(10.123456789) // => 10.123457
Returns string Big Number fixed string