-
Notifications
You must be signed in to change notification settings - Fork 376
/
IsochroneRequest.java
276 lines (221 loc) 路 9.25 KB
/
IsochroneRequest.java
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/* This file is part of Openrouteservice.
*
* Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, see <https://www.gnu.org/licenses/>.
*/
package org.heigit.ors.isochrones;
import org.heigit.ors.common.ServiceRequest;
import org.heigit.ors.common.TravelRangeType;
import org.heigit.ors.common.TravellerInfo;
import org.heigit.ors.isochrones.statistics.StatisticsProviderConfiguration;
import org.heigit.ors.routing.RoutingProfileType;
import org.heigit.ors.routing.WeightingMethod;
import org.locationtech.jts.geom.Coordinate;
import java.util.*;
public class IsochroneRequest extends ServiceRequest {
private final List<TravellerInfo> travellers;
private String calcMethod;
private String units = null;
private String areaUnits = null;
private boolean includeIntersections = false;
private String[] attributes;
private float smoothingFactor = -1.0f;
private int maximumLocations;
private boolean allowComputeArea;
private int maximumIntervals;
private int maximumRangeDistanceDefault;
private Map<Integer, Integer> profileMaxRangeDistances;
private int maximumRangeDistanceDefaultFastisochrones;
private Map<Integer, Integer> profileMaxRangeDistancesFastisochrones;
private int maximumRangeTimeDefault;
private Map<Integer, Integer> profileMaxRangeTimes;
private int maximumRangeTimeDefaultFastisochrones;
private Map<Integer, Integer> profileMaxRangeTimesFastisochrones;
private Map<String, StatisticsProviderConfiguration> statsProviders;
public IsochroneRequest() {
travellers = new ArrayList<>();
}
public String getCalcMethod() {
return calcMethod;
}
public void setCalcMethod(String calcMethod) {
this.calcMethod = calcMethod;
}
public String getUnits() {
return units;
}
public String getAreaUnits() {
return areaUnits;
}
public void setUnits(String units) {
this.units = units.toLowerCase();
}
public void setAreaUnits(String areaUnits) {
this.areaUnits = areaUnits.toLowerCase();
}
public boolean isValid() {
return !travellers.isEmpty();
}
public String[] getAttributes() {
return attributes;
}
public void setAttributes(String[] attributes) {
this.attributes = attributes;
}
public boolean hasAttribute(String attr) {
if (attributes == null || attr == null)
return false;
for (String attribute : attributes)
if (attr.equalsIgnoreCase(attribute))
return true;
return false;
}
public boolean getIncludeIntersections() {
return includeIntersections;
}
public void setIncludeIntersections(boolean value) {
includeIntersections = value;
}
public Coordinate[] getLocations() {
return travellers.stream().map(TravellerInfo::getLocation).toArray(Coordinate[]::new);
}
public void setSmoothingFactor(float smoothingFactor) {
this.smoothingFactor = smoothingFactor;
}
public IsochroneSearchParameters getSearchParameters(int travellerIndex) {
TravellerInfo traveller = travellers.get(travellerIndex);
double[] ranges = traveller.getRanges();
// convert ranges in units to meters or seconds
if (!(units == null || "m".equalsIgnoreCase(units))) {
double scale = 1.0;
if (traveller.getRangeType() == TravelRangeType.DISTANCE) {
switch (units) {
default:
case "m":
break;
case "km":
scale = 1000;
break;
case "mi":
scale = 1609.34;
break;
}
}
if (scale != 1.0) {
for (int i = 0; i < ranges.length; i++)
ranges[i] = ranges[i] * scale;
}
}
IsochroneSearchParameters parameters = new IsochroneSearchParameters(travellerIndex, traveller.getLocation(), ranges);
parameters.setLocation(traveller.getLocation());
parameters.setRangeType(traveller.getRangeType());
parameters.setCalcMethod(calcMethod);
parameters.setAttributes(attributes);
parameters.setUnits(units);
parameters.setAreaUnits(areaUnits);
parameters.setRouteParameters(traveller.getRouteSearchParameters());
if ("destination".equalsIgnoreCase(traveller.getLocationType()))
parameters.setReverseDirection(true);
parameters.setSmoothingFactor(smoothingFactor);
parameters.setStatsProviders(statsProviders);
return parameters;
}
public List<TravellerInfo> getTravellers() {
return travellers;
}
public void addTraveller(TravellerInfo traveller) throws Exception {
if (traveller == null)
throw new Exception("'traveller' argument is null.");
travellers.add(traveller);
}
public Set<String> getProfilesForAllTravellers() {
Set<String> ret = new HashSet<>();
for (TravellerInfo traveller : travellers)
ret.add(RoutingProfileType.getName(traveller.getRouteSearchParameters().getProfileType()));
return ret;
}
public Set<String> getWeightingsForAllTravellers() {
Set<String> ret = new HashSet<>();
for (TravellerInfo traveller : travellers)
ret.add(WeightingMethod.getName(traveller.getRouteSearchParameters().getWeightingMethod()));
return ret;
}
public void setMaximumLocations(int maximumLocations) {
this.maximumLocations = maximumLocations;
}
public int getMaximumLocations() {
return maximumLocations;
}
public boolean isAllowComputeArea() {
return allowComputeArea;
}
public void setAllowComputeArea(boolean allowComputeArea) {
this.allowComputeArea = allowComputeArea;
}
public int getMaximumIntervals() {
return maximumIntervals;
}
public void setMaximumIntervals(int maximumIntervals) {
this.maximumIntervals = maximumIntervals;
}
public int getMaximumRangeDistanceDefault() {
return maximumRangeDistanceDefault;
}
public void setMaximumRangeDistanceDefault(int maximumRangeDistanceDefault) {
this.maximumRangeDistanceDefault = maximumRangeDistanceDefault;
}
public Map<Integer, Integer> getProfileMaxRangeDistances() {
return profileMaxRangeDistances;
}
public void setProfileMaxRangeDistances(Map<Integer, Integer> profileMaxRangeDistances) {
this.profileMaxRangeDistances = profileMaxRangeDistances;
}
public int getMaximumRangeDistanceDefaultFastisochrones() {
return maximumRangeDistanceDefaultFastisochrones;
}
public void setMaximumRangeDistanceDefaultFastisochrones(int maximumRangeDistanceDefaultFastisochrones) {
this.maximumRangeDistanceDefaultFastisochrones = maximumRangeDistanceDefaultFastisochrones;
}
public Map<Integer, Integer> getProfileMaxRangeDistancesFastisochrones() {
return profileMaxRangeDistancesFastisochrones;
}
public void setProfileMaxRangeDistancesFastisochrones(Map<Integer, Integer> profileMaxRangeDistancesFastisochrones) {
this.profileMaxRangeDistancesFastisochrones = profileMaxRangeDistancesFastisochrones;
}
public int getMaximumRangeTimeDefault() {
return maximumRangeTimeDefault;
}
public void setMaximumRangeTimeDefault(int maximumRangeTimeDefault) {
this.maximumRangeTimeDefault = maximumRangeTimeDefault;
}
public Map<Integer, Integer> getProfileMaxRangeTimes() {
return profileMaxRangeTimes;
}
public void setProfileMaxRangeTimes(Map<Integer, Integer> profileMaxRangeTimes) {
this.profileMaxRangeTimes = profileMaxRangeTimes;
}
public int getMaximumRangeTimeDefaultFastisochrones() {
return maximumRangeTimeDefaultFastisochrones;
}
public void setMaximumRangeTimeDefaultFastisochrones(int maximumRangeTimeDefaultFastisochrones) {
this.maximumRangeTimeDefaultFastisochrones = maximumRangeTimeDefaultFastisochrones;
}
public Map<Integer, Integer> getProfileMaxRangeTimesFastisochrones() {
return profileMaxRangeTimesFastisochrones;
}
public void setProfileMaxRangeTimesFastisochrones(Map<Integer, Integer> profileMaxRangeTimesFastisochrones) {
this.profileMaxRangeTimesFastisochrones = profileMaxRangeTimesFastisochrones;
}
public Map<String, StatisticsProviderConfiguration> getStatsProviders() {
return statsProviders;
}
public void setStatsProviders(Map<String, StatisticsProviderConfiguration> statsProviders) {
this.statsProviders = statsProviders;
}
}