← All procedures

geo.nearestOnLine

This function gives the nearest point of a line to a point: the distance, the distance along the line, and the side. For many points on one line, use `lineReference`. Its rules apply.

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

From the command line

$ mark geo nearestOnLine --line <any[][]> --point <object>

As data, in a program

{
  "$proc": ["geo", "nearestOnLine"],
  "input": { "line": [], "point": {} }
}

Input

FieldTypeRequiredDefaultDescription
lineany[][]yesThe positions of the line, two or more.
pointobjectyesThe point.
optionsobjectnoThe plane of the measures.

Output

FieldTypeRequiredDefaultDescription
pointobjectyesThe nearest point of the line.
metersnumberyesThe distance from the point to the line.
alongMetersnumberyesThe distance along the line from its first position to the nearest point.
sidenumber | number | numberyesThe side of the point against the segment of the nearest point. The sign is exact on the plane, from `orient2dSign` of `@mark1russell7/predicates`.
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "line": {
        "type": "array",
        "items": {
          "type": "array",
          "items": [
            {
              "type": "number"
            },
            {
              "type": "number"
            },
            {
              "type": "number"
            }
          ],
          "additionalItems": {},
          "minItems": 2
        },
        "description": "The positions of the line, two or more."
      },
      "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": {},
        "description": "The point."
      },
      "options": {
        "type": "object",
        "properties": {
          "projection": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "description": "The name of the projection, for the legend of a map."
              },
              "toPlane": {
                "type": "object",
                "properties": {
                  "$proc": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "input": {},
                  "$when": {
                    "type": "string",
                    "const": "$never"
                  }
                },
                "required": [
                  "$proc"
                ],
                "additionalProperties": {},
                "x-procedures-program": {
                  "params": [
                    "point"
                  ],
                  "inputs": [
                    {
                      "$ref": "#/$defs/LatLon"
                    }
                  ],
                  "output": {
                    "$ref": "#/$defs/PlanePoint"
                  }
                },
                "description": "This function gives the point on the plane for a point on the Earth."
              },
              "fromPlane": {
                "type": "object",
                "properties": {
                  "$proc": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "input": {},
                  "$when": {
                    "type": "string",
                    "const": "$never"
                  }
                },
                "required": [
                  "$proc"
                ],
                "additionalProperties": {},
                "x-procedures-program": {
                  "params": [
                    "point"
                  ],
                  "inputs": [
                    {
                      "$ref": "#/$defs/PlanePoint"
                    }
                  ],
                  "output": {
                    "$ref": "#/$defs/LatLon"
                  }
                },
                "description": "This function gives the point on the Earth for a point on the plane. The longitude of the result is normalized."
              },
              "scale": {
                "type": "object",
                "properties": {
                  "$proc": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "input": {},
                  "$when": {
                    "type": "string",
                    "const": "$never"
                  }
                },
                "required": [
                  "$proc"
                ],
                "additionalProperties": {},
                "x-procedures-program": {
                  "params": [
                    "point"
                  ],
                  "inputs": [
                    {
                      "$ref": "#/$defs/LatLon"
                    }
                  ],
                  "output": {
                    "$ref": "#/$defs/ProjectionScale"
                  }
                },
                "description": "This function gives the scale factors of the projection at a point on the Earth."
              }
            },
            "required": [
              "name",
              "toPlane",
              "fromPlane",
              "scale"
            ],
            "additionalProperties": {},
            "description": "The plane of the measures. The default is `azimuthalEquidistant` with the center at the first position of the line. Each length is in the metres of this plane."
          }
        },
        "additionalProperties": {},
        "description": "The plane of the measures."
      }
    },
    "required": [
      "line",
      "point"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "object",
    "properties": {
      "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": {},
        "description": "The nearest point of the line."
      },
      "meters": {
        "type": "number",
        "description": "The distance from the point to the line."
      },
      "alongMeters": {
        "type": "number",
        "description": "The distance along the line from its first position to the nearest point."
      },
      "side": {
        "anyOf": [
          {
            "type": "number",
            "const": -1
          },
          {
            "type": "number",
            "const": 0
          },
          {
            "type": "number",
            "const": 1
          }
        ],
        "description": "The side of the point against the segment of the nearest point. The sign is exact on the plane, from `orient2dSign` of `@mark1russell7/predicates`."
      }
    },
    "required": [
      "point",
      "meters",
      "alongMeters",
      "side"
    ],
    "additionalProperties": {}
  }
}