Output Data Structure
Relevant source files
The following files were used as context for generating this wiki page:
The Output Data Structure of the geo-path-reducer library represents a simplified geographic path. This structure is the result of applying the Douglas-Peucker algorithm to an input array of coordinates, reducing the number of points while maintaining the general shape of the original path within a specified tolerance (epsilon).
The primary purpose of this output is to provide a more lightweight version of spatial data, which is particularly useful for optimizing map rendering and reducing data transmission sizes in geographic information systems (GIS).
Sources: README.md:1-5, src/index.js:3-23
Simplified Point Structure
The output consists of a standard JavaScript Array containing point objects. Each object represents a geographic coordinate that has been retained by the simplification logic.
Point Object Properties
Every point in the output array adheres to a specific schema to ensure compatibility with mapping libraries and the internal distance calculation logic.
| Property | Type | Description |
|---|---|---|
lat | Number | Latitude of the point in decimal degrees. |
lng | Number | Longitude of the point in decimal degrees. |
Sources: README.md:23-28, src/distance.js:1-15
Recursive Path Construction
The final output structure is constructed through a recursive process. If the maximum perpendicular distance from a line segment to a point exceeds the epsilon threshold, the path is split and the results are concatenated.
The diagram above illustrates the logic flow that determines which points are included in the final output structure.
Sources: src/index.js:15-22
Composition Logic
The algorithm ensures that the output is a continuous path by carefully managing the concatenation of simplified sub-paths.
- Recursive Step: When a path is split at
index, the output is formed by taking thesimplifiedLeftarray (excluding its last point) and concatenating it with thesimplifiedRightarray. - Base Case: If no point exceeds the
epsilondistance, the output for that segment is reduced to only the start and end points:[points[0], points[n - 1]].
Sources: src/index.js:15-22
Data Calculation Context
The output data is derived from calculations performed on the input points. The distance metrics used to determine point inclusion are based on great-circle distance (Haversine formula).
Distance Metadata
While not explicitly part of the output object, these values determine the output structure:
| Element | Source | Calculation Basis |
|---|---|---|
| Earth Radius | src/distance.js | 6371 kilometers |
| Triangle Area | src/perpendicular-distance.js | Heron's formula based on $d_1, d_2, d_3$ |
| Perpendicular Height | src/perpendicular-distance.js | $(Area \times 2) / d_3$ |
Sources: src/distance.js:3-14, src/perpendicular-distance.js:4-10
Implementation Example
The following snippet demonstrates the transformation from a high-resolution input to the simplified output structure.
// Output structure example
[
{ lat: 37.7749, lng: -122.4194 }, // Start point
{ lat: 37.7769, lng: -121.4159 } // End point (if epsilon is large)
]
Sources: README.md:15-28, src/index.js:21-22
Conclusion
The Output Data Structure of geo-path-reducer is a streamlined array of latitude/longitude coordinate objects. By identifying and retaining only the most significant points via the Douglas-Peucker algorithm, the module produces a data structure that effectively balances spatial accuracy with computational efficiency.