/src/geos/include/geos/linearref/LengthLocationMap.h
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2011 Sandro Santilli <strk@kbt.io> |
7 | | * Copyright (C) 2005-2006 Refractions Research Inc. |
8 | | * Copyright (C) 2001-2002 Vivid Solutions Inc. |
9 | | * |
10 | | * This is free software; you can redistribute and/or modify it under |
11 | | * the terms of the GNU Lesser General Public Licence as published |
12 | | * by the Free Software Foundation. |
13 | | * See the COPYING file for more information. |
14 | | * |
15 | | ********************************************************************** |
16 | | * |
17 | | * Last port: linearref/LengthLocationMap.java r463 |
18 | | * |
19 | | **********************************************************************/ |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <geos/geom/Coordinate.h> |
24 | | #include <geos/geom/Geometry.h> |
25 | | #include <geos/linearref/LinearLocation.h> |
26 | | |
27 | | namespace geos { |
28 | | namespace linearref { // geos::linearref |
29 | | |
30 | | /** \brief |
31 | | * Computes the LinearLocation for a given length along a linear |
32 | | * [Geometry](@ref geom::Geometry). |
33 | | * |
34 | | * Negative lengths are measured in reverse from end of the linear geometry. |
35 | | * Out-of-range values are clamped. |
36 | | */ |
37 | | class LengthLocationMap { |
38 | | |
39 | | |
40 | | private: |
41 | | const geom::Geometry* linearGeom; |
42 | | |
43 | | LinearLocation getLocationForward(double length) const; |
44 | | |
45 | | LinearLocation resolveHigher(const LinearLocation& loc) const; |
46 | | |
47 | | public: |
48 | | |
49 | | // TODO: cache computed cumulative length for each vertex |
50 | | // TODO: support user-defined measures |
51 | | // TODO: support measure index for fast mapping to a location |
52 | | |
53 | | /** |
54 | | * \brief |
55 | | * Computes the LinearLocation for a |
56 | | * given length along a linear [Geometry](@ref geom::Geometry). |
57 | | * |
58 | | * @param linearGeom the linear geometry to use |
59 | | * @param length the length index of the location |
60 | | * @return the LinearLocation for the length |
61 | | */ |
62 | | static LinearLocation |
63 | | getLocation(const geom::Geometry* linearGeom, double length) |
64 | 0 | { |
65 | 0 | LengthLocationMap locater(linearGeom); |
66 | 0 | return locater.getLocation(length); |
67 | 0 | } |
68 | | |
69 | | /** |
70 | | * \brief |
71 | | * Computes the LinearLocation for a |
72 | | * given length along a linear [Geometry]. |
73 | | * |
74 | | * @param linearGeom the linear geometry to use |
75 | | * @param length the length index of the location |
76 | | * @param resolveLower if `true` lengths are resolved to the |
77 | | * lowest possible index |
78 | | * @return the LinearLocation for the length |
79 | | */ |
80 | | static LinearLocation |
81 | | getLocation(const geom::Geometry* linearGeom, double length, bool resolveLower) |
82 | 0 | { |
83 | 0 | LengthLocationMap locater(linearGeom); |
84 | 0 | return locater.getLocation(length, resolveLower); |
85 | 0 | } |
86 | | |
87 | | /** |
88 | | * Computes the length for a given LinearLocation |
89 | | * on a linear [Geometry](@ref geom::Geometry). |
90 | | * |
91 | | * @param linearGeom the linear geometry to use |
92 | | * @param loc the LinearLocation index of the location |
93 | | * @return the length for the LinearLocation |
94 | | */ |
95 | | static double getLength(const geom::Geometry* linearGeom, const LinearLocation& loc); |
96 | | |
97 | | LengthLocationMap(const geom::Geometry* linearGeom); |
98 | | |
99 | | /** |
100 | | * \brief |
101 | | * Compute the LinearLocation corresponding to a length. |
102 | | * |
103 | | * Negative lengths are measured in reverse from end of the linear geometry. |
104 | | * Out-of-range values are clamped. |
105 | | * Ambiguous indexes are resolved to the lowest possible location value, |
106 | | * depending on the value of `resolveLower`. |
107 | | * |
108 | | * @param length the length index |
109 | | * @param resolveLower if `true` lengths are resolved to the |
110 | | * lowest possible index |
111 | | * @return the corresponding LinearLocation |
112 | | */ |
113 | | LinearLocation getLocation(double length, bool resolveLower) const; |
114 | | |
115 | | /** |
116 | | * \brief |
117 | | * Compute the LinearLocation corresponding to a length. |
118 | | * |
119 | | * Negative lengths are measured in reverse from end of the linear geometry. |
120 | | * Out-of-range values are clamped. |
121 | | * Ambiguous indexes are resolved to the lowest possible location value. |
122 | | * |
123 | | * @param length the length index |
124 | | * @return the corresponding LinearLocation |
125 | | */ |
126 | | LinearLocation getLocation(double length) const; |
127 | | |
128 | | double getLength(const LinearLocation& loc) const; |
129 | | |
130 | | }; |
131 | | |
132 | | } // geos.linearref |
133 | | } // geos |
134 | | |