private TransportStop readTransportStop( int shift, int cleft, int cright, int ctop, int cbottom, SearchRequest<TransportStop> req) throws IOException { int tag = WireFormat.getTagFieldNumber(codedIS.readTag()); if (OsmandOdb.TransportStop.DX_FIELD_NUMBER != tag) { throw new IllegalArgumentException(); } int x = codedIS.readSInt32() + cleft; tag = WireFormat.getTagFieldNumber(codedIS.readTag()); if (OsmandOdb.TransportStop.DY_FIELD_NUMBER != tag) { throw new IllegalArgumentException(); } int y = codedIS.readSInt32() + ctop; if (req.right < x || req.left > x || req.top > y || req.bottom < y) { codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); return null; } req.numberOfAcceptedObjects++; req.cacheTypes.clear(); TransportStop dataObject = new TransportStop(); dataObject.setLocation( MapUtils.getLatitudeFromTile(TRANSPORT_STOP_ZOOM, y), MapUtils.getLongitudeFromTile(TRANSPORT_STOP_ZOOM, x)); dataObject.setFileOffset(shift); while (true) { int t = codedIS.readTag(); tag = WireFormat.getTagFieldNumber(t); switch (tag) { case 0: dataObject.setReferencesToRoutes(req.cacheTypes.toArray()); if (dataObject.getEnName().length() == 0) { dataObject.setEnName(Junidecode.unidecode(dataObject.getName())); } return dataObject; case OsmandOdb.TransportStop.ROUTES_FIELD_NUMBER: req.cacheTypes.add(shift - codedIS.readUInt32()); break; case OsmandOdb.TransportStop.NAME_EN_FIELD_NUMBER: dataObject.setEnName("" + ((char) codedIS.readUInt32())); // $NON-NLS-1$ break; case OsmandOdb.TransportStop.NAME_FIELD_NUMBER: int i = codedIS.readUInt32(); dataObject.setName("" + ((char) i)); // $NON-NLS-1$ break; case OsmandOdb.TransportStop.ID_FIELD_NUMBER: dataObject.setId(codedIS.readSInt64()); break; default: skipUnknownField(t); break; } } }
private TransportStop readTransportRouteStop(int dx, int dy, long did) throws IOException { TransportStop dataObject = new TransportStop(); boolean end = false; while (!end) { int t = codedIS.readTag(); int tag = WireFormat.getTagFieldNumber(t); switch (tag) { case 0: if (dataObject.getEnName().length() == 0) { dataObject.setEnName(Junidecode.unidecode(dataObject.getName())); } end = true; break; case OsmandOdb.TransportRouteStop.NAME_EN_FIELD_NUMBER: dataObject.setEnName("" + ((char) codedIS.readUInt32())); // $NON-NLS-1$ break; case OsmandOdb.TransportRouteStop.NAME_FIELD_NUMBER: dataObject.setName("" + ((char) codedIS.readUInt32())); // $NON-NLS-1$ break; case OsmandOdb.TransportRouteStop.ID_FIELD_NUMBER: did += codedIS.readSInt64(); break; case OsmandOdb.TransportRouteStop.DX_FIELD_NUMBER: dx += codedIS.readSInt32(); break; case OsmandOdb.TransportRouteStop.DY_FIELD_NUMBER: dy += codedIS.readSInt32(); break; default: skipUnknownField(t); break; } } dataObject.setId(did); dataObject.setLocation( MapUtils.getLatitudeFromTile(TRANSPORT_STOP_ZOOM, dy), MapUtils.getLongitudeFromTile(TRANSPORT_STOP_ZOOM, dx)); return dataObject; }
public net.osmand.data.TransportRoute getTransportRoute(int filePointer, TransportIndex ind) throws IOException { codedIS.seek(filePointer); int routeLength = codedIS.readRawVarint32(); int old = codedIS.pushLimit(routeLength); net.osmand.data.TransportRoute dataObject = new net.osmand.data.TransportRoute(); boolean end = false; int name = -1; int nameEn = -1; int operator = -1; int type = -1; long rid = 0; int rx = 0; int ry = 0; long did = 0; int dx = 0; int dy = 0; while (!end) { int t = codedIS.readTag(); int tag = WireFormat.getTagFieldNumber(t); switch (tag) { case 0: end = true; break; case OsmandOdb.TransportRoute.DISTANCE_FIELD_NUMBER: dataObject.setDistance(codedIS.readUInt32()); break; case OsmandOdb.TransportRoute.ID_FIELD_NUMBER: dataObject.setId(codedIS.readUInt64()); break; case OsmandOdb.TransportRoute.REF_FIELD_NUMBER: dataObject.setRef(codedIS.readString()); break; case OsmandOdb.TransportRoute.TYPE_FIELD_NUMBER: type = codedIS.readUInt32(); break; case OsmandOdb.TransportRoute.NAME_EN_FIELD_NUMBER: nameEn = codedIS.readUInt32(); break; case OsmandOdb.TransportRoute.NAME_FIELD_NUMBER: name = codedIS.readUInt32(); break; case OsmandOdb.TransportRoute.OPERATOR_FIELD_NUMBER: operator = codedIS.readUInt32(); break; case OsmandOdb.TransportRoute.REVERSESTOPS_FIELD_NUMBER: int length = codedIS.readRawVarint32(); int olds = codedIS.pushLimit(length); TransportStop stop = readTransportRouteStop(dx, dy, did); dataObject.getBackwardStops().add(stop); did = stop.getId(); dx = (int) MapUtils.getTileNumberX(TRANSPORT_STOP_ZOOM, stop.getLocation().getLongitude()); dy = (int) MapUtils.getTileNumberY(TRANSPORT_STOP_ZOOM, stop.getLocation().getLatitude()); codedIS.popLimit(olds); break; case OsmandOdb.TransportRoute.DIRECTSTOPS_FIELD_NUMBER: length = codedIS.readRawVarint32(); olds = codedIS.pushLimit(length); stop = readTransportRouteStop(rx, ry, rid); dataObject.getForwardStops().add(stop); rid = stop.getId(); rx = (int) MapUtils.getTileNumberX(TRANSPORT_STOP_ZOOM, stop.getLocation().getLongitude()); ry = (int) MapUtils.getTileNumberY(TRANSPORT_STOP_ZOOM, stop.getLocation().getLatitude()); codedIS.popLimit(olds); break; default: skipUnknownField(t); break; } } codedIS.popLimit(old); if (name != -1) { dataObject.setName(getStringFromStringTable(ind.stringTable, name)); } if (nameEn != -1) { dataObject.setEnName(getStringFromStringTable(ind.stringTable, nameEn)); } else { dataObject.setEnName(Junidecode.unidecode(dataObject.getName())); } if (operator != -1) { dataObject.setOperator(getStringFromStringTable(ind.stringTable, operator)); } if (type != -1) { dataObject.setType(getStringFromStringTable(ind.stringTable, type)); } for (int i = 0; i < 2; i++) { List<TransportStop> stops = i == 0 ? dataObject.getForwardStops() : dataObject.getBackwardStops(); for (TransportStop s : stops) { if (s.getName().length() > 0) { s.setName(getStringFromStringTable(ind.stringTable, s.getName().charAt(0))); } if (s.getEnName().length() > 0) { s.setEnName(getStringFromStringTable(ind.stringTable, s.getEnName().charAt(0))); } else { s.setEnName(Junidecode.unidecode(s.getName())); } } } return dataObject; }
public void writeBinaryTransportTree( rtree.Node parent, RTree r, BinaryMapIndexWriter writer, PreparedStatement selectTransportStop, PreparedStatement selectTransportRouteStop, Map<Long, Long> transportRoutes, Map<String, Integer> stringTable) throws IOException, RTreeException, SQLException { Element[] e = parent.getAllElements(); List<Long> routes = null; for (int i = 0; i < parent.getTotalElements(); i++) { Rect re = e[i].getRect(); if (e[i].getElementType() == rtree.Node.LEAF_NODE) { long id = ((LeafElement) e[i]).getPtr(); selectTransportStop.setLong(1, id); selectTransportRouteStop.setLong(1, id); ResultSet rs = selectTransportStop.executeQuery(); if (rs.next()) { int x24 = (int) MapUtils.getTileNumberX(24, rs.getDouble(3)); int y24 = (int) MapUtils.getTileNumberY(24, rs.getDouble(2)); String name = rs.getString(4); String nameEn = rs.getString(5); if (nameEn != null && nameEn.equals(Junidecode.unidecode(name))) { nameEn = null; } ResultSet rset = selectTransportRouteStop.executeQuery(); if (routes == null) { routes = new ArrayList<Long>(); } else { routes.clear(); } while (rset.next()) { Long route = transportRoutes.get(rset.getLong(1)); if (route == null) { log.error( "Something goes wrong with transport route id = " + rset.getLong(1)); // $NON-NLS-1$ } else { routes.add(route); } } rset.close(); writer.writeTransportStop(id, x24, y24, name, nameEn, stringTable, routes); } else { log.error("Something goes wrong with transport id = " + id); // $NON-NLS-1$ } } else { long ptr = ((NonLeafElement) e[i]).getPtr(); rtree.Node ns = r.getReadNode(ptr); writer.startTransportTreeElement(re.getMinX(), re.getMaxX(), re.getMinY(), re.getMaxY()); writeBinaryTransportTree( ns, r, writer, selectTransportStop, selectTransportRouteStop, transportRoutes, stringTable); writer.endWriteTransportTreeElement(); } } }
public void writeBinaryTransportIndex( BinaryMapIndexWriter writer, String regionName, Connection mapConnection) throws IOException, SQLException { try { closePreparedStatements(transRouteStat, transRouteStopsStat, transStopsStat); mapConnection.commit(); transportStopsTree.flush(); visitedStops = null; // allow gc to collect it PreparedStatement selectTransportRouteData = mapConnection.prepareStatement( "SELECT id, dist, name, name_en, ref, operator, type FROM transport_route"); //$NON-NLS-1$ PreparedStatement selectTransportData = mapConnection.prepareStatement( "SELECT S.stop, S.direction," + //$NON-NLS-1$ " A.latitude, A.longitude, A.name, A.name_en " + //$NON-NLS-1$ "FROM transport_route_stop S INNER JOIN transport_stop A ON A.id = S.stop WHERE S.route = ? ORDER BY S.ord asc"); //$NON-NLS-1$ writer.startWriteTransportIndex(regionName); writer.startWriteTransportRoutes(); // expect that memory would be enough Map<String, Integer> stringTable = createStringTableForTransport(); Map<Long, Long> transportRoutes = new LinkedHashMap<Long, Long>(); ResultSet rs = selectTransportRouteData.executeQuery(); List<TransportStop> directStops = new ArrayList<TransportStop>(); List<TransportStop> reverseStops = new ArrayList<TransportStop>(); while (rs.next()) { long idRoute = rs.getLong(1); int dist = rs.getInt(2); String routeName = rs.getString(3); String routeEnName = rs.getString(4); if (routeEnName != null && routeEnName.equals(Junidecode.unidecode(routeName))) { routeEnName = null; } String ref = rs.getString(5); String operator = rs.getString(6); String type = rs.getString(7); selectTransportData.setLong(1, idRoute); ResultSet rset = selectTransportData.executeQuery(); reverseStops.clear(); directStops.clear(); while (rset.next()) { boolean dir = rset.getInt(2) != 0; long idStop = rset.getInt(1); String stopName = rset.getString(5); String stopEnName = rset.getString(6); if (stopEnName != null && stopEnName.equals(Junidecode.unidecode(stopName))) { stopEnName = null; } TransportStop st = new TransportStop(); st.setId(idStop); st.setName(stopName); st.setLocation(rset.getDouble(3), rset.getDouble(4)); if (stopEnName != null) { st.setEnName(stopEnName); } if (dir) { directStops.add(st); } else { reverseStops.add(st); } } writer.writeTransportRoute( idRoute, routeName, routeEnName, ref, operator, type, dist, directStops, reverseStops, stringTable, transportRoutes); } rs.close(); selectTransportRouteData.close(); selectTransportData.close(); writer.endWriteTransportRoutes(); PreparedStatement selectTransportStop = mapConnection.prepareStatement( "SELECT A.id, A.latitude, A.longitude, A.name, A.name_en FROM transport_stop A where A.id = ?"); //$NON-NLS-1$ PreparedStatement selectTransportRouteStop = mapConnection.prepareStatement( "SELECT DISTINCT S.route FROM transport_route_stop S WHERE S.stop = ? "); //$NON-NLS-1$ long rootIndex = transportStopsTree.getFileHdr().getRootIndex(); rtree.Node root = transportStopsTree.getReadNode(rootIndex); Rect rootBounds = calcBounds(root); if (rootBounds != null) { writer.startTransportTreeElement( rootBounds.getMinX(), rootBounds.getMaxX(), rootBounds.getMinY(), rootBounds.getMaxY()); writeBinaryTransportTree( root, transportStopsTree, writer, selectTransportStop, selectTransportRouteStop, transportRoutes, stringTable); writer.endWriteTransportTreeElement(); } selectTransportStop.close(); selectTransportRouteStop.close(); writer.writeTransportStringTable(stringTable); writer.endWriteTransportIndex(); writer.flush(); } catch (RTreeException e) { throw new IllegalStateException(e); } }
public void drawTextOverCanvas(RenderingContext rc, Canvas cv, boolean useEnglishNames) { int size = rc.textToDraw.size(); // 1. Sort text using text order Collections.sort( rc.textToDraw, new Comparator<TextDrawInfo>() { @Override public int compare(TextDrawInfo object1, TextDrawInfo object2) { return object1.textOrder - object2.textOrder; } }); RectF r = new RectF(0, 0, rc.width, rc.height); r.inset(-100, -100); QuadTree<TextDrawInfo> nonIntersectedBounds = new QuadTree<TextDrawInfo>(r, 4, 0.6f); for (int i = 0; i < size; i++) { TextDrawInfo text = rc.textToDraw.get(i); if (text.text != null && text.text.length() > 0) { if (useEnglishNames) { text.text = Junidecode.unidecode(text.text); } // sest text size before finding intersection (it is used there) float textSize = rc.getDensityValue(text.textSize); paintText.setTextSize(textSize); paintText.setFakeBoldText(text.bold); paintText.setColor(text.textColor); // align center y text.centerY += (-paintText.ascent()); // calculate if there is intersection boolean intersects = findTextIntersection(cv, rc, nonIntersectedBounds, text); if (!intersects) { if (text.drawOnPath != null) { if (text.textShadow > 0) { paintText.setColor(Color.WHITE); paintText.setStyle(Style.STROKE); paintText.setStrokeWidth(2 + text.textShadow); cv.drawTextOnPath(text.text, text.drawOnPath, 0, text.vOffset, paintText); // reset paintText.setStyle(Style.FILL); paintText.setStrokeWidth(2); paintText.setColor(text.textColor); } cv.drawTextOnPath(text.text, text.drawOnPath, 0, text.vOffset, paintText); } else { if (text.shieldRes != null) { Bitmap ico = RenderingIcons.getIcon(context, text.shieldRes); if (ico != null) { if (rc.highResMode) { float left = text.centerX - rc.getDensityValue(ico.getWidth() / 2) - 0.5f; float top = text.centerY - rc.getDensityValue(ico.getHeight() / 2) - rc.getDensityValue(4.5f); Rect rec = new Rect(0, 0, ico.getWidth(), ico.getHeight()); cv.drawBitmap( ico, rec, new RectF( left, top, left + rc.getDensityValue(ico.getWidth()), top + rc.getDensityValue(ico.getHeight())), paintIcon); } else { float left = text.centerX - ico.getWidth() / 2 - 0.5f; float top = text.centerY - ico.getHeight() / 2 - rc.getDensityValue(4.5f); cv.drawBitmap(ico, left, top, paintIcon); } } } drawWrappedText(cv, text, textSize); } } } } }