Search in sources :

Example 6 with CountryRule

use of com.graphhopper.routing.util.countryrules.CountryRule in project graphhopper by graphhopper.

the class OSMTollParser method handleWayTags.

@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, IntsRef relationFlags) {
    Toll toll;
    if (readerWay.hasTag("toll", "yes")) {
        toll = Toll.ALL;
    } else if (readerWay.hasTag(HGV_TAGS, Collections.singletonList("yes"))) {
        toll = Toll.HGV;
    } else if (readerWay.hasTag("toll", "no")) {
        toll = Toll.NO;
    } else {
        toll = Toll.MISSING;
    }
    CountryRule countryRule = readerWay.getTag("country_rule", null);
    if (countryRule != null)
        toll = countryRule.getToll(readerWay, TransportationMode.CAR, toll);
    tollEnc.setEnum(false, edgeFlags, toll);
    return edgeFlags;
}
Also used : CountryRule(com.graphhopper.routing.util.countryrules.CountryRule) Toll(com.graphhopper.routing.ev.Toll)

Example 7 with CountryRule

use of com.graphhopper.routing.util.countryrules.CountryRule in project graphhopper by graphhopper.

the class OSMReader method setArtificialWayTags.

/**
 * This method is called during the second pass of {@link WaySegmentParser} and provides an entry point to enrich
 * the given OSM way with additional tags before it is passed on to the tag parsers.
 */
protected void setArtificialWayTags(PointList pointList, ReaderWay way) {
    // Estimate length of ways containing a route tag e.g. for ferry speed calculation
    double firstLat = pointList.getLat(0), firstLon = pointList.getLon(0);
    double lastLat = pointList.getLat(pointList.size() - 1), lastLon = pointList.getLon(pointList.size() - 1);
    // we have to remove existing artificial tags, because we modify the way even though there can be multiple edges
    // per way. sooner or later we should separate the artificial ('edge') tags from the way, see discussion here:
    // https://github.com/graphhopper/graphhopper/pull/2457#discussion_r751155404
    way.removeTag("estimated_distance");
    double estimatedDist = distCalc.calcDist(firstLat, firstLon, lastLat, lastLon);
    way.setTag("estimated_distance", estimatedDist);
    way.removeTag("duration:seconds");
    if (way.getTag("duration") != null) {
        try {
            long dur = OSMReaderUtility.parseDuration(way.getTag("duration"));
            // Provide the duration value in seconds in an artificial graphhopper specific tag:
            way.setTag("duration:seconds", Long.toString(dur));
        } catch (Exception ex) {
            LOGGER.warn("Parsing error in way with OSMID=" + way.getId() + " : " + ex.getMessage());
        }
    }
    way.removeTag("country");
    way.removeTag("country_rule");
    way.removeTag("custom_areas");
    List<CustomArea> customAreas;
    if (areaIndex != null) {
        double middleLat;
        double middleLon;
        if (pointList.size() > 2) {
            middleLat = pointList.getLat(pointList.size() / 2);
            middleLon = pointList.getLon(pointList.size() / 2);
        } else {
            middleLat = (firstLat + lastLat) / 2;
            middleLon = (firstLon + lastLon) / 2;
        }
        customAreas = areaIndex.query(middleLat, middleLon);
    } else {
        customAreas = emptyList();
    }
    // special handling for countries: since they are built-in with GraphHopper they are always fed to the EncodingManager
    Country country = Country.MISSING;
    for (CustomArea customArea : customAreas) {
        Object countryCode = customArea.getProperties().get("ISO3166-1:alpha3");
        if (countryCode == null)
            continue;
        if (country != Country.MISSING)
            LOGGER.warn("Multiple countries found for way {}: {}, {}", way.getId(), country, countryCode);
        country = Country.valueOf(countryCode.toString());
    }
    way.setTag("country", country);
    if (countryRuleFactory != null) {
        CountryRule countryRule = countryRuleFactory.getCountryRule(country);
        if (countryRule != null)
            way.setTag("country_rule", countryRule);
    }
    // also add all custom areas as artificial tag
    way.setTag("custom_areas", customAreas);
}
Also used : CountryRule(com.graphhopper.routing.util.countryrules.CountryRule) Country(com.graphhopper.routing.ev.Country) CustomArea(com.graphhopper.routing.util.CustomArea) IOException(java.io.IOException)

Aggregations

CountryRule (com.graphhopper.routing.util.countryrules.CountryRule)7 ReaderWay (com.graphhopper.reader.ReaderWay)2 RoadAccess (com.graphhopper.routing.ev.RoadAccess)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)2 TransportationMode (com.graphhopper.routing.util.TransportationMode)2 Graph (com.graphhopper.storage.Graph)2 GraphBuilder (com.graphhopper.storage.GraphBuilder)2 IntsRef (com.graphhopper.storage.IntsRef)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 Test (org.junit.jupiter.api.Test)2 Country (com.graphhopper.routing.ev.Country)1 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)1 Toll (com.graphhopper.routing.ev.Toll)1 CustomArea (com.graphhopper.routing.util.CustomArea)1 IOException (java.io.IOException)1