New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mapbox/graph-normalizer

Package Overview
Dependencies
Maintainers
181
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/graph-normalizer - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

lib/unidirectional-ways.js

4

index.js

@@ -5,8 +5,10 @@ 'use strict';

var splitWays = require('./lib/split-ways');
var unidirectionalWays = require('./lib/unidirectional-ways');
var graphNormalizer = {
mergeWays: mergeWays,
splitWays: splitWays
splitWays: splitWays,
unidirectionalWays: unidirectionalWays
};
module.exports = graphNormalizer;

@@ -5,2 +5,8 @@ 'use strict';

/**
* Given ways, split any ways that cross over an intersections
* @param {Object} ways an array of ways
* @param {Object} options an options object defining mergeHighways, mergeTunnels, and mergeBridges (all default to false)
* @return {Object} ways another array of ways
*/
module.exports = function (wayList, options) {

@@ -7,0 +13,0 @@ // default options

@@ -5,2 +5,7 @@ 'use strict';

/**
* Given ways, split any ways that cross over an intersections
* @param {Object} ways an array of ways
* @return {Object} ways another array of ways
*/
module.exports = function (ways) {

@@ -13,5 +18,5 @@ // construct node hash

way.properties.refs.forEach(function (ref) {
if (!nodeHash[ref]) nodeHash[ref] = {};
if (!nodeHash[ref]) nodeHash[ref] = 0;
nodeHash[ref][way.properties.id] = true;
nodeHash[ref] += 1;
});

@@ -33,3 +38,3 @@ });

// find the number of ways that contain the node
var ownerCount = Object.keys(nodeHash[ref]).length;
var ownerCount = nodeHash[ref];

@@ -36,0 +41,0 @@ // look for nodes with more than 1 owner

{
"name": "@mapbox/graph-normalizer",
"version": "3.0.0",
"version": "3.0.1",
"description": "Takes nodes and ways and turn them into a normalized graph of intersections and ways.",

@@ -11,3 +11,3 @@ "bin": "./bin/normalize-ways",

"scripts": {
"test": "npm run lint && tap test/*.test.js",
"test": "npm run lint && tap -R spec test/*.test.js",
"lint": "eslint '*.js' './**/*.js'",

@@ -32,3 +32,2 @@ "fix": "eslint --fix '*.js' './**/*.js'",

"through2": "^2.0.1",
"tile-cover": "^3.0.1",
"turf-linestring": "^1.0.2"

@@ -35,0 +34,0 @@ },

@@ -5,65 +5,68 @@ # Graph-normalizer

`graph-normalizer` is a JavaScript module that performs operations on an array of GeoJSON LineStrings representing OpenStreetMap ways. The operations performed cover a standard set of graph normalization techniques such as merging edges between intersections and splitting edges that cross over intersections. Ids assigned to ways in the normalized graph are deterministic and reproducible.
`graph-normalizer` is a Command Line Interface that pipes in a geojson file of ways (usually at the z7 level), and outputs normalized pieces of graph at a given zoom level.
### Installation
This package is intended as a utility for graph-tiler, but can be used on its own.
```sh
npm install @mapbox/graph-normlizer
```
### Installation
### Test
`npm install @mapbox/graph-normlizer`
```sh
npm test
```
### Usage
### Benchmark
```
node_modules/graph-normalizer/bin/normalize-ways \
--waysFile <geojson line-delimited ways file> \
--outputPath <output path> \
--zoomLevel <output zoom level - default 14> \
--mergeHighways <optional - merge ways with different highway tags - default false> \
--mergeTunnels <optional - merge ways with different tunnel tags - default false> \
--mergeBridges <optional - merge ways with different bridge tags - default false>
npm run bench
```
The output is a number of files, named `<quadkey>.json`, of line-delimited geojson way features.
### Use
It satisfies the following constraints:
- All way geometries in the original road network have an equivalent in the normalized graph.
- No intersection ever lies within a normalized way, only at its ends.
- Normalized way ids keep track of the history of transformations that led to it.
- `highway`, `oneway`, `bridge` and `tunnel` tags are conserved from the original graph by default.
- `highway`, `bridge` and `tunnel` tags can be merged using optional arguments. When merging different tags:
- `highway` tag is set as `unclassified`
- `tunnel` tag is set to `yes` i.e. we keep the info that there is a tunnel in the merged way
- `bridge` tag is set to `yes` i.e. we keep the info that there is a bridge in the merged way
```js
var normalizer = require('@mapbox/graph-normalizer');
Edges that are shared by multiple tiles are conserved in all of them.
var ways = require('./ways.json');
It is recommended to keep the output zoom level high, as performance might drop when trying to normalize at a larger scale.
var splitWays = normalizer.splitWays(ways);
var mergedWays = normalizer.mergeWays(ways);
### Algorithm
console.log(JSON.stringify(ways));
```
`graph-normalizer` expects geojson LineString features that have a `refs` property, each ref corresponding to the node id of the matching coordinates in the `geometry.coordinates` array.
### API
Any way that does not respect this constraint will be dropped.
#### splitWays(ways)
The algorithm follows this workflow:
Any ways that traverse an intersection are split in two. `!<i>` is appended to the way id where `i` is the index of the split way in the original geometry. Note that `!0` is appended to the way id if there is no split.
- **Indexing** - It loads the ways into memory and indexes their segments into the quadkey(s) of the target zoom level in which they land.
#### mergeWays(ways)
- **Tiling** - For each quadkey, it reconstructs each way from its segments. The segments of the original way that do not intersect with the tile are effectively dropped from this tile. Conversely, any segment that overlaps multiple tiles will be duplicated in all tiles.
Ways that share a node which is not an intersection (only 2 way owners) are merged together. The resulting id is `<wayOne>,<wayTwo>`.
- **Splitting** - Having the ways from each quadkey, `graph-normalizer` then splits the ways that traverse an intersection into two. `!<i>` is appended to the way id where `i` is the index of the split way in the original geometry.
### Input format
- **Merging** - Ways that share a node which is not an intersection (only 2 way owners) are merged together. The resulting id is `<wayOne>,<wayTwo>`.
- An array of GeoJSON LineString Features
- Each feature must have a `refs` array signifying node Ids of the coordinates that make up the way used for topology construction
- Each feature must have an `id` property representing the OpenStreetMap id of the way
- Each feature must have a `highway` property representing the OpenStreetMap highway tag of the way
- Each feature must have a `oneway` property representing the OpenStreetMap oneway tag of the way
- the `oneway` property must be normalized to `0`, `1`, or `-1`
- `0` signifies a bidirectional way
- `1` signifies a oneway way traveling in coordinate order
- `-1` signifies a oneway way traveling in reverse coordinate order (this will be normalized to forward order `1`)
- graph-normalizer will not work with raw OpenStreetMap oneway values such as `yes`, or `no`
### Tests
### Misc
```
npm test
```
- All way geometries in the original road network have an equivalent in the normalized graph.
- No intersection ever lies within a normalized way, only at its ends.
- Normalized way ids keep track of the history of transformations that led to it.
- `highway`, `oneway`, `bridge` and `tunnel` tags are conserved from the original graph by default.
- `highway`, `bridge` and `tunnel` tags can be merged using optional arguments. When merging different tags:
- `highway` tag is set as `unclassified`
- `tunnel` tag is set to `yes` i.e. we keep the info that there is a tunnel in the merged way
- `bridge` tag is set to `yes` i.e. we keep the info that there is a bridge in the merged way
### Benchmarks
```
npm run bench
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc