use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule in project Osmand by osmandapp.
the class BinaryInspector method printOsmRouteDetails.
private void printOsmRouteDetails(RouteDataObject obj, StringBuilder b) {
StringBuilder tags = new StringBuilder();
int[] types = obj.getTypes();
for (int j = 0; j < types.length; j++) {
RouteTypeRule rt = obj.region.quickGetEncodingRule(types[j]);
if (rt == null) {
throw new NullPointerException("Type " + types[j] + "was not found");
}
String value = quoteName(rt.getValue());
tags.append("\t<tag k='").append(rt.getTag()).append("' v='").append(value).append("' />\n");
}
TIntObjectHashMap<String> names = obj.getNames();
if (names != null && !names.isEmpty()) {
int[] keys = names.keys();
for (int j = 0; j < keys.length; j++) {
RouteTypeRule rt = obj.region.quickGetEncodingRule(keys[j]);
if (rt == null) {
throw new NullPointerException("Type " + keys[j] + "was not found");
}
String name = quoteName(names.get(keys[j]));
tags.append("\t<tag k='").append(rt.getTag()).append("' v='").append(name).append("' />\n");
}
}
tags.append("\t<tag k=\'").append("original_id").append("' v='").append(obj.getId() >> (SHIFT_ID)).append("'/>\n");
tags.append("\t<tag k=\'").append("osmand_id").append("' v='").append(obj.getId()).append("'/>\n");
TLongArrayList ids = new TLongArrayList();
for (int i = 0; i < obj.getPointsLength(); i++) {
float lon = (float) MapUtils.get31LongitudeX(obj.getPoint31XTile(i));
float lat = (float) MapUtils.get31LatitudeY(obj.getPoint31YTile(i));
int id = OSM_ID++;
b.append("\t<node id = '" + id + "' version='1' lat='" + lat + "' lon='" + lon + "' >\n");
if (obj.getPointNames(i) != null) {
String[] vs = obj.getPointNames(i);
int[] keys = obj.getPointNameTypes(i);
for (int j = 0; j < keys.length; j++) {
RouteTypeRule rt = obj.region.quickGetEncodingRule(keys[j]);
String name = quoteName(vs[j]);
tags.append("\t\t<tag k='").append(rt.getTag()).append("' v='").append(name).append("' />\n");
}
}
if (obj.getPointTypes(i) != null) {
int[] keys = obj.getPointTypes(i);
for (int j = 0; j < keys.length; j++) {
RouteTypeRule rt = obj.region.quickGetEncodingRule(keys[j]);
String value = quoteName(rt.getValue());
tags.append("\t\t<tag k='").append(rt.getTag()).append("' v='").append(value).append("' />\n");
}
}
b.append("\t</node >\n");
ids.add(id);
}
long idway = printWay(ids, b, tags);
if (obj.getRestrictionLength() > 0) {
for (int i = 0; i < obj.getRestrictionLength(); i++) {
long ld = obj.getRestrictionId(i);
String tp = MapRenderingTypes.getRestrictionValue(obj.getRestrictionType(i));
int id = OSM_ID++;
b.append("<relation id = '" + id + "' version='1'>\n");
b.append("\t<member ref='").append(idway).append("' role='from' type='way' />\n");
b.append("\t<tag k='").append("from_osmand_id").append("' v='").append(obj.getId()).append("' />\n");
b.append("\t<tag k='").append("from_id").append("' v='").append(obj.getId() >> SHIFT_ID).append("' />\n");
b.append("\t<tag k='").append("to_osmand_id").append("' v='").append(ld).append("' />\n");
b.append("\t<tag k='").append("to_id").append("' v='").append(ld >> SHIFT_ID).append("' />\n");
b.append("\t<tag k='").append("type").append("' v='").append("restriction").append("' />\n");
b.append("\t<tag k='").append("restriction").append("' v='").append(tp).append("' />\n");
b.append("</relation>\n");
}
}
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule in project Osmand by osmandapp.
the class WaypointHelper method calculateMostImportantAlarm.
public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc, boolean showCameras) {
float mxspeed = ro.getMaximumSpeed(ro.bearingVsRouteDirection(loc));
float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f;
AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta);
if (speedAlarm != null) {
getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), loc.getSpeed());
return speedAlarm;
}
for (int i = 0; i < ro.getPointsLength(); i++) {
int[] pointTypes = ro.getPointTypes(i);
RouteRegion reg = ro.region;
if (pointTypes != null) {
for (int r = 0; r < pointTypes.length; r++) {
RouteTypeRule typeRule = reg.quickGetEncodingRule(pointTypes[r]);
AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, 0, loc);
if (info != null) {
if (info.getType() != AlarmInfoType.SPEED_CAMERA || showCameras) {
long ms = System.currentTimeMillis();
if (ms - announcedAlarmTime > 50 * 1000) {
announcedAlarmTime = ms;
getVoiceRouter().announceAlarm(info, loc.getSpeed());
}
return info;
}
}
}
}
}
return null;
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule in project Osmand by osmandapp.
the class RouteDataObject method isStopApplicable.
public boolean isStopApplicable(boolean direction, int intId, int startPointInd, int endPointInd) {
int[] pt = getPointTypes(intId);
int sz = pt.length;
for (int i = 0; i < sz; i++) {
RouteTypeRule r = region.quickGetEncodingRule(pt[i]);
// Evaluate direction tag if present
if (r.getTag().equals("direction")) {
String dv = r.getValue();
if ((dv.equals("forward") && direction == true) || (dv.equals("backward") && direction == false)) {
return true;
} else if ((dv.equals("forward") && direction == false) || (dv.equals("backward") && direction == true)) {
return false;
}
}
// Tagging stop=all should be ok anyway, usually tagged on intersection node itself, so not needed here
// if (r.getTag().equals("stop") && r.getValue().equals("all")) {
// return true;
// }
}
// Heuristic fallback: Distance analysis for STOP with no recognized directional tagging:
// Mask STOPs closer to the start than to the end of the routing segment if it is within 50m of start, but do not mask STOPs mapped directly on start/end (likely intersection node)
double d2Start = distance(startPointInd, intId);
double d2End = distance(intId, endPointInd);
if ((d2Start < d2End) && d2Start != 0 && d2End != 0 && d2Start < 50) {
return false;
}
// No directional info detected
return true;
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule in project Osmand by osmandapp.
the class RouteDataObject method getMaximumSpeed.
public float getMaximumSpeed(boolean direction) {
int sz = types.length;
float maxSpeed = 0;
for (int i = 0; i < sz; i++) {
RouteTypeRule r = region.quickGetEncodingRule(types[i]);
if (r.isForward() != 0) {
if ((r.isForward() == 1) != direction) {
continue;
}
}
float mx = r.maxSpeed();
if (mx > 0) {
maxSpeed = mx;
// conditional has priority
if (r.conditional()) {
break;
}
}
}
return maxSpeed;
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule in project Osmand by osmandapp.
the class RouteDataObject method calculateHeightArray.
public float[] calculateHeightArray() {
if (heightDistanceArray != null) {
return heightDistanceArray;
}
int startHeight = Algorithms.parseIntSilently(getValue("osmand_ele_start"), HEIGHT_UNDEFINED);
int endHeight = Algorithms.parseIntSilently(getValue("osmand_ele_end"), startHeight);
if (startHeight == HEIGHT_UNDEFINED) {
heightDistanceArray = new float[0];
return heightDistanceArray;
}
heightDistanceArray = new float[2 * getPointsLength()];
double plon = 0;
double plat = 0;
float prevHeight = startHeight;
for (int k = 0; k < getPointsLength(); k++) {
double lon = MapUtils.get31LongitudeX(getPoint31XTile(k));
double lat = MapUtils.get31LatitudeY(getPoint31YTile(k));
if (k > 0) {
double dd = MapUtils.getDistance(plat, plon, lat, lon);
float height = HEIGHT_UNDEFINED;
if (k == getPointsLength() - 1) {
height = endHeight;
} else {
int[] tps = getPointTypes(k);
if (tps != null) {
for (int id : tps) {
RouteTypeRule rt = region.quickGetEncodingRule(id);
if (rt.getTag().equals("osmand_ele_asc")) {
height = (prevHeight + Float.parseFloat(rt.getValue()));
break;
} else if (rt.getTag().equals("osmand_ele_desc")) {
height = (prevHeight - Float.parseFloat(rt.getValue()));
break;
}
}
}
}
heightDistanceArray[2 * k] = (float) dd;
heightDistanceArray[2 * k + 1] = height;
if (height != HEIGHT_UNDEFINED) {
// interpolate undefined
double totalDistance = dd;
int startUndefined = k;
while (startUndefined - 1 >= 0 && heightDistanceArray[2 * (startUndefined - 1) + 1] == HEIGHT_UNDEFINED) {
startUndefined--;
totalDistance += heightDistanceArray[2 * (startUndefined)];
}
if (totalDistance > 0) {
double angle = (height - prevHeight) / totalDistance;
for (int j = startUndefined; j < k; j++) {
heightDistanceArray[2 * j + 1] = (float) ((heightDistanceArray[2 * j] * angle) + heightDistanceArray[2 * j - 1]);
}
}
prevHeight = height;
}
} else {
heightDistanceArray[0] = 0;
heightDistanceArray[1] = startHeight;
}
plat = lat;
plon = lon;
}
return heightDistanceArray;
}
Aggregations