use of gnu.trove.list.array.TLongArrayList in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method simplifyCoordinates.
private List<TLongArrayList> simplifyCoordinates(List<byte[]> rt) {
List<TLongArrayList> ct = new ArrayList<>();
for (byte[] coordinates : rt) {
TLongArrayList lst = new TLongArrayList();
int len = coordinates.length / 8;
for (int i = 0; i < len; i++) {
int x = Algorithms.parseIntFromBytes(coordinates, i * 8);
int y = Algorithms.parseIntFromBytes(coordinates, i * 8 + 4);
long clt = MapUtils.interleaveBits(x, y);
lst.add(clt);
}
if (lst.size() > 0) {
ct.add(lst);
}
}
// simple merge lines
boolean merged = true;
while (merged) {
merged = false;
for (int i = 0; i < ct.size() && !merged; i++) {
TLongArrayList head = ct.get(i);
for (int j = 0; j < ct.size() && !merged; j++) {
if (j != i) {
TLongArrayList tail = ct.get(j);
if (head.get(head.size() - 1) == tail.get(0)) {
head.addAll(tail.subList(1, tail.size()));
ct.remove(j);
merged = true;
}
}
}
}
}
Collections.sort(ct, new Comparator<TLongArrayList>() {
@Override
public int compare(TLongArrayList o1, TLongArrayList o2) {
long l1 = o1.size() > 0 ? o1.get(0) : 0;
long l2 = o1.size() > 0 ? o2.get(0) : 0;
return Algorithms.compare(l1, l2);
}
});
return ct;
}
use of gnu.trove.list.array.TLongArrayList in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method writeTransportRouteCoordinates.
private void writeTransportRouteCoordinates(List<byte[]> rt) throws IOException {
int pcalcx = 0;
int pcalcy = 0;
mapDataBuf.clear();
List<TLongArrayList> coordinates = simplifyCoordinates(rt);
for (int j = 0; j < coordinates.size(); j++) {
if (j > 0) {
writeRawVarint32(mapDataBuf, CodedOutputStream.encodeZigZag32(0));
writeRawVarint32(mapDataBuf, CodedOutputStream.encodeZigZag32(0));
}
TLongArrayList lst = coordinates.get(j);
for (int i = 0; i < lst.size(); i++) {
int x = (int) MapUtils.deinterleaveX(lst.get(i));
int y = (int) MapUtils.deinterleaveY(lst.get(i));
int tx = (x >> SHIFT_COORDINATES) - pcalcx;
int ty = (y >> SHIFT_COORDINATES) - pcalcy;
if (tx != 0 || ty != 0) {
writeRawVarint32(mapDataBuf, CodedOutputStream.encodeZigZag32(tx));
writeRawVarint32(mapDataBuf, CodedOutputStream.encodeZigZag32(ty));
}
pcalcx = pcalcx + tx;
pcalcy = pcalcy + ty;
}
}
}
use of gnu.trove.list.array.TLongArrayList in project OsmAnd-tools by osmandapp.
the class FixBasemapRoads method processWay.
private void processWay(Way way) {
String ref = way.getTag("ref");
if (way.getFirstNodeId() == way.getLastNodeId()) {
TLongArrayList connectionIds = new TLongArrayList(way.getNodeIds());
for (int i = 0; i < connectionIds.size(); i++) {
roundabouts.put(connectionIds.get(i), connectionIds);
}
return;
}
if (ref == null || ref.isEmpty()) {
ref = way.getTag("int_ref");
}
if (ref == null || ref.isEmpty()) {
ref = way.getTag("name");
} else {
// fix road inconsistency
ref = ref.replace('-', ' ');
if (ref.indexOf(';') != -1) {
ref = ref.substring(0, ref.indexOf(';'));
}
}
boolean adminLevel = false;
if (ref == null || ref.isEmpty()) {
ref = way.getTag("admin_level");
LatLon lt = way.getLatLon();
ref += ((int) MapUtils.getTileNumberY(4, lt.getLatitude())) + " " + ((int) MapUtils.getTileNumberX(4, lt.getLongitude()));
adminLevel = true;
}
if (ref == null || ref.isEmpty()) {
LatLon lt = way.getLatLon();
ref = ((int) MapUtils.getTileNumberY(6, lt.getLatitude())) + " " + ((int) MapUtils.getTileNumberX(6, lt.getLongitude()));
}
if (!roadInfoMap.containsKey(ref)) {
roadInfoMap.put(ref, new RoadInfo());
}
RoadInfo ri = roadInfoMap.get(ref);
ri.adminLevel = adminLevel;
ri.registerRoadLine(new RoadLine(way));
}
use of gnu.trove.list.array.TLongArrayList in project OsmAnd-tools by osmandapp.
the class ManyToOneRoadCalculation method calculateManyToMany.
private void calculateManyToMany(RoutingContext ctx, TLongObjectHashMap<ManyToManySegment> allSegments, List<ManyToManySegment> topIntersects, List<ManyToManySegment> bottomIntersects, int stop, final int sbottom) {
final GeneralRouter router = ctx.config.router;
float DISTANCE_THRESHOLD = 50000;
// TODO depth search from one top intersect
List<TLongArrayList> sets = new ArrayList<TLongArrayList>();
for (int i = 0; i < topIntersects.size(); i++) {
ManyToManySegment oneTop = topIntersects.get(i);
clearAllSegments(allSegments);
List<ManyToManySegment> finalSegmentResult = calculateOneToMany(allSegments, bottomIntersects, sbottom, router, oneTop);
for (ManyToManySegment fnsResult : finalSegmentResult) {
TLongArrayList set = convertToRoadIds(fnsResult, DISTANCE_THRESHOLD / router.getMaxDefaultSpeed());
combineWithLocal(sets, set);
}
System.out.println(oneTop.road.getHighway() + " " + oneTop.road.id + " " + oneTop.segmentIndex + " common ways=" + sets.size());
}
System.out.println(sets.size());
for (TLongArrayList s : sets) {
System.out.println(s);
}
}
use of gnu.trove.list.array.TLongArrayList in project Osmand by osmandapp.
the class BinaryInspector method printOsmMapDetails.
private void printOsmMapDetails(BinaryMapDataObject obj, StringBuilder b) {
boolean multipolygon = obj.getPolygonInnerCoordinates() != null && obj.getPolygonInnerCoordinates().length > 0;
boolean point = obj.getPointsLength() == 1;
StringBuilder tags = new StringBuilder();
int[] types = obj.getTypes();
for (int j = 0; j < types.length; j++) {
TagValuePair pair = obj.getMapIndex().decodeType(types[j]);
if (pair == null) {
throw new NullPointerException("Type " + types[j] + "was not found");
}
tags.append("\t<tag k='").append(pair.tag).append("' v='").append(quoteName(pair.value)).append("' />\n");
}
if (obj.getAdditionalTypes() != null && obj.getAdditionalTypes().length > 0) {
for (int j = 0; j < obj.getAdditionalTypes().length; j++) {
int addtype = obj.getAdditionalTypes()[j];
TagValuePair pair = obj.getMapIndex().decodeType(addtype);
if (pair == null) {
throw new NullPointerException("Type " + obj.getAdditionalTypes()[j] + "was not found");
}
tags.append("\t<tag k='").append(pair.tag).append("' v='").append(quoteName(pair.value)).append("' />\n");
}
}
TIntObjectHashMap<String> names = obj.getObjectNames();
if (names != null && !names.isEmpty()) {
int[] keys = names.keys();
for (int j = 0; j < keys.length; j++) {
TagValuePair pair = obj.getMapIndex().decodeType(keys[j]);
if (pair == null) {
throw new NullPointerException("Type " + keys[j] + "was not found");
}
String name = names.get(keys[j]);
name = quoteName(name);
tags.append("\t<tag k='").append(pair.tag).append("' v='").append(name).append("' />\n");
}
}
tags.append("\t<tag k=\'").append("original_id").append("' v='").append(obj.getId() >> (SHIFT_ID + 1)).append("'/>\n");
tags.append("\t<tag k=\'").append("osmand_id").append("' v='").append(obj.getId()).append("'/>\n");
if (point) {
float lon = (float) MapUtils.get31LongitudeX(obj.getPoint31XTile(0));
float lat = (float) MapUtils.get31LatitudeY(obj.getPoint31YTile(0));
b.append("<node id = '" + OSM_ID++ + "' version='1' lat='" + lat + "' lon='" + lon + "' >\n");
b.append(tags);
b.append("</node>\n");
} else {
TLongArrayList innerIds = new TLongArrayList();
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");
ids.add(id);
}
long outerId = printWay(ids, b, multipolygon ? null : tags);
if (multipolygon) {
int[][] polygonInnerCoordinates = obj.getPolygonInnerCoordinates();
for (int j = 0; j < polygonInnerCoordinates.length; j++) {
ids.clear();
for (int i = 0; i < polygonInnerCoordinates[j].length; i += 2) {
float lon = (float) MapUtils.get31LongitudeX(polygonInnerCoordinates[j][i]);
float lat = (float) MapUtils.get31LatitudeY(polygonInnerCoordinates[j][i + 1]);
int id = OSM_ID++;
b.append("<node id = '" + id + "' version='1' lat='" + lat + "' lon='" + lon + "' />\n");
ids.add(id);
}
innerIds.add(printWay(ids, b, null));
}
int id = OSM_ID++;
b.append("<relation id = '" + id + "' version='1'>\n");
b.append(tags);
b.append("\t<member type='way' role='outer' ref= '" + outerId + "'/>\n");
TLongIterator it = innerIds.iterator();
while (it.hasNext()) {
long ref = it.next();
b.append("<member type='way' role='inner' ref= '" + ref + "'/>\n");
}
b.append("</relation>\n");
}
}
}
Aggregations