Skip to content

Commit c9d85e6

Browse files
committed
Rename Development -> UrbanDensity (graphhopper#2637)
1 parent a615a6b commit c9d85e6

File tree

7 files changed

+64
-64
lines changed

7 files changed

+64
-64
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- don't allow cars or motorcycles to use ways tagged with service=emergency_access (#2484)
1414
- faster flexible routing, especially in conjunction with turn costs (#2571)
1515
- negative OSM Ids are not supported any longer (#2652)
16-
- new development encoded value based on road density (#2637)
16+
- new urban_density encoded value based on road density calculation (#2637)
1717

1818
### 5.0 [23 Mar 2022]
1919

config-example.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,19 @@ graphhopper:
109109
# elevation and will remove the extra points that long edge sampling added
110110
# graph.elevation.way_point_max_distance: 10
111111

112-
#### Development (built-up areas) ####
112+
#### Urban density (built-up areas) ####
113113

114114

115-
# This feature allows classifying roads into 'rural', 'residential' and 'city' areas (encoded value 'development')
115+
# This feature allows classifying roads into 'rural', 'residential' and 'city' areas (encoded value 'urban_density')
116116
# Use 1 or more threads to enable the feature
117-
# graph.development.threads: 8
117+
# graph.urban_density.threads: 8
118118
# Use higher/lower sensitivities if too little/many roads fall into the according categories.
119119
# Using smaller radii will speed up the classification, but only change these values if you know what you are doing.
120120
# If you do not need the (rather slow) city classification set city_radius to zero.
121-
# graph.development.residential_radius: 300
122-
# graph.development.residential_sensitivity: 60
123-
# graph.development.city_radius: 2000
124-
# graph.development.city_sensitivity: 30
121+
# graph.urban_density.residential_radius: 300
122+
# graph.urban_density.residential_sensitivity: 60
123+
# graph.urban_density.city_radius: 2000
124+
# graph.urban_density.city_sensitivity: 30
125125

126126

127127
#### Speed, hybrid and flexible mode ####

core/src/main/java/com/graphhopper/GraphHopper.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public class GraphHopper {
112112
private double residentialAreaSensitivity = 60;
113113
private double cityAreaRadius = 2000;
114114
private double cityAreaSensitivity = 30;
115-
private int developmentCalculationThreads = 0;
115+
private int urbanDensityCalculationThreads = 0;
116116

117117
// preparation handlers
118118
private final LMPreparationHandler lmPreparationHandler = new LMPreparationHandler();
@@ -195,7 +195,7 @@ public GraphHopper setMinNetworkSize(int minNetworkSize) {
195195
}
196196

197197
/**
198-
* Configures the development classification. Each edge will be classified as 'rural','residential' or 'city', {@link Development}
198+
* Configures the urban density classification. Each edge will be classified as 'rural','residential' or 'city', {@link UrbanDensity}
199199
*
200200
* @param residentialAreaRadius in meters. The higher this value the longer the calculation will take and the bigger the area for
201201
* which the road density used to identify residential areas is calculated.
@@ -206,17 +206,17 @@ public GraphHopper setMinNetworkSize(int minNetworkSize) {
206206
* to skip the city classification.
207207
* @param cityAreaSensitivity Use this to find a trade-off between too many roads being classified as city (too high values)
208208
* and not enough roads being classified as city (too small values)
209-
* @param threads the number of threads used for the calculation. If this is zero the development
210-
* classification is skipped entirely
209+
* @param threads the number of threads used for the calculation. If this is zero the urban density
210+
* calculation is skipped entirely
211211
*/
212-
public GraphHopper setDevelopmentClassification(double residentialAreaRadius, double residentialAreaSensitivity,
213-
double cityAreaRadius, double cityAreaSensitivity, int threads) {
212+
public GraphHopper setUrbanDensityCalculation(double residentialAreaRadius, double residentialAreaSensitivity,
213+
double cityAreaRadius, double cityAreaSensitivity, int threads) {
214214
ensureNotLoaded();
215215
this.residentialAreaRadius = residentialAreaRadius;
216216
this.residentialAreaSensitivity = residentialAreaSensitivity;
217217
this.cityAreaRadius = cityAreaRadius;
218218
this.cityAreaSensitivity = cityAreaSensitivity;
219-
this.developmentCalculationThreads = threads;
219+
this.urbanDensityCalculationThreads = threads;
220220
return this;
221221
}
222222

@@ -571,12 +571,12 @@ public GraphHopper init(GraphHopperConfig ghConfig) {
571571
preciseIndexResolution = ghConfig.getInt("index.high_resolution", preciseIndexResolution);
572572
maxRegionSearch = ghConfig.getInt("index.max_region_search", maxRegionSearch);
573573

574-
// development calculation
575-
residentialAreaRadius = ghConfig.getDouble("graph.development.residential_radius", residentialAreaRadius);
576-
residentialAreaSensitivity = ghConfig.getDouble("graph.development.residential_sensitivity", residentialAreaSensitivity);
577-
cityAreaRadius = ghConfig.getDouble("graph.development.city_radius", cityAreaRadius);
578-
cityAreaSensitivity = ghConfig.getDouble("graph.development.city_sensitivity", cityAreaSensitivity);
579-
developmentCalculationThreads = ghConfig.getInt("graph.development.threads", developmentCalculationThreads);
574+
// urban density calculation
575+
residentialAreaRadius = ghConfig.getDouble("graph.urban_density.residential_radius", residentialAreaRadius);
576+
residentialAreaSensitivity = ghConfig.getDouble("graph.urban_density.residential_sensitivity", residentialAreaSensitivity);
577+
cityAreaRadius = ghConfig.getDouble("graph.urban_density.city_radius", cityAreaRadius);
578+
cityAreaSensitivity = ghConfig.getDouble("graph.urban_density.city_sensitivity", cityAreaSensitivity);
579+
urbanDensityCalculationThreads = ghConfig.getInt("graph.urban_density.threads", urbanDensityCalculationThreads);
580580

581581
// routing
582582
routerConfig.setMaxVisitedNodes(ghConfig.getInt(Routing.INIT_MAX_VISITED_NODES, routerConfig.getMaxVisitedNodes()));
@@ -592,7 +592,7 @@ public GraphHopper init(GraphHopperConfig ghConfig) {
592592
return this;
593593
}
594594

595-
private void buildEncodingManagerAndOSMParsers(String flagEncodersStr, String encodedValuesStr, String dateRangeParserString, boolean withDevelopment, Collection<Profile> profiles) {
595+
private void buildEncodingManagerAndOSMParsers(String flagEncodersStr, String encodedValuesStr, String dateRangeParserString, boolean withUrbanDensity, Collection<Profile> profiles) {
596596
Map<String, String> flagEncodersMap = new LinkedHashMap<>();
597597
for (String encoderStr : flagEncodersStr.split(",")) {
598598
String name = encoderStr.split("\\|")[0].trim();
@@ -620,8 +620,8 @@ private void buildEncodingManagerAndOSMParsers(String flagEncodersStr, String en
620620
EncodingManager.Builder emBuilder = new EncodingManager.Builder();
621621
flagEncodersMap.forEach((name, encoderStr) -> emBuilder.add(vehicleEncodedValuesFactory.createVehicleEncodedValues(name, new PMap(encoderStr))));
622622
profiles.forEach(profile -> emBuilder.add(Subnetwork.create(profile.getName())));
623-
if (withDevelopment)
624-
emBuilder.add(Development.create());
623+
if (withUrbanDensity)
624+
emBuilder.add(UrbanDensity.create());
625625
encodedValueStrings.forEach(s -> emBuilder.add(encodedValueFactory.create(s)));
626626
encodingManager = emBuilder.build();
627627

@@ -780,8 +780,8 @@ public void importAndClose() {
780780
private void process(boolean closeEarly) {
781781
GHDirectory directory = new GHDirectory(ghLocation, dataAccessDefaultType);
782782
directory.configure(dataAccessConfig);
783-
boolean withDevelopment = developmentCalculationThreads > 0;
784-
buildEncodingManagerAndOSMParsers(flagEncodersString, encodedValuesString, dateRangeParserString, withDevelopment, profilesByName.values());
783+
boolean withUrbanDensity = urbanDensityCalculationThreads > 0;
784+
buildEncodingManagerAndOSMParsers(flagEncodersString, encodedValuesString, dateRangeParserString, withUrbanDensity, profilesByName.values());
785785
baseGraph = new BaseGraph.Builder(getEncodingManager())
786786
.setDir(directory)
787787
.set3D(hasElevation())
@@ -822,15 +822,15 @@ protected void postImport() {
822822
if (hasElevation())
823823
interpolateBridgesTunnelsAndFerries();
824824

825-
if (encodingManager.hasEncodedValue(Development.KEY)) {
826-
EnumEncodedValue<Development> developmentEnc = encodingManager.getEnumEncodedValue(Development.KEY, Development.class);
825+
if (encodingManager.hasEncodedValue(UrbanDensity.KEY)) {
826+
EnumEncodedValue<UrbanDensity> urbanDensityEnc = encodingManager.getEnumEncodedValue(UrbanDensity.KEY, UrbanDensity.class);
827827
if (!encodingManager.hasEncodedValue(RoadClass.KEY))
828-
throw new IllegalArgumentException("Development calculation requires " + RoadClass.KEY);
828+
throw new IllegalArgumentException("Urban density calculation requires " + RoadClass.KEY);
829829
if (!encodingManager.hasEncodedValue(RoadClassLink.KEY))
830-
throw new IllegalArgumentException("Development calculation requires " + RoadClassLink.KEY);
830+
throw new IllegalArgumentException("Urban density calculation requires " + RoadClassLink.KEY);
831831
EnumEncodedValue<RoadClass> roadClassEnc = encodingManager.getEnumEncodedValue(RoadClass.KEY, RoadClass.class);
832832
BooleanEncodedValue roadClassLinkEnc = encodingManager.getBooleanEncodedValue(RoadClassLink.KEY);
833-
DevelopmentCalculator.calcDevelopment(baseGraph, developmentEnc, roadClassEnc, roadClassLinkEnc, residentialAreaRadius, residentialAreaSensitivity, cityAreaRadius, cityAreaSensitivity, developmentCalculationThreads);
833+
UrbanDensityCalculator.calcUrbanDensity(baseGraph, urbanDensityEnc, roadClassEnc, roadClassLinkEnc, residentialAreaRadius, residentialAreaSensitivity, cityAreaRadius, cityAreaSensitivity, urbanDensityCalculationThreads);
834834
}
835835
}
836836

core/src/main/java/com/graphhopper/routing/ev/Development.java renamed to core/src/main/java/com/graphhopper/routing/ev/UrbanDensity.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818

1919
package com.graphhopper.routing.ev;
2020

21-
public enum Development {
21+
public enum UrbanDensity {
2222
RURAL("rural"), RESIDENTIAL("residential"), CITY("city");
2323

24-
public static EnumEncodedValue<Development> create() {
25-
return new EnumEncodedValue<>(KEY, Development.class);
24+
public static EnumEncodedValue<UrbanDensity> create() {
25+
return new EnumEncodedValue<>(KEY, UrbanDensity.class);
2626
}
2727

28-
public static final String KEY = "development";
28+
public static final String KEY = "urban_density";
2929

3030
private final String name;
3131

32-
Development(String name) {
32+
UrbanDensity(String name) {
3333
this.name = name;
3434
}
3535

core/src/main/java/com/graphhopper/routing/util/DevelopmentCalculator.java renamed to core/src/main/java/com/graphhopper/routing/util/UrbanDensityCalculator.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
package com.graphhopper.routing.util;
2020

2121
import com.graphhopper.routing.ev.BooleanEncodedValue;
22-
import com.graphhopper.routing.ev.Development;
2322
import com.graphhopper.routing.ev.EnumEncodedValue;
2423
import com.graphhopper.routing.ev.RoadClass;
24+
import com.graphhopper.routing.ev.UrbanDensity;
2525
import com.graphhopper.storage.Graph;
2626
import com.graphhopper.util.EdgeIteratorState;
2727
import com.graphhopper.util.StopWatch;
@@ -30,11 +30,11 @@
3030

3131
import java.util.function.ToDoubleFunction;
3232

33-
public class DevelopmentCalculator {
34-
private static final Logger logger = LoggerFactory.getLogger(RoadDensityCalculator.class);
33+
public class UrbanDensityCalculator {
34+
private static final Logger logger = LoggerFactory.getLogger(UrbanDensityCalculator.class);
3535

3636
/**
37-
* Calculates the development (rural/residential/city) for all edges of the graph.
37+
* Calculates the urban density (rural/residential/city) for all edges of the graph.
3838
* First a weighted road density is calculated for every edge to determine whether it belongs to a residential area.
3939
* In a second step very dense residential areas are classified as 'city'.
4040
*
@@ -45,24 +45,24 @@ public class DevelopmentCalculator {
4545
* @param cityAreaSensitivity similar to residentialAreaSensitivity, but for the city classification
4646
* @param threads number of threads used to calculate the road densities
4747
*/
48-
public static void calcDevelopment(Graph graph, EnumEncodedValue<Development> developmentEnc,
49-
EnumEncodedValue<RoadClass> roadClassEnc, BooleanEncodedValue roadClassLinkEnc,
50-
double residentialAreaRadius, double residentialAreaSensitivity,
51-
double cityAreaRadius, double cityAreaSensitivity,
52-
int threads) {
48+
public static void calcUrbanDensity(Graph graph, EnumEncodedValue<UrbanDensity> urbanDensityEnc,
49+
EnumEncodedValue<RoadClass> roadClassEnc, BooleanEncodedValue roadClassLinkEnc,
50+
double residentialAreaRadius, double residentialAreaSensitivity,
51+
double cityAreaRadius, double cityAreaSensitivity,
52+
int threads) {
5353
logger.info("Calculating residential areas ..., radius={}, sensitivity={}, threads={}", residentialAreaRadius, residentialAreaSensitivity, threads);
5454
StopWatch sw = StopWatch.started();
55-
calcResidential(graph, developmentEnc, roadClassEnc, roadClassLinkEnc, residentialAreaRadius, residentialAreaSensitivity, threads);
55+
calcResidential(graph, urbanDensityEnc, roadClassEnc, roadClassLinkEnc, residentialAreaRadius, residentialAreaSensitivity, threads);
5656
logger.info("Finished calculating residential areas, took: " + sw.stop().getSeconds() + "s");
5757
if (cityAreaRadius > 1) {
5858
logger.info("Calculating city areas ..., radius={}, sensitivity={}, threads={}", cityAreaRadius, cityAreaSensitivity, threads);
5959
sw = StopWatch.started();
60-
calcCity(graph, developmentEnc, cityAreaRadius, cityAreaSensitivity, threads);
60+
calcCity(graph, urbanDensityEnc, cityAreaRadius, cityAreaSensitivity, threads);
6161
logger.info("Finished calculating city areas, took: " + sw.stop().getSeconds() + "s");
6262
}
6363
}
6464

65-
private static void calcResidential(Graph graph, EnumEncodedValue<Development> developmentEnc,
65+
private static void calcResidential(Graph graph, EnumEncodedValue<UrbanDensity> urbanDensityEnc,
6666
EnumEncodedValue<RoadClass> roadClassEnc, BooleanEncodedValue roadClassLinkEnc,
6767
double radius, double sensitivity, int threads) {
6868
final ToDoubleFunction<EdgeIteratorState> calcRoadFactor = edge -> {
@@ -103,24 +103,24 @@ private static void calcResidential(Graph graph, EnumEncodedValue<Development> d
103103
isResidential[edge.getEdge()] = roadDensity * sensitivity >= 1.0;
104104
}, threads);
105105
for (int edge = 0; edge < isResidential.length; edge++)
106-
graph.getEdgeIteratorState(edge, Integer.MIN_VALUE).set(developmentEnc, isResidential[edge] ? Development.RESIDENTIAL : Development.RURAL);
106+
graph.getEdgeIteratorState(edge, Integer.MIN_VALUE).set(urbanDensityEnc, isResidential[edge] ? UrbanDensity.RESIDENTIAL : UrbanDensity.RURAL);
107107
}
108108

109-
private static void calcCity(Graph graph, EnumEncodedValue<Development> developmentEnc,
109+
private static void calcCity(Graph graph, EnumEncodedValue<UrbanDensity> urbanDensityEnc,
110110
double radius, double sensitivity, int threads) {
111-
// do not modify the development values as long as we are still reading them -> store city flags in this array first
111+
// do not modify the urban density values as long as we are still reading them -> store city flags in this array first
112112
boolean[] isCity = new boolean[graph.getEdges()];
113-
final ToDoubleFunction<EdgeIteratorState> calcRoadFactor = edge -> edge.get(developmentEnc) == Development.RESIDENTIAL ? 1 : 0;
113+
final ToDoubleFunction<EdgeIteratorState> calcRoadFactor = edge -> edge.get(urbanDensityEnc) == UrbanDensity.RESIDENTIAL ? 1 : 0;
114114
RoadDensityCalculator.calcRoadDensities(graph, (calculator, edge) -> {
115-
Development development = edge.get(developmentEnc);
116-
if (development == Development.RURAL)
115+
UrbanDensity urbanDensity = edge.get(urbanDensityEnc);
116+
if (urbanDensity == UrbanDensity.RURAL)
117117
return;
118118
double roadDensity = calculator.calcRoadDensity(edge, radius, calcRoadFactor);
119119
if (roadDensity * sensitivity >= 1.0)
120120
isCity[edge.getEdge()] = true;
121121
}, threads);
122122
for (int edge = 0; edge < isCity.length; edge++)
123123
if (isCity[edge])
124-
graph.getEdgeIteratorState(edge, Integer.MIN_VALUE).set(developmentEnc, Development.CITY);
124+
graph.getEdgeIteratorState(edge, Integer.MIN_VALUE).set(urbanDensityEnc, UrbanDensity.CITY);
125125
}
126126
}

web-bundle/src/main/java/com/graphhopper/resources/MVTResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Response doGetXyz(
9494
locationIndex.query(bbox, edgeId -> {
9595
EdgeIteratorState edge = graphHopper.getBaseGraph().getEdgeIteratorStateForKey(edgeId * 2);
9696
LineString lineString;
97-
if (pathDetails.contains(Development.KEY)) {
97+
if (pathDetails.contains(UrbanDensity.KEY)) {
9898
if (zInfo >= 9) {
9999
PointList pl = edge.fetchWayGeometry(FetchMode.ALL);
100100
lineString = pl.toLineString(false);

web-bundle/src/main/resources/com/graphhopper/maps/js/config/tileLayers.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ module.exports.enableVectorTiles = function () {
136136
},
137137
},
138138
})
139-
var developmentLayer = L.vectorGrid.protobuf("/mvt/{z}/{x}/{y}.mvt?details=max_speed&details=road_class&details=road_environment&details=development", {
139+
var urbanDensityLayer = L.vectorGrid.protobuf("/mvt/{z}/{x}/{y}.mvt?details=max_speed&details=road_class&details=road_environment&details=urban_density", {
140140
rendererFactory: L.canvas.tile,
141141
maxZoom: 20,
142142
minZoom: 10,
143143
interactive: true,
144144
vectorTileLayerStyles: {
145145
'roads': function (properties, zoom) {
146-
var rd = properties.development;
147-
let c = getDevelopmentColor(rd);
146+
var ud = properties.urban_density;
147+
let c = getUrbanDensityColor(ud);
148148
return {
149149
weight: 1 + c.weight,
150150
color: c.color,
@@ -153,7 +153,7 @@ module.exports.enableVectorTiles = function () {
153153
},
154154
},
155155
});
156-
var vtLayers = [vtLayer, developmentLayer];
156+
var vtLayers = [vtLayer, urbanDensityLayer];
157157
for (var i = 0; i < vtLayers.length; ++i) {
158158
vtLayers[i]
159159
.on('click', function (e) {
@@ -178,14 +178,14 @@ module.exports.enableVectorTiles = function () {
178178
}
179179
overlays = {
180180
"Local MVT": vtLayer,
181-
"Show Development": developmentLayer
181+
"Show Urban Density": urbanDensityLayer
182182
};
183183
}
184184

185-
function getDevelopmentColor(development) {
185+
function getUrbanDensityColor(urbanDensity) {
186186
var color = '#0aaff1';
187-
if (development === "residential") color = '#fd084a';
188-
else if (development === "city") color = '#edf259';
187+
if (urbanDensity === "residential") color = '#fd084a';
188+
else if (urbanDensity === "city") color = '#edf259';
189189
return {
190190
weight: 1,
191191
color: color

0 commit comments

Comments
 (0)