← All procedures

geo.snapToRoad

This function connects a point to a road graph. It gives the nearest node, or a new node at the nearest point of an edge.

CLI
Package
@procedures/geo · README
Path
["geo","snapToRoad"]
CLI
mark geo snapToRoad --graph <object> --point <object>
As data
{"$proc":["geo","snapToRoad"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/geo/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["geo","snapToRoad"], { graph: {}, point: {} });
console.log(JSON.stringify(result));

From the command line

$ mark geo snapToRoad --graph <object> --point <object>

As data, in a program

{
  "$proc": ["geo", "snapToRoad"],
  "input": { "graph": {}, "point": {} }
}

Input

FieldTypeRequiredDefaultDescription
graphobjectyes
pointobjectyes
optionsobjectno

Output

The schema does not list fields (object | null).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "graph": {
        "type": "object",
        "properties": {
          "mode": {
            "type": "string"
          },
          "nodes": {
            "type": "array",
            "items": {
              "type": "array",
              "items": [
                {
                  "type": "string"
                },
                {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "point": {
                      "type": "object",
                      "properties": {
                        "lat": {
                          "type": "number",
                          "description": "The latitude in degrees, from -90 to 90."
                        },
                        "lon": {
                          "type": "number",
                          "description": "The longitude in degrees. A normalized longitude is from -180 to less than 180."
                        }
                      },
                      "required": [
                        "lat",
                        "lon"
                      ],
                      "additionalProperties": {}
                    }
                  },
                  "required": [
                    "id",
                    "point"
                  ],
                  "additionalProperties": {}
                }
              ],
              "additionalItems": {},
              "minItems": 2,
              "maxItems": 2
            },
            "x-procedures-codec": "map"
          },
          "edges": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "from": {
                  "type": "string"
                },
                "to": {
                  "type": "string"
                },
                "weight": {
                  "type": "number"
                },
                "meters": {
                  "type": "number",
                  "description": "The length of `line` on the sphere, from `distanceMeters`."
                },
                "line": {
                  "type": "array",
                  "items": {
                    "type": "array",
                    "items": [
                      {
                        "type": "number"
                      },
                      {
                        "type": "number"
                      },
                      {
                        "type": "number"
                      }
                    ],
                    "additionalItems": {},
                    "minItems": 2
                  },
                  "description": "The positions from the node `from` to the node `to`."
                },
                "feature": {
                  "type": "number",
                  "description": "The index of the feature of the way in the input."
                },
                "segment": {
                  "type": "number",
                  "description": "The number of the part of the way. The two directions of one part have the same number."
                }
              },
              "required": [
                "from",
                "to",
                "weight",
                "meters",
                "line",
                "feature",
                "segment"
              ],
              "additionalProperties": {}
            }
          }
        },
        "required": [
          "mode",
          "nodes",
          "edges"
        ],
        "additionalProperties": {}
      },
      "point": {
        "type": "object",
        "properties": {
          "lat": {
            "type": "number",
            "description": "The latitude in degrees, from -90 to 90."
          },
          "lon": {
            "type": "number",
            "description": "The longitude in degrees. A normalized longitude is from -180 to less than 180."
          }
        },
        "required": [
          "lat",
          "lon"
        ],
        "additionalProperties": {}
      },
      "options": {
        "type": "object",
        "properties": {
          "toleranceMeters": {
            "type": "number",
            "description": "The distance from an end of an edge in metres, within which the point goes to that end and not to a new node. The default is 0.5."
          },
          "id": {
            "type": "string",
            "description": "The identifier of a new node. The default is the key of its position, as the default key of `roadGraph`."
          }
        },
        "additionalProperties": {}
      }
    },
    "required": [
      "graph",
      "point"
    ],
    "additionalProperties": false
  },
  "output": {
    "anyOf": [
      {
        "type": "object",
        "properties": {
          "graph": {
            "type": "object",
            "properties": {
              "mode": {
                "type": "string"
              },
              "nodes": {
                "type": "array",
                "items": {
                  "type": "array",
                  "items": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "point": {
                          "type": "object",
                          "properties": {
                            "lat": {
                              "type": "number",
                              "description": "The latitude in degrees, from -90 to 90."
                            },
                            "lon": {
                              "type": "number",
                              "description": "The longitude in degrees. A normalized longitude is from -180 to less than 180."
                            }
                          },
                          "required": [
                            "lat",
                            "lon"
                          ],
                          "additionalProperties": {}
                        }
                      },
                      "required": [
                        "id",
                        "point"
                      ],
                      "additionalProperties": {}
                    }
                  ],
                  "additionalItems": {},
                  "minItems": 2,
                  "maxItems": 2
                },
                "x-procedures-codec": "map"
              },
              "edges": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "from": {
                      "type": "string"
                    },
                    "to": {
                      "type": "string"
                    },
                    "weight": {
                      "type": "number"
                    },
                    "meters": {
                      "type": "number",
                      "description": "The length of `line` on the sphere, from `distanceMeters`."
                    },
                    "line": {
                      "type": "array",
                      "items": {
                        "type": "array",
                        "items": [
                          {
                            "type": "number"
                          },
                          {
                            "type": "number"
                          },
                          {
                            "type": "number"
                          }
                        ],
                        "additionalItems": {},
                        "minItems": 2
                      },
                      "description": "The positions from the node `from` to the node `to`."
                    },
                    "feature": {
                      "type": "number",
                      "description": "The index of the feature of the way in the input."
                    },
                    "segment": {
                      "type": "number",
                      "description": "The number of the part of the way. The two directions of one part have the same number."
                    }
                  },
                  "required": [
                    "from",
                    "to",
                    "weight",
                    "meters",
                    "line",
                    "feature",
                    "segment"
                  ],
                  "additionalProperties": {}
                }
              }
            },
            "required": [
              "mode",
              "nodes",
              "edges"
            ],
            "additionalProperties": {},
            "description": "The graph with the new node and its edges. It is the input graph when the point goes to a node."
          },
          "node": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "point": {
                "type": "object",
                "properties": {
                  "lat": {
                    "type": "number",
                    "description": "The latitude in degrees, from -90 to 90."
                  },
                  "lon": {
                    "type": "number",
                    "description": "The longitude in degrees. A normalized longitude is from -180 to less than 180."
                  }
                },
                "required": [
                  "lat",
                  "lon"
                ],
                "additionalProperties": {}
              }
            },
            "required": [
              "id",
              "point"
            ],
            "additionalProperties": {},
            "description": "The node of the point: a node of the input graph, or a new node on an edge."
          },
          "meters": {
            "type": "number",
            "description": "The distance from the point to the node in metres."
          },
          "split": {
            "type": "boolean",
            "description": "True when the function cut an edge to add the node."
          }
        },
        "required": [
          "graph",
          "node",
          "meters",
          "split"
        ],
        "additionalProperties": {}
      },
      {
        "type": "null"
      }
    ]
  }
}