public static final Map instanceOf(TTSQLiteOpenHelper sqLiteOpenHelper, int mapId) { Map map = new Map(); SQLiteDatabase database = sqLiteOpenHelper.getReadableDatabase(); Cursor cursor = database.query( TABLE_MAPS, ALL_MAP_COLUMNS, COLUMN_ID + " = " + mapId, null, null, null, null); cursor.moveToFirst(); map.id = mapId; map.name = cursor.getString(cursor.getColumnIndex(COLUMN_NAME)); map.startTime = cursor.getInt(cursor.getColumnIndex(COLUMN_START_TIME)); map.endTime = cursor.getInt(cursor.getColumnIndex(COLUMN_END_TIME)); map.averageSpeed = cursor.getFloat(cursor.getColumnIndex(COLUMN_AVERAGE_SPEED)); map.totalDistance = cursor.getFloat(cursor.getColumnIndex(COLUMN_TOTAL_DISTANCE)); map.linearDistance = cursor.getFloat(cursor.getColumnIndex(COLUMN_LINEAR_DISTANCE)); map.maximumSpeed = cursor.getFloat(cursor.getColumnIndex(COLUMN_MAXIMUM_SPEED)); map.maximumAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_MAX_ALTITUDE)); map.minimumAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_MIN_ALTITUDE)); map.startAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_START_ALTITUDE)); map.endAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_END_ALTITUDE)); map.notes = cursor.getString(cursor.getColumnIndex(COLUMN_NOTES)); cursor.close(); map.locations = TTLocation.getAll(sqLiteOpenHelper, mapId); map.waypoints = Waypoint.getAll(sqLiteOpenHelper, mapId); map.stops = Stop.getAll(sqLiteOpenHelper, mapId); return map; }
/** * filters out nonessential points. A point is nonessential if it affects the path taken by less * than 5 meters * * @return The checkpoints of the trail in this map */ public TTLocation[] getCheckpoints() { // starting point always relevant// ArrayList<TTLocation> checkpointList = new ArrayList<TTLocation>(); checkpointList.add(locations[0]); int relevantPointIndex = 0; for (int locationIndex = 2; locationIndex < locations.length; locationIndex++) { TTLocation ptInQuestion = locations[locationIndex - 1]; TTLocation relevantPt = locations[relevantPointIndex]; // distance from the last relevant to the point in question// float distanceTo = relevantPt.distanceTo(ptInQuestion.getLongitude(), ptInQuestion.getLatitude()); // if the point is less than 5m away, it can't affect the trail by more than 5m// if (distanceTo < 5) { continue; } // difference between the bearing from the relevant point to the point in question // and the bearing from the relevant point to the point after the point in question float bearingDifference = Math.abs( relevantPt.bearingTo(ptInQuestion.getLongitude(), ptInQuestion.getLatitude()) - relevantPt.bearingTo( locations[locationIndex].getLongitude(), locations[locationIndex].getLatitude())); // distance away from the point in question that the new path will take// double distanceOff = Math.sin(bearingDifference) * distanceTo; if (distanceOff > 5) { checkpointList.add(ptInQuestion); relevantPointIndex = locationIndex - 1; } } // the last point is always relevant and, as a result of the loop conditions, // never added by the loop// checkpointList.add(locations[locations.length - 1]); TTLocation[] array = new TTLocation[checkpointList.size()]; return checkpointList.toArray(array); }
/** * Convenience method for adding appending a location's information to a StringBuilder for use in * a KML export * * @param stopsSB StringBuilder to which to append the location info * @param loc TTLocation from which to get info */ private void appendLocationString(StringBuilder stopsSB, TTLocation loc) { stopsSB .append(loc.getLongitude()) .append(",") .append(loc.getLatitude()) .append(",") .append(loc.getAccuracy()) .append(",") .append(loc.getAltitude()) .append(",") .append(loc.getAccuracy()) .append(",") .append(loc.getSpeed()) .append(",") .append(loc.getTime()) .append(",") .append(loc.getTime() / 1000) .append(",") .append(loc.getDistance()) .append(";") .append("\n"); }