use of com.graphhopper.routing.ev.Country in project graphhopper by graphhopper.
the class CountryParser method handleWayTags.
@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, IntsRef relationFlags) {
Country country = way.getTag("country", Country.MISSING);
countryEnc.setEnum(false, edgeFlags, country);
return edgeFlags;
}
use of com.graphhopper.routing.ev.Country 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);
}
Aggregations