use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class TransportRouteController method addPlainMenuItems.
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) {
super.addPlainMenuItems(typeStr, pointDescription, latLon);
List<TransportStop> stops = transportRoute.route.getForwardStops();
boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
int currentStop = getCurrentStop();
int defaultIcon = transportRoute.type == null ? R.drawable.mx_route_bus_ref : transportRoute.type.getResourceId();
int startPosition = 0;
if (!transportRoute.showWholeRoute) {
startPosition = (currentStop == -1 ? 0 : currentStop);
if (currentStop > 0) {
addPlainMenuItem(defaultIcon, getMapActivity().getString(R.string.shared_string_show), getMapActivity().getString(R.string.route_stops_before, currentStop), false, false, new OnClickListener() {
@Override
public void onClick(View arg0) {
MapContextMenu menu = getMapActivity().getContextMenu();
menu.showOrUpdate(latLon, getPointDescription(), transportRoute);
}
});
}
}
for (int i = startPosition; i < stops.size(); i++) {
final TransportStop stop = stops.get(i);
String name = useEnglishNames ? stop.getEnName(true) : stop.getName();
if (TextUtils.isEmpty(name)) {
name = getStopType();
}
addPlainMenuItem(currentStop == i ? R.drawable.ic_action_marker_dark : defaultIcon, null, name, false, false, new OnClickListener() {
@Override
public void onClick(View arg0) {
showTransportStop(stop);
/*
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_STOP,
getMapActivity().getString(R.string.transport_Stop), name);
LatLon stopLocation = stop.getLocation();
getMapActivity().getMyApplication().getSettings()
.setMapLocationToShow(stopLocation.getLatitude(), stopLocation.getLongitude(),
15, pd, false, transportRoute);
MapActivity.launchMapActivityMoveToTop(getMapActivity());
*/
}
});
}
}
use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class AmenityMenuController method processTransportStop.
private void processTransportStop() {
routes = new ArrayList<>();
List<TransportIndexRepository> reps = getMapActivity().getMyApplication().getResourceManager().searchTransportRepositories(amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude());
boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
boolean isSubwayEntrance = amenity.getSubType().equals("subway_entrance");
for (TransportIndexRepository t : reps) {
ArrayList<TransportStop> ls = new ArrayList<>();
QuadRect ll = MapUtils.calculateLatLonBbox(amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), isSubwayEntrance ? 400 : 150);
t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
for (TransportStop tstop : ls) {
addRoutes(useEnglishNames, t, tstop, (int) MapUtils.getDistance(tstop.getLocation(), amenity.getLocation()), isSubwayEntrance);
}
}
Collections.sort(routes, new Comparator<TransportStopRoute>() {
@Override
public int compare(TransportStopRoute o1, TransportStopRoute o2) {
if (o1.distance != o2.distance) {
return Algorithms.compare(o1.distance, o2.distance);
}
int i1 = Algorithms.extractFirstIntegerNumber(o1.desc);
int i2 = Algorithms.extractFirstIntegerNumber(o2.desc);
if (i1 != i2) {
return Algorithms.compare(i1, i2);
}
return o1.desc.compareTo(o2.desc);
}
});
builder.setRoutes(routes);
}
use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class EntityParser method parseTransportStop.
public static TransportStop parseTransportStop(Entity e) {
TransportStop st = new TransportStop();
parseMapObject(st, e, e.getTags());
return st;
}
use of net.osmand.data.TransportStop in project OsmAnd-tools by osmandapp.
the class IndexTransportCreator method writeBinaryTransportIndex.
public void writeBinaryTransportIndex(BinaryMapIndexWriter writer, String regionName, Connection mapConnection) throws IOException, SQLException {
try {
closePreparedStatements(transRouteStat, transRouteStopsStat, transStopsStat, transRouteGeometryStat);
mapConnection.commit();
transportStopsTree.flush();
// allow gc to collect it
visitedStops = null;
PreparedStatement selectTransportRouteData = mapConnection.prepareStatement(// $NON-NLS-1$
"SELECT id, dist, name, name_en, ref, operator, type, color FROM transport_route");
PreparedStatement selectTransportData = mapConnection.prepareStatement(// $NON-NLS-1$
"SELECT S.stop, " + // $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");
PreparedStatement selectTransportRouteGeometry = mapConnection.prepareStatement("SELECT S.geometry " + // $NON-NLS-1$
"FROM transport_route_geometry S WHERE S.route = ?");
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<>();
List<TransportStop> reverseStops = new ArrayList<>();
List<byte[]> directGeometry = new ArrayList<>();
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);
String color = rs.getString(8);
selectTransportData.setLong(1, idRoute);
ResultSet rset = selectTransportData.executeQuery();
reverseStops.clear();
directStops.clear();
directGeometry.clear();
while (rset.next()) {
long idStop = rset.getInt(1);
String stopName = rset.getString(4);
String stopEnName = rset.getString(5);
if (stopEnName != null && stopEnName.equals(Junidecode.unidecode(stopName))) {
stopEnName = null;
}
TransportStop st = new TransportStop();
st.setId(idStop);
st.setName(stopName);
st.setLocation(rset.getDouble(2), rset.getDouble(3));
if (stopEnName != null) {
st.setEnName(stopEnName);
}
directStops.add(st);
}
selectTransportRouteGeometry.setLong(1, idRoute);
rset = selectTransportRouteGeometry.executeQuery();
while (rset.next()) {
byte[] bytes = rset.getBytes(1);
directGeometry.add(bytes);
}
writer.writeTransportRoute(idRoute, routeName, routeEnName, ref, operator, type, dist, color, directStops, directGeometry, stringTable, transportRoutes);
}
rs.close();
selectTransportRouteData.close();
selectTransportData.close();
writer.endWriteTransportRoutes();
PreparedStatement selectTransportStop = mapConnection.prepareStatement(// $NON-NLS-1$
"SELECT A.id, A.latitude, A.longitude, A.name, A.name_en FROM transport_stop A where A.id = ?");
PreparedStatement selectTransportRouteStop = mapConnection.prepareStatement(// $NON-NLS-1$
"SELECT DISTINCT S.route FROM transport_route_stop S join transport_route R on R.id = S.route WHERE S.stop = ? ORDER BY R.type, R.ref ");
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);
}
}
use of net.osmand.data.TransportStop in project OsmAnd-tools by osmandapp.
the class IndexTransportCreator method processTransportRelationV2.
private boolean processTransportRelationV2(Relation rel, TransportRoute route) {
// first, verify we can accept this relation as new transport relation
// accepted roles restricted to: <empty>, stop, platform, ^(stop|platform)_(entry|exit)_only$
String version = rel.getTag("public_transport:version");
try {
if (Algorithms.isEmpty(version) || Integer.parseInt(version) < 2) {
for (RelationMember entry : rel.getMembers()) {
// ignore ways (cause with even with new relations there could be a mix of forward/backward ways)
if (entry.getEntity() instanceof Way) {
continue;
}
String role = entry.getRole();
if (role.isEmpty() || "stop".equals(role) || "platform".equals(role)) {
// accepted roles
continue;
}
stopPlatformMatcher.reset(role);
if (stopPlatformMatcher.matches()) {
continue;
}
// there is wrong role in the relation, exit
return false;
}
}
} catch (NumberFormatException e) {
return false;
}
List<Entity> platformsAndStops = new ArrayList<Entity>();
List<Entity> platforms = new ArrayList<Entity>();
List<Entity> stops = new ArrayList<Entity>();
Map<EntityId, Entity> platformNames = new LinkedHashMap<>();
for (RelationMember entry : rel.getMembers()) {
String role = entry.getRole();
if (entry.getEntity() == null || entry.getEntity().getLatLon() == null) {
continue;
}
if (role.startsWith("platform")) {
platformsAndStops.add(entry.getEntity());
platforms.add(entry.getEntity());
} else if (role.startsWith("stop")) {
platformsAndStops.add(entry.getEntity());
stops.add(entry.getEntity());
} else {
if (entry.getEntity() instanceof Way) {
route.addWay((Way) entry.getEntity());
}
}
}
mergePlatformsStops(platformsAndStops, platforms, stops, platformNames);
if (platformsAndStops.isEmpty()) {
// nothing to get from this relation - there is no stop
return true;
}
for (Entity s : platformsAndStops) {
TransportStop stop = EntityParser.parseTransportStop(s);
Relation stopArea = stopAreas.get(EntityId.valueOf(s));
// verify name tag, not stop.getName because it may contain unnecessary refs, etc
Entity genericStopName = null;
if (stopArea != null && !Algorithms.isEmpty(stopArea.getTag(OSMTagKey.NAME))) {
genericStopName = stopArea;
} else if (platformNames.containsKey(EntityId.valueOf(s))) {
genericStopName = platformNames.get(EntityId.valueOf(s));
}
if (genericStopName != null) {
stop.copyNames(genericStopName.getTag(OSMTagKey.NAME), genericStopName.getTag(OSMTagKey.NAME_EN), genericStopName.getNameTags(), true);
}
route.getForwardStops().add(stop);
}
return true;
}
Aggregations