use of com.graphhopper.coll.GHIntHashSet in project graphhopper by graphhopper.
the class GraphEdgeIdFinder method parseStringHints.
/**
* This method reads string values from the hints about blocked areas and fills the configMap with either the
* created shapes or the found edges if area is small enough.
*/
public ConfigMap parseStringHints(ConfigMap configMap, HintsMap hints, EdgeFilter filter) {
final String objectSeparator = ";";
final String innerObjSep = ",";
// use shapes if bigger than 1km^2
final double shapeArea = 1000 * 1000;
final GHIntHashSet blockedEdges = new GHIntHashSet();
final List<Shape> blockedShapes = new ArrayList<>();
// Add blocked circular areas or points
String blockedCircularAreasStr = hints.get(BLOCK_AREA, "");
if (!blockedCircularAreasStr.isEmpty()) {
String[] blockedCircularAreasArr = blockedCircularAreasStr.split(objectSeparator);
for (int i = 0; i < blockedCircularAreasArr.length; i++) {
String objectAsString = blockedCircularAreasArr[i];
String[] splittedObject = objectAsString.split(innerObjSep);
if (splittedObject.length == 4) {
final BBox bbox = BBox.parseTwoPoints(objectAsString);
if (bbox.calculateArea() > shapeArea)
blockedShapes.add(bbox);
else
findEdgesInShape(blockedEdges, bbox, filter);
} else if (splittedObject.length == 3) {
double lat = Double.parseDouble(splittedObject[0]);
double lon = Double.parseDouble(splittedObject[1]);
int radius = Integer.parseInt(splittedObject[2]);
Circle circle = new Circle(lat, lon, radius);
if (circle.calculateArea() > shapeArea) {
blockedShapes.add(circle);
} else {
findEdgesInShape(blockedEdges, circle, filter);
}
} else if (splittedObject.length == 2) {
double lat = Double.parseDouble(splittedObject[0]);
double lon = Double.parseDouble(splittedObject[1]);
findClosestEdge(blockedEdges, lat, lon, filter);
} else {
throw new IllegalArgumentException(objectAsString + " at index " + i + " need to be defined as lat,lon " + "or as a circle lat,lon,radius or rectangular lat1,lon1,lat2,lon2");
}
}
}
configMap.put(BLOCKED_EDGES, blockedEdges);
configMap.put(BLOCKED_SHAPES, blockedShapes);
return configMap;
}
use of com.graphhopper.coll.GHIntHashSet in project graphhopper by graphhopper.
the class AbstractEdgeElevationInterpolator method interpolateEdge.
private void interpolateEdge(final EdgeIteratorState interpolatableEdge, final GHBitSet visitedEdgeIds, final EdgeExplorer edgeExplorer) {
final IntSet outerNodeIds = new GHIntHashSet();
final GHIntHashSet innerNodeIds = new GHIntHashSet();
gatherOuterAndInnerNodeIds(edgeExplorer, interpolatableEdge, visitedEdgeIds, outerNodeIds, innerNodeIds);
nodeElevationInterpolator.interpolateElevationsOfInnerNodes(outerNodeIds.toArray(), innerNodeIds.toArray());
}
use of com.graphhopper.coll.GHIntHashSet in project graphhopper by graphhopper.
the class ChangeGraphHelper method applyChange.
private long applyChange(JsonFeature jsonFeature, FlagEncoder encoder) {
long updates = 0;
EdgeFilter filter = new DefaultEdgeFilter(encoder);
GHIntHashSet edges = new GHIntHashSet();
if (jsonFeature.hasGeometry()) {
graphBrowser.fillEdgeIDs(edges, jsonFeature.getGeometry(), filter);
} else if (jsonFeature.getBBox() != null) {
graphBrowser.findEdgesInShape(edges, jsonFeature.getBBox(), filter);
} else
throw new IllegalArgumentException("Feature " + jsonFeature.getId() + " has no geometry and no bbox");
Iterator<IntCursor> iter = edges.iterator();
Map<String, Object> props = jsonFeature.getProperties();
while (iter.hasNext()) {
int edgeId = iter.next().value;
EdgeIteratorState edge = graph.getEdgeIteratorState(edgeId, Integer.MIN_VALUE);
if (props.containsKey("access")) {
boolean value = (boolean) props.get("access");
updates++;
if (enableLogging)
logger.info(encoder.toString() + " - access change via feature " + jsonFeature.getId());
edge.setFlags(encoder.setAccess(edge.getFlags(), value, value));
} else if (props.containsKey("speed")) {
// TODO use different speed for the different directions (see e.g. Bike2WeightFlagEncoder)
double value = ((Number) props.get("speed")).doubleValue();
double oldSpeed = encoder.getSpeed(edge.getFlags());
if (oldSpeed != value) {
updates++;
if (enableLogging)
logger.info(encoder.toString() + " - speed change via feature " + jsonFeature.getId() + ". Old: " + oldSpeed + ", new:" + value);
edge.setFlags(encoder.setSpeed(edge.getFlags(), value));
}
}
}
return updates;
}
use of com.graphhopper.coll.GHIntHashSet in project graphhopper by graphhopper.
the class LocationIndexTreeCHTest method testCHGraphBug.
@Test
public void testCHGraphBug() {
// 0
// |
// | X 2--3
// |
// 1
GraphHopperStorage g = createGHStorage(new RAMDirectory(), encodingManager, false);
NodeAccess na = g.getNodeAccess();
na.setNode(0, 1, 0);
na.setNode(1, 0, 0);
na.setNode(2, 0.5, 0.5);
na.setNode(3, 0.5, 1);
EdgeIteratorState iter1 = g.edge(1, 0, 100, true);
g.edge(2, 3, 100, true);
CHGraphImpl lg = (CHGraphImpl) g.getGraph(CHGraph.class);
g.freeze();
lg.setLevel(0, 11);
lg.setLevel(1, 10);
// disconnect higher 0 from lower 1
lg.disconnect(lg.createEdgeExplorer(), iter1);
lg.setLevel(2, 12);
lg.setLevel(3, 13);
// disconnect higher 3 from lower 2
lg.disconnect(lg.createEdgeExplorer(), iter1);
LocationIndexTree index = createIndex(g, 100000);
// very close to 2, but should match the edge 0--1
GHIntHashSet set = new GHIntHashSet();
index.findNetworkEntries(0.51, 0.2, set, 0);
index.findNetworkEntries(0.51, 0.2, set, 1);
IntSet expectedSet = new GHIntHashSet();
expectedSet.add(0);
expectedSet.add(2);
assertEquals(expectedSet, set);
assertEquals(0, findID(index, 0.51, 0.2));
assertEquals(1, findID(index, 0.1, 0.1));
assertEquals(2, findID(index, 0.51, 0.51));
assertEquals(3, findID(index, 0.51, 1.1));
}
use of com.graphhopper.coll.GHIntHashSet in project graphhopper by graphhopper.
the class GenericWeightingTest method testBlockedById.
@Test
public void testBlockedById() {
EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
ConfigMap cMap = encoder.readStringMap(new PMap());
Weighting instance = new GenericWeighting(encoder, cMap);
assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
GHIntHashSet blockedEdges = new GHIntHashSet(1);
cMap.put(BLOCKED_EDGES, blockedEdges);
blockedEdges.add(0);
instance = new GenericWeighting(encoder, cMap);
assertEquals(Double.POSITIVE_INFINITY, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}
Aggregations