@NonNull
    public static Set<Waypoint> loadWaypoints(final Viewport viewport) {
        return withAccessLock(() -> {

            final StringBuilder where = buildCoordinateWhere(dbTableWaypoints, viewport);

            final StringBuilder query = new StringBuilder("SELECT ");
            for (int i = 0; i < WAYPOINT_COLUMNS.length; i++) {
                query.append(i > 0 ? ", " : "").append(dbTableWaypoints).append('.').append(WAYPOINT_COLUMNS[i]).append(' ');
            }
            query.append(" FROM ").append(dbTableWaypoints).append(", ").append(dbTableCaches).append(" WHERE ").append(dbTableWaypoints)
                    .append(".geocode == ").append(dbTableCaches).append(".geocode AND ").append(where)
                    .append(" LIMIT ").append(Math.max(10, Settings.getKeyInt(R.integer.waypoint_threshold_max)) * 2);  // Hardcoded limit to avoid memory overflow

            return cursorToColl(database.rawQuery(query.toString(), null), new HashSet<>(), DataStore::createWaypointFromDatabaseContent);
        });
    }
Loads all Waypoints in the coordinate rectangle.
main/src/main/java/cgeo/geocaching/storage/DataStore.java