forked from libgeos/geos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLengthIndexedLine.cpp
166 lines (138 loc) · 4.33 KB
/
LengthIndexedLine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2011 Sandro Santilli <[email protected]>
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: linearref/LengthIndexedLine.java r463
*
**********************************************************************/
#include <geos/linearref/ExtractLineByLocation.h>
#include <geos/linearref/LengthIndexedLine.h>
#include <geos/linearref/LocationIndexedLine.h>
#include <geos/linearref/LinearLocation.h>
#include <geos/linearref/LengthLocationMap.h>
#include <geos/linearref/LengthIndexOfPoint.h>
#include <geos/linearref/LocationIndexOfLine.h>
using namespace geos::geom;
namespace geos {
namespace linearref { // geos.linearref
LengthIndexedLine::LengthIndexedLine(const Geometry* p_linearGeom) :
linearGeom(p_linearGeom) {}
Coordinate
LengthIndexedLine::extractPoint(double index) const
{
LinearLocation loc = LengthLocationMap::getLocation(linearGeom, index);
Coordinate coord = loc.getCoordinate(linearGeom);
return coord;
}
Coordinate
LengthIndexedLine::extractPoint(double index, double offsetDistance) const
{
LinearLocation loc = LengthLocationMap::getLocation(linearGeom, index);
Coordinate ret;
loc.getSegment(linearGeom)->pointAlongOffset(loc.getSegmentFraction(), offsetDistance, ret);
return ret;
}
std::unique_ptr<Geometry>
LengthIndexedLine::extractLine(double startIndex, double endIndex) const
{
const LocationIndexedLine lil(linearGeom);
const double startIndex2 = clampIndex(startIndex);
const double endIndex2 = clampIndex(endIndex);
// if extracted line is zero-length, resolve start lower as well to
// ensure they are equal
const bool resolveStartLower = (startIndex2 == endIndex2);
const LinearLocation startLoc = locationOf(startIndex2, resolveStartLower);
const LinearLocation endLoc = locationOf(endIndex2);
// LinearLocation std::endloc = locationOf(endIndex2, true);
// LinearLocation startLoc = locationOf(startIndex2);
return ExtractLineByLocation::extract(linearGeom, startLoc, endLoc);
}
LinearLocation
LengthIndexedLine::locationOf(double index) const
{
return LengthLocationMap::getLocation(linearGeom, index);
}
LinearLocation
LengthIndexedLine::locationOf(double index, bool resolveLower) const
{
return LengthLocationMap::getLocation(linearGeom, index, resolveLower);
}
double
LengthIndexedLine::indexOf(const Coordinate& pt) const
{
return LengthIndexOfPoint::indexOf(linearGeom, pt);
}
double
LengthIndexedLine::indexOfAfter(const Coordinate& pt, double minIndex) const
{
return LengthIndexOfPoint::indexOfAfter(linearGeom, pt, minIndex);
}
double*
LengthIndexedLine::indicesOf(const Geometry* subLine) const
{
LinearLocation* locIndex = LocationIndexOfLine::indicesOf(linearGeom, subLine);
double* index = new double[2];
index[0] = LengthLocationMap::getLength(linearGeom, locIndex[0]);
index[1] = LengthLocationMap::getLength(linearGeom, locIndex[1]);
delete [] locIndex;
return index;
}
double
LengthIndexedLine::project(const Coordinate& pt) const
{
return LengthIndexOfPoint::indexOf(linearGeom, pt);
}
double
LengthIndexedLine::getStartIndex() const
{
return 0.0;
}
double
LengthIndexedLine::getEndIndex() const
{
return linearGeom->getLength();
}
bool
LengthIndexedLine::isValidIndex(double index) const
{
return (index >= getStartIndex()
&& index <= getEndIndex());
}
/* public */
double
LengthIndexedLine::clampIndex(double index) const
{
double posIndex = positiveIndex(index);
double startIndex = getStartIndex();
if(posIndex < startIndex) {
return startIndex;
}
double endIndex = getEndIndex();
if(posIndex > endIndex) {
return endIndex;
}
return posIndex;
}
/* private */
double
LengthIndexedLine::positiveIndex(double index) const
{
if(index >= 0.0) {
return index;
}
return linearGeom->getLength() + index;
}
} // geos.linearref
} // geos