Last active
August 29, 2015 14:18
-
-
Save dos65/574cc169a8630e0116e5 to your computer and use it in GitHub Desktop.
graphopper edgeFilter by azimuth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.graphhopper.util; | |
import com.graphhopper.routing.util.EdgeFilter; | |
import com.graphhopper.routing.util.FlagEncoder; | |
import com.graphhopper.storage.NodeAccess; | |
public class EdgeFilterDirection implements EdgeFilter{ | |
private final double azimuth; | |
private AngleCalc2D angleCalc = new AngleCalc2D(); | |
private final NodeAccess nodeAccess; | |
private final FlagEncoder encoder; | |
public EdgeFilterDirection(NodeAccess nodeAccess, FlagEncoder encoder ,double azimuth){ | |
this.azimuth = azimuth; | |
this.nodeAccess = nodeAccess; | |
this.encoder = encoder; | |
} | |
@Override | |
public boolean accept(EdgeIteratorState edge) { | |
if(Helper.isBidirect(encoder, edge.getFlags())) | |
return true; | |
double lat1 = nodeAccess.getLat(edge.getBaseNode()); | |
double lon1 = nodeAccess.getLon(edge.getBaseNode()); | |
double lat2 = nodeAccess.getLat(edge.getAdjNode()); | |
double lon2 = nodeAccess.getLon(edge.getAdjNode()); | |
double edgeAzimuth = angleCalc.calcAzimuth(lat1, lon1, lat2, lon2); | |
double min = edgeAzimuth - 90; | |
double max = edgeAzimuth + 90; | |
if(azimuth > min && azimuth < max) | |
return true; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment