← All procedures

geo.nearestNode

This function gives the node of a road graph that is nearest to a point, with the distance from `distanceMeters`. Two nodes at the same distance give the first in the order of `graph.nodes`.

CLI
Package
@procedures/geo · README
Path
["geo","nearestNode"]
CLI
mark geo nearestNode --graph <object> --point <object>
As data
{"$proc":["geo","nearestNode"],"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","nearestNode"], { graph: {}, point: {} });
console.log(JSON.stringify(result));

From the command line

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

As data, in a program

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

Input

FieldTypeRequiredDefaultDescription
graphobjectyes
pointobjectyes

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": {}
      }
    },
    "required": [
      "graph",
      "point"
    ],
    "additionalProperties": false
  },
  "output": {
    "anyOf": [
      {
        "type": "object",
        "properties": {
          "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": {}
          },
          "meters": {
            "type": "number",
            "description": "The distance from the point to the node, from `distanceMeters`."
          }
        },
        "required": [
          "node",
          "meters"
        ],
        "additionalProperties": {}
      },
      {
        "type": "null"
      }
    ]
  }
}